#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*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int main() {
  pid_t pid = fork();
  if (pid < 0)
    printf("Error : fork() \n");
  else if (pid == 0)
    _exit(0);
  else {
    sleep(2);
    system("ps -o pid,ppid,stat,tty,comm");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1186 <main+0x36>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
jmp    11b3 <main+0x63>
cmpq   $0x0,-0x10(%rbp)
jne    1198 <main+0x48>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe68(%rip),%rdi
call   1040 <system@plt>
jmp    11b3 <main+0x63>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1177 <main+0x27>
je     1187 <main+0x37>
mov    $0x2,%edi
call   1060 <sleep@plt>
lea    0xe90(%rip),%rdi
call   1050 <system@plt>
jmp    1183 <main+0x33>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Error : fork() \0A\00"
@.str.1 = [29 x i8] c"ps -o pid,ppid,stat,tty,comm\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %17
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @_exit(i32 0)
unreachable
13: ; preds = %8
%14 = call i32 @sleep(i32 2)
%15 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13
br label %17
17: ; preds = %16, %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"ps -o pid,ppid,stat,tty,comm\00"
@str = [16 x i8] c"Error : fork() \00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @_exit(i32 0)
unreachable
9: ; preds = %5
%10 = tail call i32 @sleep(i32 2)
%11 = tail call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %3
ret i32 0
}