#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*/ create_child();
int /*<<< orphan*/ del_child();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_child();
int main() {
  int ndx;
  printf("begin\n");
  for (ndx = 1; ndx < 5; ++ndx) {
    create_child();
    run_child();
    del_child();
    printf("child fiber returned\n");
    printf("\n");
  }
  printf("done\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11a7 <main+0x67>
mov    $0x0,%al
call   1050 <create_child@plt>
mov    $0x0,%al
call   1060 <run_child@plt>
mov    $0x0,%al
call   1030 <del_child@plt>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <main+0x22>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1060 <create_child@plt>
xor    %eax,%eax
call   1070 <run_child@plt>
xor    %eax,%eax
call   1030 <del_child@plt>
lea    0xe92(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <create_child@plt>
xor    %eax,%eax
call   1070 <run_child@plt>
xor    %eax,%eax
call   1030 <del_child@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <create_child@plt>
xor    %eax,%eax
call   1070 <run_child@plt>
xor    %eax,%eax
call   1030 <del_child@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <create_child@plt>
xor    %eax,%eax
call   1070 <run_child@plt>
xor    %eax,%eax
call   1030 <del_child@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdff(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"begin\0A\00"
@.str.1 = [22 x i8] c"child fiber returned\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"done\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 5
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = call i32 (...) @create_child()
%9 = call i32 (...) @run_child()
%10 = call i32 (...) @del_child()
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %7
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %4
16: ; preds = %4
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [6 x i8] c"begin\00"
@str.4 = [5 x i8] c"done\00"
@str.5 = [21 x i8] c"child fiber returned\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @create_child()
%3 = tail call i32 (...) @run_child()
%4 = tail call i32 (...) @del_child()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
%7 = tail call i32 (...) @create_child()
%8 = tail call i32 (...) @run_child()
%9 = tail call i32 (...) @del_child()
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 (...) @create_child()
%13 = tail call i32 (...) @run_child()
%14 = tail call i32 (...) @del_child()
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%16 = tail call i32 @putchar(i32 10)
%17 = tail call i32 (...) @create_child()
%18 = tail call i32 (...) @run_child()
%19 = tail call i32 (...) @del_child()
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}