#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ val;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ tracee_read(int /*<<< orphan*/, void *, void const *, int);
uint64_t tracee_getlong(int mode, pid_t tid, const void *addr) {
  if (mode == 1) {
    uint32_t val;
    tracee_read(tid, (void *)&val, addr, sizeof(val));
    return (uint64_t)val;
  } else {
    uint64_t val;
    tracee_read(tid, (void *)&val, addr, sizeof(val));
    return val;
  }
}


x86 assembly (clang, -O0):
<tracee_getlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    114c <tracee_getlong+0x3c>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <tracee_read@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1167 <tracee_getlong+0x57>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <tracee_read@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracee_getlong>:
push   %rax
mov    %esi,%eax
cmp    $0x1,%edi
jne    112f <tracee_getlong+0x1f>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%ecx
call   1030 <tracee_read@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%ecx
call   1030 <tracee_read@plt>
mov    (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @tracee_getlong(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* %6
%14 = bitcast i32* %8 to i8*
%15 = load i8*, i8** %7
%16 = call i32 @tracee_read(i32 %13, i8* %14, i8* %15, i32 4)
%17 = load i32, i32* %8
store i32 %17, i32* %4
br label %24
18: ; preds = %3
%19 = load i32, i32* %6
%20 = bitcast i32* %9 to i8*
%21 = load i8*, i8** %7
%22 = call i32 @tracee_read(i32 %19, i8* %20, i8* %21, i32 4)
%23 = load i32, i32* %9
store i32 %23, i32* %4
br label %24
24: ; preds = %18, %12
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
define i32 @tracee_getlong(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = bitcast i32* %4 to i8*
%9 = call i32 @tracee_read(i32 %1, i8* %8, i8* %2, i32 4)
%10 = load i32, i32* %4
br label %15
11: ; preds = %3
%12 = bitcast i32* %5 to i8*
%13 = call i32 @tracee_read(i32 %1, i8* %12, i8* %2, i32 4)
%14 = load i32, i32* %5
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ %10, %7 ], [ %14, %11 ]
ret i32 %16
}