#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*/ PTRACE_DETACH;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int ptrace(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/);
int detach_pid(pid_t pid) {
  if (pid <= 1) {
    printf("pid error\n");
    return -1;
  }
  if (-1 == ptrace(PTRACE_DETACH, pid, 0, 0)) {
    perror("ptrace PTRACE_DETACH");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<detach_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     115d <detach_pid+0x2d>
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <detach_pid+0x70>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <ptrace@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1199 <detach_pid+0x69>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <detach_pid+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detach_pid>:
push   %rbx
cmp    $0x1,%edi
jg     1149 <detach_pid+0x19>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1164 <detach_pid+0x34>
mov    %edi,%esi
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
cmp    $0xffffffff,%eax
je     1168 <detach_pid+0x38>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
jmp    1142 <detach_pid+0x12>

LLVM IR (-O0):
@.str = [11 x i8] c"pid error\0A\00"
@PTRACE_DETACH = global i32 0
@.str.1 = [21 x i8] c"ptrace PTRACE_DETACH\00"
define i32 @detach_pid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sle i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %16
8: ; preds = %1
%9 = load i32, i32* @PTRACE_DETACH
%10 = load i32, i32* %3
%11 = call i32 @ptrace(i32 %9, i32 %10, i32 0, i32 0)
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %16
15: ; preds = %8
store i32 0, i32* %2
br label %16
16: ; preds = %15, %13, %6
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@PTRACE_DETACH = global i32 0
@.str.1 = [21 x i8] c"ptrace PTRACE_DETACH\00"
@str = [10 x i8] c"pid error\00"
define i32 @detach_pid(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %11
5: ; preds = %1
%6 = load i32, i32* @PTRACE_DETACH
%7 = tail call i32 @ptrace(i32 %6, i32 %0, i32 0, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %5, %9, %3
%12 = phi i32 [ -1, %3 ], [ -1, %9 ], [ 0, %5 ]
ret i32 %12
}