#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 */
scalar_t__ file_exists(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ write_num_to_file(int, char *);
void run_parent(void) {
  int i;
  int num;
  for (i = 0; i < 10; i++) {
    while (file_exists("number.txt"))
      ;
    num = rand();
    printf("Parent generates: %d\n", num);
    write_num_to_file(num, "number.txt");
  }
  printf("Parent terminates\n");
}


x86 assembly (clang, -O0):
<run_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    11b1 <run_parent+0x71>
jmp    115e <run_parent+0x1e>
lea    0xe9b(%rip),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     1179 <run_parent+0x39>
jmp    115e <run_parent+0x1e>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe62(%rip),%rsi
call   1050 <write_num_to_file@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <run_parent+0xf>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_parent>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    1160 <run_parent+0x10>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe73(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    11a0 <run_parent+0x50>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe33(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    11e0 <run_parent+0x90>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xe0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf3(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    1220 <run_parent+0xd0>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xdce(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb3(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    1260 <run_parent+0x110>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xd8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd73(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    12a0 <run_parent+0x150>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xd4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd33(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    12e0 <run_parent+0x190>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xd0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcf3(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    1320 <run_parent+0x1d0>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xcce(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcb3(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    1360 <run_parent+0x210>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xc8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc73(%rip),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <write_num_to_file@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    13a0 <run_parent+0x250>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebx
lea    0xc4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc33(%rip),%rsi
mov    %ebx,%edi
call   1060 <write_num_to_file@plt>
lea    0xc46(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"number.txt\00"
@.str.1 = [22 x i8] c"Parent generates: %d\0A\00"
@.str.2 = [19 x i8] c"Parent terminates\0A\00"
define void @run_parent() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 10
br i1 %5, label %6, label %20
6: ; preds = %3
br label %7
7: ; preds = %10, %6
%8 = call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
br label %7
11: ; preds = %7
%12 = call i32 (...) @rand()
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @write_num_to_file(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %11
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %3
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"number.txt\00"
@.str.1 = [22 x i8] c"Parent generates: %d\0A\00"
@str = [18 x i8] c"Parent terminates\00"
define void @run_parent() {
br label %1
1: ; preds = %0, %1
%2 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %1
4: ; preds = %1
%5 = tail call i32 (...) @rand()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = tail call i32 @write_num_to_file(i32 %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %8, %4
%9 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %8
11: ; preds = %8
%12 = tail call i32 (...) @rand()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @write_num_to_file(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %15, %11
%16 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %15
18: ; preds = %15
%19 = tail call i32 (...) @rand()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = tail call i32 @write_num_to_file(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %22, %18
%23 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %22
25: ; preds = %22
%26 = tail call i32 (...) @rand()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = tail call i32 @write_num_to_file(i32 %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %29, %25
%30 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %29
32: ; preds = %29
%33 = tail call i32 (...) @rand()
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = tail call i32 @write_num_to_file(i32 %33, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %36, %32
%37 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %36
39: ; preds = %36
%40 = tail call i32 (...) @rand()
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = tail call i32 @write_num_to_file(i32 %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %43, %39
%44 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %43
46: ; preds = %43
%47 = tail call i32 (...) @rand()
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = tail call i32 @write_num_to_file(i32 %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %50, %46
%51 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %50
53: ; preds = %50
%54 = tail call i32 (...) @rand()
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = tail call i32 @write_num_to_file(i32 %54, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %57
57: ; preds = %57, %53
%58 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %57
60: ; preds = %57
%61 = tail call i32 (...) @rand()
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%63 = tail call i32 @write_num_to_file(i32 %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %64
64: ; preds = %64, %60
%65 = tail call i64 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %64
67: ; preds = %64
%68 = tail call i32 (...) @rand()
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %68)
%70 = tail call i32 @write_num_to_file(i32 %68, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
ret void
}