#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 {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ perror(char *);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
            struct user_regs_struct *);
int proc_get_regs(pid_t pid, struct user_regs_struct *regs) {
  long ret;
  ret = ptrace(PTRACE_GETREGS, pid, NULL, regs);
  if (ret == -1) {
    perror("ptrace getregs");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<proc_get_regs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ptrace@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    116f <proc_get_regs+0x4f>
lea    0xea2(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1176 <proc_get_regs+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_get_regs>:
push   %rbx
mov    %rsi,%rcx
mov    %edi,%esi
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <ptrace@plt>
cmp    $0xffffffffffffffff,%rax
je     1142 <proc_get_regs+0x22>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xeb7(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    113e <proc_get_regs+0x1e>

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

LLVM IR (-O2):
%struct.user_regs_struct = type { i32 }
@PTRACE_GETREGS = global i32 0
@.str = [15 x i8] c"ptrace getregs\00"
define i32 @proc_get_regs(i32 %0, %struct.user_regs_struct* %1) {
%3 = load i32, i32* @PTRACE_GETREGS
%4 = tail call i64 @ptrace(i32 %3, i32 %0, i32* null, %struct.user_regs_struct* %1)
%5 = icmp eq i64 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ -1, %6 ], [ 0, %2 ]
ret i32 %9
}