#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 */
struct user_regs_struct {
  long rip;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ perror(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct user_regs_struct *);
long get_child_eip(pid_t pid) {
  struct user_regs_struct regs;
  if (ptrace(PTRACE_GETREGS, pid, 0, &regs) < 0) {
    perror("ptrace2");
    return -1;
  }
  return regs.rip;
}


x86 assembly (clang, -O0):
<get_child_eip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
call   1030 <ptrace@plt>
cmp    $0x0,%rax
jge    1165 <get_child_eip+0x45>
lea    0xead(%rip),%rdi
call   1040 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    116d <get_child_eip+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_child_eip>:
push   %rax
mov    %edi,%esi
mov    0x2eb6(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rcx
xor    %edx,%edx
call   1030 <ptrace@plt>
test   %rax,%rax
js     1141 <get_child_eip+0x21>
mov    (%rsp),%rax
pop    %rcx
ret
lea    0xeb8(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffffffffffff,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.user_regs_struct = type { i64 }
@PTRACE_GETREGS = global i32 0
@.str = [8 x i8] c"ptrace2\00"
define i64 @get_child_eip(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca %struct.user_regs_struct
store i32 %0, i32* %3
%5 = load i32, i32* @PTRACE_GETREGS
%6 = load i32, i32* %3
%7 = call i64 @ptrace(i32 %5, i32 %6, i32 0, %struct.user_regs_struct* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 -1, i64* %2
br label %14
11: ; preds = %1
%12 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %4, i32 0, i32 0
%13 = load i64, i64* %12
store i64 %13, i64* %2
br label %14
14: ; preds = %11, %9
%15 = load i64, i64* %2
ret i64 %15
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i64 }
@PTRACE_GETREGS = global i32 0
@.str = [8 x i8] c"ptrace2\00"
define i64 @get_child_eip(i32 %0) {
%2 = alloca %struct.user_regs_struct
%3 = bitcast %struct.user_regs_struct* %2 to i8*
%4 = load i32, i32* @PTRACE_GETREGS
%5 = call i64 @ptrace(i32 %4, i32 %0, i32 0, %struct.user_regs_struct* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %1
%10 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %2, i64 0, i32 0
%11 = load i64, i64* %10
br label %12
12: ; preds = %9, %7
%13 = phi i64 [ -1, %7 ], [ %11, %9 ]
ret i64 %13
}