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

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  pid_t pid;
  if ((pid = fork()) < 0) {
    err_sys("error on fork()");
  } else if (pid == 0) {
    printf("child: I am gone\n");
    _exit(0);
  }
  sleep(5);
  system("ps f");
  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    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    119c <main+0x3c>
lea    0xe6e(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11bf <main+0x5f>
cmpq   $0x0,-0x18(%rbp)
jne    11ba <main+0x5a>
lea    0xe62(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    11bf <main+0x5f>
mov    $0x5,%edi
call   1070 <sleep@plt>
lea    0xe52(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     1182 <main+0x22>
jne    118e <main+0x2e>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xe77(%rip),%rdi
call   1050 <err_sys@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
lea    0xe71(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"error on fork()\00"
@.str.1 = [18 x i8] c"child: I am gone\0A\00"
@.str.2 = [5 x i8] c"ps f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @_exit(i32 0)
unreachable
17: ; preds = %11
br label %18
18: ; preds = %17, %9
%19 = call i32 @sleep(i32 5)
%20 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"error on fork()\00"
@.str.2 = [5 x i8] c"ps f\00"
@str = [17 x i8] c"child: I am gone\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @_exit(i32 0)
unreachable
12: ; preds = %7, %5
%13 = tail call i32 @sleep(i32 5)
%14 = tail call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}