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

/* Variables and functions */
int /*<<< orphan*/ PTRACE_DETACH;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, scalar_t__,
                           char *, int);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int ptrace_detach(int pid) {
  do {
    if (!(ptrace(PTRACE_DETACH, (pid_t)pid, NULL, NULL) == 0)) {
      fprintf(stderr,
              "(%s:%d: error: %d [%s]) "
              "Failed to detach to 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",
              30, errno, errno == 0 ? "None" : strerror(errno), pid);
      errno = 0;
      goto error;
    }
  } while (0);
  return 1;
error:
  return 0;
}


x86 assembly (clang, -O0):
<ptrace_detach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
je     11e7 <ptrace_detach+0xb7>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e52(%rip),%rax
cmpq   $0x0,(%rax)
jne    1198 <ptrace_detach+0x68>
lea    0xf3d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ab <ptrace_detach+0x7b>
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%r9
mov    -0x8(%rbp),%eax
lea    0xe40(%rip),%rsi
lea    0xe78(%rip),%rdx
mov    $0x1e,%ecx
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    0x2df5(%rip),%rax
movq   $0x0,(%rax)
jmp    11f8 <ptrace_detach+0xc8>
jmp    11ec <ptrace_detach+0xbc>
movl   $0x1,-0x4(%rbp)
jmp    11ff <ptrace_detach+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace_detach>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
test   %rax,%rax
je     1178 <ptrace_detach+0x48>
mov    0x2e7f(%rip),%rax
mov    (%rax),%r14d
mov    0x2e6d(%rip),%r15
mov    (%r15),%rbx
test   %rbx,%rbx
je     117f <ptrace_detach+0x4f>
mov    %rbx,%rdi
call   1050 <strerror@plt>
mov    %rax,%r9
jmp    1186 <ptrace_detach+0x56>
mov    $0x1,%eax
jmp    11b0 <ptrace_detach+0x80>
lea    0xf46(%rip),%r9
mov    %ebp,(%rsp)
lea    0xe70(%rip),%rsi
lea    0xea8(%rip),%rdx
mov    %r14d,%edi
mov    $0x1e,%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):
@PTRACE_DETACH = global i32 0
@stderr = global i32 0
@.str = [63 x i8] c"(%s:%d: error: %d [%s]) Failed to detach to 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_detach(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
br label %4
4: ; preds = %1
%5 = load i32, i32* @PTRACE_DETACH
%6 = load i32, i32* %3
%7 = call i64 @ptrace(i32 %5, i32 %6, i32* null, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = load i64, i64* @errno
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %18
15: ; preds = %9
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
br label %18
18: ; preds = %15, %14
%19 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %14 ], [ %17, %15 ]
%20 = load i32, i32* %3
%21 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 30, i64 %11, i8* %19, i32 %20)
store i64 0, i64* @errno
br label %24
22: ; preds = %4
br label %23
23: ; preds = %22
store i32 1, i32* %2
br label %25
24: ; preds = %18
store i32 0, i32* %2
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@PTRACE_DETACH = global i32 0
@stderr = global i32 0
@.str = [63 x i8] c"(%s:%d: error: %d [%s]) Failed to detach to 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_detach(i32 %0) {
%2 = load i32, i32* @PTRACE_DETACH
%3 = tail call i64 @ptrace(i32 %2, i32 %0, i32* null, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i8* @strerror(i64 %7)
br label %11
11: ; preds = %5, %9
%12 = phi i8* [ %10, %9 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %5 ]
%13 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 30, i64 %7, i8* %12, i32 %0)
store i64 0, i64* @errno
br label %14
14: ; preds = %1, %11
%15 = phi i32 [ 0, %11 ], [ 1, %1 ]
ret i32 %15
}