> For the complete documentation index, see [llms.txt](https://valineliu.gitbook.io/deuterium-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valineliu.gitbook.io/deuterium-wiki/reading/cs-jing-dian-shu-ji/csapp-3e-homework-solution/3.-machine-level-representation-of-programs/3.58-decode.md).

# 3.58 Decode

★

Problem:

For a function with prototype:

```c
long decode2(long x, long y, long z);
```

GCC generates the following assembly code:

```
decode2:
    subq    %rdx, %rsi
    imulq    %rsi, %rdi
    movq    %rsi, %rax
    salq    $63, %rax
    sarq    $63, %rax
    xorq    %rdi, %rax
    ret
```

Parameters `x`, `y`, and `z` are passed in registers %rdi, %rsi, and %rdx. The code stores the return value in register %rax.

Write C code for `decode2` that will have an effect equivalent to the assembly code shown.

Code:

```c
long decode2(long x, long y, long z) {
    long tmp = y - z;
    return (tmp * x) ^ (tmp << 63 >> 63);
}
```
