#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_PEEKUSER;
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
long peek_user(pid_t pid, long offset) {
  long data;
  data = ptrace(PTRACE_PEEKUSER, pid, sizeof(long) * offset, NULL);
  if (data == -1 && errno)
    fatal("PTRACE_PEEKUSER failed");
  return (data);
}


x86 assembly (clang, -O0):
<peek_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <ptrace@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    117a <peek_user+0x5a>
mov    0x2e7c(%rip),%rax
cmpq   $0x0,(%rax)
je     117a <peek_user+0x5a>
lea    0xe8b(%rip),%rdi
call   1040 <fatal@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek_user>:
push   %rbx
mov    %edi,%eax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%edi
lea    0x0(,%rsi,8),%edx
mov    %eax,%esi
xor    %ecx,%ecx
call   1030 <ptrace@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    115e <peek_user+0x3e>
mov    0x2e94(%rip),%rax
cmpq   $0x0,(%rax)
je     115e <peek_user+0x3e>
lea    0xea7(%rip),%rdi
call   1040 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@PTRACE_PEEKUSER = global i32 0
@errno = global i64 0
@.str = [23 x i8] c"PTRACE_PEEKUSER failed\00"
define i64 @peek_user(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%6 = load i32, i32* @PTRACE_PEEKUSER
%7 = load i32, i32* %3
%8 = load i64, i64* %4
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @ptrace(i32 %6, i32 %7, i32 %10, i32* null)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14, %2
%20 = load i64, i64* %5
ret i64 %20
}

LLVM IR (-O2):
@PTRACE_PEEKUSER = global i32 0
@errno = global i64 0
@.str = [23 x i8] c"PTRACE_PEEKUSER failed\00"
define i64 @peek_user(i32 %0, i64 %1) {
%3 = load i32, i32* @PTRACE_PEEKUSER
%4 = trunc i64 %1 to i32
%5 = shl i32 %4, 3
%6 = tail call i64 @ptrace(i32 %3, i32 %0, i32 %5, i32* null)
%7 = icmp eq i64 %6, -1
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
ret i64 %6
}