#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 uint32_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int GetFood();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void RunFeedMe(void) {
  int status = 0;
  uint32_t i;
  for (i = 0; i < (800); i++) {
    pid_t child_pid = fork();
    if (child_pid == 0) {
      printf("YUM, got %d bytes!\n", GetFood());
      break;
    } else {
      pid_t wait_pid = waitpid(child_pid, &status, 0);
      if (wait_pid == -1) {
        printf("Wait error!\n");
        exit(-1);
      }
      if (status == -1) {
        printf("Child IO error!\n");
        exit(-1);
      }
      printf("Child exit.\n");
      fflush(0);
    }
  }
}


x86 assembly (clang, -O0):
<RunFeedMe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x320,-0x8(%rbp)
jge    1235 <RunFeedMe+0xd5>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <RunFeedMe+0x55>
mov    $0x0,%al
call   1040 <GetFood@plt>
mov    %eax,%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <RunFeedMe+0xd5>
mov    -0x10(%rbp),%rdi
lea    -0x4(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11eb <RunFeedMe+0x8b>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpl   $0xffffffff,-0x4(%rbp)
jne    120d <RunFeedMe+0xad>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
jmp    1227 <RunFeedMe+0xc7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <RunFeedMe+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunFeedMe>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    $0x320,%ebp
lea    0xc(%rsp),%r14
lea    0xe83(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11dc <RunFeedMe+0x6c>
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     11fc <RunFeedMe+0x8c>
cmpl   $0xffffffff,0xc(%rsp)
je     1205 <RunFeedMe+0x95>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
add    $0xffffffff,%ebp
jne    11a0 <RunFeedMe+0x30>
jmp    11f3 <RunFeedMe+0x83>
xor    %eax,%eax
call   1050 <GetFood@plt>
lea    0xe16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
jmp    120c <RunFeedMe+0x9c>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"YUM, got %d bytes!\0A\00"
@.str.1 = [13 x i8] c"Wait error!\0A\00"
@.str.2 = [17 x i8] c"Child IO error!\0A\00"
@.str.3 = [13 x i8] c"Child exit.\0A\00"
define void @RunFeedMe() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %33, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 800
br i1 %7, label %8, label %36
8: ; preds = %5
%9 = call i64 (...) @fork()
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 (...) @GetFood()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %36
15: ; preds = %8
%16 = load i64, i64* %3
%17 = call i64 @waitpid(i64 %16, i32* %1, i32 0)
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = icmp eq i64 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %15
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @fflush(i32 0)
br label %32
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %5
36: ; preds = %12, %5
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"YUM, got %d bytes!\0A\00"
@str = [12 x i8] c"Child exit.\00"
@str.4 = [16 x i8] c"Child IO error!\00"
@str.5 = [12 x i8] c"Wait error!\00"
define void @RunFeedMe() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %3
3: ; preds = %0, %22
%4 = phi i32 [ 0, %0 ], [ %25, %22 ]
%5 = call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = call i64 @waitpid(i64 %5, i32* %1, i32 0)
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %7
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %3
%20 = call i32 (...) @GetFood()
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %27
22: ; preds = %13
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%24 = call i32 @fflush(i32 0)
%25 = add nuw nsw i32 %4, 1
%26 = icmp eq i32 %25, 800
br i1 %26, label %27, label %3
27: ; preds = %22, %19
ret void
}