#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*/ file_exists(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read_num_from_file(char *);
int unlink(char *);
void run_child(void) {
  int i;
  int num;
  for (i = 0; i < 10; i++) {
    while (!file_exists("number.txt"))
      ;
    num = read_num_from_file("number.txt");
    printf("Child reads: %d\n", num);
    if (unlink("number.txt") == -1) {
      perror("unlink");
    }
  }
  printf("Child terminates\n");
}


x86 assembly (clang, -O0):
<run_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    11e8 <run_child+0x98>
jmp    116e <run_child+0x1e>
lea    0xe8b(%rip),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118f <run_child+0x3f>
jmp    1194 <run_child+0x44>
jmp    116e <run_child+0x1e>
lea    0xe65(%rip),%rdi
call   1070 <read_num_from_file@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe45(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    11d5 <run_child+0x85>
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
jmp    11da <run_child+0x8a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115f <run_child+0xf>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_child>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rbx
lea    0xe96(%rip),%r14
lea    0xea0(%rip),%r15
xor    %ebp,%ebp
jmp    1190 <run_child+0x30>
add    $0x1,%ebp
cmp    $0xa,%ebp
je     11c7 <run_child+0x67>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <file_exists@plt>
test   %eax,%eax
je     1190 <run_child+0x30>
mov    %rbx,%rdi
call   1080 <read_num_from_file@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1180 <run_child+0x20>
mov    %r15,%rdi
call   1070 <perror@plt>
jmp    1180 <run_child+0x20>
lea    0xe55(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <puts@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"number.txt\00"
@.str.1 = [17 x i8] c"Child reads: %d\0A\00"
@.str.2 = [7 x i8] c"unlink\00"
@str = [17 x i8] c"Child terminates\00"
define void @run_child() {
br label %1
1: ; preds = %0, %13
%2 = phi i32 [ 0, %0 ], [ %14, %13 ]
br label %3
3: ; preds = %1, %3
%4 = tail call i32 @file_exists(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %3, label %6
6: ; preds = %3
%7 = tail call i32 @read_num_from_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %6, %11
%14 = add nuw nsw i32 %2, 1
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %1
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
ret void
}