#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*/ assert(int);
int fork();
int /*<<< orphan*/ remove_dir();
int setup_dir();
int /*<<< orphan*/ test_logscan();
int /*<<< orphan*/ test_purge();
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ret = 0;
  pid_t child;
  ret = setup_dir();
  if (ret < 0) {
    return ret;
  }
  child = fork();
  if (child == -1) {
    return -1;
  } else if (child > 0) {
    int status = 0;
    waitpid(child, &status, 0);
    remove_dir();
    return ret;
  } else {
    assert(child == 0);
    test_logscan();
    test_purge();
  }
  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)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1070 <setup_dir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ac <main+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1228 <main+0xb8>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cc <main+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <main+0xb8>
cmpl   $0x0,-0x18(%rbp)
jle    11fd <main+0x8d>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    $0x0,%al
call   1050 <remove_dir@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1228 <main+0xb8>
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1030 <test_logscan@plt>
mov    $0x0,%al
call   1060 <test_purge@plt>
jmp    1221 <main+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <setup_dir@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11d3 <main+0x63>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11b1 <main+0x41>
test   %eax,%eax
jle    11b8 <main+0x48>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
xor    %eax,%eax
call   1050 <remove_dir@plt>
jmp    11d3 <main+0x63>
mov    $0xffffffff,%ebx
jmp    11d3 <main+0x63>
sete   %al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <test_logscan@plt>
xor    %eax,%eax
call   1060 <test_purge@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i32 (...) @setup_dir()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %6
store i32 %13, i32* %3
br label %36
14: ; preds = %2
%15 = call i32 (...) @fork()
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %3
br label %36
19: ; preds = %14
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
store i32 0, i32* %8
%23 = load i32, i32* %7
%24 = call i32 @waitpid(i32 %23, i32* %8, i32 0)
%25 = call i32 (...) @remove_dir()
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %36
27: ; preds = %19
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 (...) @test_logscan()
%33 = call i32 (...) @test_purge()
br label %34
34: ; preds = %27
br label %35
35: ; preds = %34
store i32 0, i32* %3
br label %36
36: ; preds = %35, %22, %18, %12
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @setup_dir()
%5 = icmp slt i32 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, -1
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = icmp sgt i32 %7, 0
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%13 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%14 = call i32 (...) @remove_dir()
br label %21
15: ; preds = %9
%16 = icmp eq i32 %7, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 (...) @test_logscan()
%20 = tail call i32 (...) @test_purge()
br label %21
21: ; preds = %6, %2, %15, %11
%22 = phi i32 [ %4, %11 ], [ 0, %15 ], [ %4, %2 ], [ -1, %6 ]
ret i32 %22
}