#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ ptrace(int /*<<< orphan*/, scalar_t__, int /*<<< orphan*/,
                  struct user_regs_struct *);
int ftrace_peek_registers(pid_t child, struct user_regs_struct *regs) {
  assert(child != 0);
  assert(regs != NULL);
  errno = 0;
  if (ptrace(PTRACE_GETREGS, child, 0, regs) && errno)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<ftrace_peek_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e7d(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
je     11a1 <ftrace_peek_registers+0x81>
mov    0x2e4d(%rip),%rax
cmpq   $0x0,(%rax)
je     11a1 <ftrace_peek_registers+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <ftrace_peek_registers+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftrace_peek_registers>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
mov    0x2e8a(%rip),%r15
movq   $0x0,(%r15)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <ptrace@plt>
test   %rax,%rax
setne  %al
cmpq   $0x0,(%r15)
setne  %cl
and    %al,%cl
movzbl %cl,%eax
neg    %eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.user_regs_struct = type { i32 }
@errno = global i64 0
@PTRACE_GETREGS = global i32 0
define i32 @ftrace_peek_registers(i64 %0, %struct.user_regs_struct* %1) {
%3 = icmp ne i64 %0, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne %struct.user_regs_struct* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
store i64 0, i64* @errno
%9 = load i32, i32* @PTRACE_GETREGS
%10 = tail call i64 @ptrace(i32 %9, i64 %0, i32 0, %struct.user_regs_struct* %1)
%11 = icmp ne i64 %10, 0
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
%14 = select i1 %11, i1 %13, i1 false
%15 = sext i1 %14 to i32
ret i32 %15
}