#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_SETREGS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, scalar_t__,
                           char *, int);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  struct user_regs_struct *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int ptrace_setregs(int pid, struct user_regs_struct *regs) {
  do {
    if (!(ptrace(PTRACE_SETREGS, (pid_t)pid, NULL, regs) == 0)) {
      fprintf(stderr,
              "(%s:%d: error: %d [%s]) "
              "Failed to set registers of target process %d"
              "\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/dismantl/linux-injector/refs/heads/"
              "master/ptrace.c",
              50, errno, errno == 0 ? "None" : strerror(errno), pid);
      errno = 0;
      goto error;
    }
  } while (0);
  return 1;
error:
  return 0;
}


x86 assembly (clang, -O0):
<ptrace_setregs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
je     11ec <ptrace_setregs+0xbc>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e4d(%rip),%rax
cmpq   $0x0,(%rax)
jne    119d <ptrace_setregs+0x6d>
lea    0xf3f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b0 <ptrace_setregs+0x80>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%r9
mov    -0x8(%rbp),%eax
lea    0xe3b(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    $0x32,%ecx
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    0x2df0(%rip),%rax
movq   $0x0,(%rax)
jmp    11fd <ptrace_setregs+0xcd>
jmp    11f1 <ptrace_setregs+0xc1>
movl   $0x1,-0x4(%rbp)
jmp    1204 <ptrace_setregs+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace_setregs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rcx
mov    %edi,%ebp
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <ptrace@plt>
test   %rax,%rax
je     1179 <ptrace_setregs+0x49>
mov    0x2e7e(%rip),%rax
mov    (%rax),%r14d
mov    0x2e6c(%rip),%r15
mov    (%r15),%rbx
test   %rbx,%rbx
je     1180 <ptrace_setregs+0x50>
mov    %rbx,%rdi
call   1050 <strerror@plt>
mov    %rax,%r9
jmp    1187 <ptrace_setregs+0x57>
mov    $0x1,%eax
jmp    11b1 <ptrace_setregs+0x81>
lea    0xf4c(%rip),%r9
mov    %ebp,(%rsp)
lea    0xe6f(%rip),%rsi
lea    0xeae(%rip),%rdx
mov    %r14d,%edi
mov    $0x32,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
movq   $0x0,(%r15)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.user_regs_struct = type { i32 }
@PTRACE_SETREGS = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"(%s:%d: error: %d [%s]) Failed to set registers of target process %d\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dismantl/linux-injector/refs/heads/master/ptrace.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
define i32 @ptrace_setregs(i32 %0, %struct.user_regs_struct* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.user_regs_struct*
store i32 %0, i32* %4
store %struct.user_regs_struct* %1, %struct.user_regs_struct** %5
br label %6
6: ; preds = %2
%7 = load i32, i32* @PTRACE_SETREGS
%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)
%11 = icmp eq i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = load i64, i64* @errno
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %21
18: ; preds = %12
%19 = load i64, i64* @errno
%20 = call i8* @strerror(i64 %19)
br label %21
21: ; preds = %18, %17
%22 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %17 ], [ %20, %18 ]
%23 = load i32, i32* %4
%24 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 50, i64 %14, i8* %22, i32 %23)
store i64 0, i64* @errno
br label %27
25: ; preds = %6
br label %26
26: ; preds = %25
store i32 1, i32* %3
br label %28
27: ; preds = %21
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i32 }
@PTRACE_SETREGS = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"(%s:%d: error: %d [%s]) Failed to set registers of target process %d\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dismantl/linux-injector/refs/heads/master/ptrace.c\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"None\00"
define i32 @ptrace_setregs(i32 %0, %struct.user_regs_struct* %1) {
%3 = load i32, i32* @PTRACE_SETREGS
%4 = tail call i64 @ptrace(i32 %3, i32 %0, i32* null, %struct.user_regs_struct* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i8* @strerror(i64 %8)
br label %12
12: ; preds = %6, %10
%13 = phi i8* [ %11, %10 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %6 ]
%14 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 50, i64 %8, i8* %13, i32 %0)
store i64 0, i64* @errno
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %16
}