#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_PEEKDATA;
scalar_t__ errno;
int /*<<< orphan*/ log_real_(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                             char *, int /*<<< orphan*/);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, void const *,
            int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(scalar_t__);
long tracee_getword(pid_t tid, const void *addr) {
  long res;
  errno = 0;
  res = ptrace(PTRACE_PEEKDATA, tid, addr, NULL);
  if (errno) {
    log_real_(tid, "CRITICAL", 0,
              "tracee_getword() failed: %s"
              "\n",
              strerror(errno));
    return 0;
  }
  return res;
}


x86 assembly (clang, -O0):
<tracee_getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e9a(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <ptrace@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e6f(%rip),%rax
cmpq   $0x0,(%rax)
je     11b8 <tracee_getword+0x88>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%r8d
lea    0xe63(%rip),%rsi
xor    %edx,%edx
lea    0xe63(%rip),%rcx
call   1030 <log_real_@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <tracee_getword+0x90>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracee_getword>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rdx
mov    %edi,%ebp
mov    0x2ea0(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
xor    %ecx,%ecx
call   1040 <ptrace@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
je     1184 <tracee_getword+0x54>
call   1050 <strerror@plt>
lea    0xe93(%rip),%rsi
lea    0xe95(%rip),%rcx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
mov    %eax,%r8d
call   1030 <log_real_@plt>
jmp    1187 <tracee_getword+0x57>
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@PTRACE_PEEKDATA = global i32 0
@.str = [9 x i8] c"CRITICAL\00"
@.str.1 = [29 x i8] c"tracee_getword() failed: %s\0A\00"
define i64 @tracee_getword(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 0, i64* @errno
%7 = load i32, i32* @PTRACE_PEEKDATA
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = call i64 @ptrace(i32 %7, i32 %8, i8* %9, i32* null)
store i64 %10, i64* %6
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i64, i64* @errno
%16 = call i32 @strerror(i64 %15)
%17 = call i32 @log_real_(i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i64 0, i64* %3
br label %20
18: ; preds = %2
%19 = load i64, i64* %6
store i64 %19, i64* %3
br label %20
20: ; preds = %18, %13
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
@errno = global i64 0
@PTRACE_PEEKDATA = global i32 0
@.str = [9 x i8] c"CRITICAL\00"
@.str.1 = [29 x i8] c"tracee_getword() failed: %s\0A\00"
define i64 @tracee_getword(i32 %0, i8* %1) {
store i64 0, i64* @errno
%3 = load i32, i32* @PTRACE_PEEKDATA
%4 = tail call i64 @ptrace(i32 %3, i32 %0, i8* %1, i32* null)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @strerror(i64 %5)
%9 = tail call i32 @log_real_(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %2, %7
%11 = phi i64 [ 0, %7 ], [ %4, %2 ]
ret i64 %11
}