#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*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ in_fork_child();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int status;
  int child;
  if ((child = fork()) == 0) {
    in_fork_child();
    _exit(0);
  }
  printf("After fork() in parent\n");
  fflush(stdout);
  waitpid(child, &status, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1197 <main+0x37>
mov    $0x0,%al
call   1040 <in_fork_child@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a2 <main+0x42>
mov    %eax,%ebx
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1050 <in_fork_child@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"After fork() in parent\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (...) @in_fork_child()
%12 = call i32 @_exit(i32 0)
unreachable
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = load i32, i32* %7
%18 = call i32 @waitpid(i32 %17, i32* %6, i32 0)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@str = [23 x i8] c"After fork() in parent\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (...) @in_fork_child()
%9 = tail call i32 @_exit(i32 0)
unreachable
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = call i32 @waitpid(i32 %5, i32* %3, i32 0)
ret i32 0
}