#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*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quit();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int *);
int main() {
  register int i;
  int k;
  printf("Test 12 ");
  fflush(stdout);
  system("rm -rf DIR_12; mkdir DIR_12");
  chdir("DIR_12");
  for (i = 0; i < 1000; i++)
    switch (fork()) {
    case 0:
      exit(1);
      break;
    case -1:
      printf("fork broke\n");
      exit(1);
    default:
      wait(&k);
      break;
    }
  quit();
  return (-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe59(%rip),%rdi
call   1040 <system@plt>
lea    0xe62(%rip),%rdi
call   1030 <chdir@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    123b <main+0xbb>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0xffffffff,%eax
je     1209 <main+0x89>
jmp    11ef <main+0x6f>
mov    -0x10(%rbp),%eax
test   %eax,%eax
jne    121f <main+0x9f>
jmp    11ff <main+0x7f>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0xc(%rbp),%rdi
call   1090 <wait@plt>
jmp    122d <main+0xad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c8 <main+0x48>
mov    $0x0,%al
call   1060 <quit@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe66(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    0xe55(%rip),%rdi
call   1050 <system@plt>
lea    0xe5e(%rip),%rdi
call   1040 <chdir@plt>
mov    $0x3e8,%ebp
lea    0x4(%rsp),%rbx
nop
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     1200 <main+0x70>
test   %eax,%eax
je     120c <main+0x7c>
mov    %rbx,%rdi
call   10a0 <wait@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x40>
xor    %eax,%eax
call   1070 <quit@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Test 12 \00"
@stdout = global i32 0
@.str.1 = [28 x i8] c"rm -rf DIR_12; mkdir DIR_12\00"
@.str.2 = [7 x i8] c"DIR_12\00"
@.str.3 = [12 x i8] c"fork broke\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %9
9: ; preds = %22, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = call i32 (...) @fork()
switch i32 %13, label %19 [
i32 0, label %14
i32 -1, label %16
]
14: ; preds = %12
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = call i32 @wait(i32* %3)
br label %21
21: ; preds = %19
br label %22
22: ; preds = %21
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %9
25: ; preds = %9
%26 = call i32 (...) @quit()
ret i32 -1
}

LLVM IR (-O2):
@.str = [9 x i8] c"Test 12 \00"
@stdout = global i32 0
@.str.1 = [28 x i8] c"rm -rf DIR_12; mkdir DIR_12\00"
@.str.2 = [7 x i8] c"DIR_12\00"
@str = [11 x i8] c"fork broke\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = tail call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %0, %16
%9 = phi i32 [ 0, %0 ], [ %18, %16 ]
%10 = call i32 (...) @fork()
switch i32 %10, label %16 [
i32 0, label %11
i32 -1, label %13
]
11: ; preds = %8
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = call i32 @wait(i32* %1)
%18 = add nuw nsw i32 %9, 1
%19 = icmp eq i32 %18, 1000
br i1 %19, label %20, label %8
20: ; preds = %16
%21 = call i32 (...) @quit()
ret i32 -1
}