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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PTRACE_DETACH;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ptrace(int /*<<< orphan*/, int, int /*<<< orphan*/,
                  int /*<<< orphan*/);
void detach(pid_t pid) {
  printf("detach\n");
  printf("Detaching from PID %u\n", pid);
  if (ptrace(PTRACE_DETACH, pid, 0, 0) < 0)
    err(EXIT_FAILURE, "ptrace (DETACH)");
}


x86 assembly (clang, -O0):
<detach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <ptrace@plt>
cmp    $0x0,%rax
jge    118e <detach+0x5e>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1040 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detach>:
push   %rbx
mov    %edi,%ebx
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
js     117a <detach+0x3a>
pop    %rbx
ret
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
pop    %rbx
jmp    1050 <err@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"detach\0A\00"
@.str.1 = [23 x i8] c"Detaching from PID %u\0A\00"
@PTRACE_DETACH = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"ptrace (DETACH)\00"
define void @detach(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @PTRACE_DETACH
%7 = load i32, i32* %2
%8 = call i64 @ptrace(i32 %6, i32 %7, i32 0, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @err(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Detaching from PID %u\0A\00"
@PTRACE_DETACH = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"ptrace (DETACH)\00"
@str = [7 x i8] c"detach\00"
define void @detach(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%4 = load i32, i32* @PTRACE_DETACH
%5 = tail call i64 @ptrace(i32 %4, i32 %0, i32 0, i32 0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @err(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
ret void
}