#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;
scalar_t__ errno;
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct user_regs_struct *);
int strace_peek_registers(pid_t child, struct user_regs_struct *regsp) {
  struct user_regs_struct registers;
  errno = 0;
  if (ptrace(PTRACE_GETREGS, child, 0, &registers) && errno)
    return (-1);
  *regsp = registers;
  return (0);
}


x86 assembly (clang, -O0):
<strace_peek_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb2(%rip),%rax
movq   $0x0,(%rax)
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
call   1030 <ptrace@plt>
cmp    $0x0,%rax
je     116b <strace_peek_registers+0x5b>
mov    0x2e83(%rip),%rax
cmpq   $0x0,(%rax)
je     116b <strace_peek_registers+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <strace_peek_registers+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strace_peek_registers>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%esi
mov    0x2eb8(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rcx
xor    %edx,%edx
call   1030 <ptrace@plt>
test   %rax,%rax
je     114a <strace_peek_registers+0x3a>
mov    $0xffffffff,%eax
cmpq   $0x0,(%rbx)
jne    1152 <strace_peek_registers+0x42>
mov    (%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.user_regs_struct = type { i32 }
@errno = global i64 0
@PTRACE_GETREGS = global i32 0
define i32 @strace_peek_registers(i32 %0, %struct.user_regs_struct* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.user_regs_struct*
%6 = alloca %struct.user_regs_struct
store i32 %0, i32* %4
store %struct.user_regs_struct* %1, %struct.user_regs_struct** %5
store i64 0, i64* @errno
%7 = load i32, i32* @PTRACE_GETREGS
%8 = load i32, i32* %4
%9 = call i64 @ptrace(i32 %7, i32 %8, i32 0, %struct.user_regs_struct* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %3
br label %19
15: ; preds = %11, %2
%16 = load %struct.user_regs_struct*, %struct.user_regs_struct** %5
%17 = bitcast %struct.user_regs_struct* %16 to i8*
%18 = bitcast %struct.user_regs_struct* %6 to i8*
store i32 0, i32* %3
br label %19
19: ; preds = %15, %14
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i32 }
@errno = global i64 0
@PTRACE_GETREGS = global i32 0
define i32 @strace_peek_registers(i32 %0, %struct.user_regs_struct* nocapture writeonly %1) {
%3 = alloca %struct.user_regs_struct
%4 = bitcast %struct.user_regs_struct* %3 to i8*
store i64 0, i64* @errno
%5 = load i32, i32* @PTRACE_GETREGS
%6 = call i64 @ptrace(i32 %5, i32 %0, i32 0, %struct.user_regs_struct* %3)
%7 = icmp ne i64 %6, 0
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %3, i64 0, i32 0
%13 = getelementptr %struct.user_regs_struct, %struct.user_regs_struct* %1, i64 0, i32 0
%14 = load i32, i32* %12
store i32 %14, i32* %13
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ 0, %11 ], [ -1, %2 ]
ret i32 %16
}