#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execl(char *, char *, char *, int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int cloud_pid = fork();
  if (cloud_pid > 0) {
    fprintf(stderr, "Tracing pid %d\n", cloud_pid);
    int cloud = open("/dev/cloudover", O_RDONLY);
    if (cloud < 0) {
      fprintf(stderr, "Cannot open cloudover dev\n");
      return 1;
    }
    ioctl(cloud, 0, cloud_pid);
    close(cloud);
  } else if (cloud_pid == 0) {
    sleep(20);
    fprintf(stderr, "go!\n");
    execl("/bin/cat", "/bin/cat", "/etc/passwd", 0x00);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1213 <main+0xa3>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11f9 <main+0x89>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <main+0xf2>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    125b <main+0xeb>
cmpl   $0x0,-0x14(%rbp)
jne    1256 <main+0xe6>
mov    $0x14,%edi
call   1080 <sleep@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xdfa(%rip),%rsi
lea    0xdfc(%rip),%rdx
xor    %ecx,%ecx
mov    %rsi,%rdi
call   1070 <execl@plt>
jmp    125b <main+0xeb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jle    11d3 <main+0x63>
mov    %eax,%ebp
mov    0x2e4a(%rip),%r15
mov    (%r15),%edi
lea    0xe68(%rip),%rsi
xor    %r14d,%r14d
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1213 <main+0xa3>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    122a <main+0xba>
jne    122a <main+0xba>
mov    $0x14,%edi
call   1080 <sleep@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe3f(%rip),%rdi
lea    0xe41(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1070 <execl@plt>
jmp    122a <main+0xba>
mov    (%r15),%edi
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Tracing pid %d\0A\00"
@.str.1 = [15 x i8] c"/dev/cloudover\00"
@O_RDONLY = global i32 0
@.str.2 = [27 x i8] c"Cannot open cloudover dev\0A\00"
@.str.3 = [5 x i8] c"go!\0A\00"
@.str.4 = [9 x i8] c"/bin/cat\00"
@.str.5 = [12 x i8] c"/etc/passwd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %6
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %38
22: ; preds = %11
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = call i32 @ioctl(i32 %23, i32 0, i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
br label %37
28: ; preds = %2
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = call i32 @sleep(i32 20)
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %36
36: ; preds = %31, %28
br label %37
37: ; preds = %36, %22
store i32 0, i32* %3
br label %38
38: ; preds = %37, %19
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Tracing pid %d\0A\00"
@.str.1 = [15 x i8] c"/dev/cloudover\00"
@O_RDONLY = global i32 0
@.str.2 = [27 x i8] c"Cannot open cloudover dev\0A\00"
@.str.3 = [5 x i8] c"go!\0A\00"
@.str.4 = [9 x i8] c"/bin/cat\00"
@.str.5 = [12 x i8] c"/etc/passwd\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %24
14: ; preds = %5
%15 = tail call i32 @ioctl(i32 %9, i32 0, i32 %3)
%16 = tail call i32 @close(i32 %9)
br label %24
17: ; preds = %2
%18 = icmp eq i32 %3, 0
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = tail call i32 @sleep(i32 20)
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %24
24: ; preds = %19, %17, %14, %11
%25 = phi i32 [ 1, %11 ], [ 0, %14 ], [ 0, %17 ], [ 0, %19 ]
ret i32 %25
}