#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 iovec {
  unsigned long *iov_base;
  int iov_len;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ FAIL_IF(int /*<<< orphan*/);
int /*<<< orphan*/ PTRACE_SETREGSET;
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, unsigned long,
            struct iovec *);
int /*<<< orphan*/ start_trace(int /*<<< orphan*/);
int /*<<< orphan*/ stop_trace(int /*<<< orphan*/);
long ptrace_write_regs(pid_t child, unsigned long type, unsigned long regs[],
                       int n) {
  struct iovec iov;
  long ret;
  FAIL_IF(start_trace(child));
  iov.iov_base = regs;
  iov.iov_len = n * sizeof(unsigned long);
  ret = ptrace(PTRACE_SETREGSET, child, type, &iov);
  FAIL_IF(stop_trace(child));
  return ret;
}


x86 assembly (clang, -O0):
<ptrace_write_regs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <start_trace@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,-0x28(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1060 <ptrace@plt>
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <stop_trace@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace_write_regs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
call   1050 <start_trace@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    %r14,0x8(%rsp)
shl    $0x3,%ebx
mov    %ebx,0x10(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rcx
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <ptrace@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <stop_trace@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i64*, i32 }
@PTRACE_SETREGSET = global i32 0
define i64 @ptrace_write_regs(i32 %0, i64 %1, i64* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i32
%9 = alloca %struct.iovec
%10 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i64* %2, i64** %7
store i32 %3, i32* %8
%11 = load i32, i32* %5
%12 = call i32 @start_trace(i32 %11)
%13 = call i32 @FAIL_IF(i32 %12)
%14 = load i64*, i64** %7
%15 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 0
store i64* %14, i64** %15
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @PTRACE_SETREGSET
%22 = load i32, i32* %5
%23 = load i64, i64* %6
%24 = call i64 @ptrace(i32 %21, i32 %22, i64 %23, %struct.iovec* %9)
store i64 %24, i64* %10
%25 = load i32, i32* %5
%26 = call i32 @stop_trace(i32 %25)
%27 = call i32 @FAIL_IF(i32 %26)
%28 = load i64, i64* %10
ret i64 %28
}

LLVM IR (-O2):
%struct.iovec = type { i64*, i32 }
@PTRACE_SETREGSET = global i32 0
define i64 @ptrace_write_regs(i32 %0, i64 %1, i64* %2, i32 %3) {
%5 = alloca %struct.iovec
%6 = bitcast %struct.iovec* %5 to i8*
%7 = tail call i32 @start_trace(i32 %0)
%8 = tail call i32 @FAIL_IF(i32 %7)
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
store i64* %2, i64** %9
%10 = shl i32 %3, 3
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @PTRACE_SETREGSET
%13 = call i64 @ptrace(i32 %12, i32 %0, i64 %1, %struct.iovec* %5)
%14 = call i32 @stop_trace(i32 %0)
%15 = call i32 @FAIL_IF(i32 %14)
ret i64 %13
}