#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 */

/* Variables and functions */
int /*<<< orphan*/ PTRACE_ATTACH;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int main(void) {
  long l;
  switch (fork()) {
  case -1:
    perror("fork");
    exit(1);
  case 0:
    errno = 0;
    ptrace(PTRACE_ATTACH, getppid(), NULL, NULL);
    if (errno != 0)
      perror("PTRACE_ATTACH");
    break;
  }
  sleep(600);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1199 <main+0x39>
jmp    1189 <main+0x29>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     11af <main+0x4f>
jmp    1201 <main+0xa1>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e22(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <ptrace@plt>
mov    0x2df1(%rip),%rax
cmpl   $0x0,(%rax)
je     11fc <main+0x9c>
lea    0xe0e(%rip),%rdi
call   1040 <perror@plt>
jmp    1201 <main+0xa1>
mov    $0x258,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     118a <main+0x2a>
cmp    $0xffffffff,%eax
jne    11bb <main+0x5b>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e47(%rip),%r14
movl   $0x0,(%r14)
mov    0x2e49(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <ptrace@plt>
cmpl   $0x0,(%r14)
jne    11cf <main+0x6f>
mov    $0x258,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2f(%rip),%rdi
call   1040 <perror@plt>
jmp    11bb <main+0x5b>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@errno = global i32 0
@PTRACE_ATTACH = global i32 0
@.str.1 = [14 x i8] c"PTRACE_ATTACH\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i32 (...) @fork()
switch i32 %3, label %16 [
i32 -1, label %4
i32 0, label %7
]
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @exit(i32 1)
unreachable
7: ; preds = %0
store i32 0, i32* @errno
%8 = load i32, i32* @PTRACE_ATTACH
%9 = call i32 (...) @getppid()
%10 = call i32 @ptrace(i32 %8, i32 %9, i32* null, i32* null)
%11 = load i32, i32* @errno
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
br label %16
16: ; preds = %0, %15
%17 = call i32 @sleep(i32 600)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@errno = global i32 0
@PTRACE_ATTACH = global i32 0
@.str.1 = [14 x i8] c"PTRACE_ATTACH\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %13 [
i32 -1, label %2
i32 0, label %5
]
2: ; preds = %0
%3 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
store i32 0, i32* @errno
%6 = load i32, i32* @PTRACE_ATTACH
%7 = tail call i32 (...) @getppid()
%8 = tail call i32 @ptrace(i32 %6, i32 %7, i32* null, i32* null)
%9 = load i32, i32* @errno
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %5, %11, %0
%14 = tail call i32 @sleep(i32 600)
ret i32 0
}