#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*/ err_sys(char *);
int /*<<< orphan*/ execl(char *, char *, char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ vfork();
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  pid = vfork();
  if (pid < 0)
    err_sys("vfork error");
  else if (pid == 0) {
    execl("/bin/ps", "ps", "ax", (char *)0);
  } else {
    printf("this is parent\n");
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <vfork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1186 <main+0x36>
lea    0xe84(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11ce <main+0x7e>
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <main+0x64>
lea    0xe74(%rip),%rdi
lea    0xe72(%rip),%rsi
lea    0xe6e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execl@plt>
jmp    11c9 <main+0x79>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
jmp    11ce <main+0x7e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
js     1174 <main+0x24>
je     1182 <main+0x32>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <wait@plt>
jmp    119e <main+0x4e>
lea    0xe85(%rip),%rdi
call   1040 <err_sys@plt>
jmp    119e <main+0x4e>
lea    0xe83(%rip),%rdi
lea    0xe81(%rip),%rsi
lea    0xe7d(%rip),%rdx
xor    %ecx,%ecx
call   1060 <execl@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"vfork error\00"
@.str.1 = [8 x i8] c"/bin/ps\00"
@.str.2 = [3 x i8] c"ps\00"
@.str.3 = [3 x i8] c"ax\00"
@.str.4 = [16 x i8] c"this is parent\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @vfork()
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 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 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 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
br label %16
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @wait(i32* null)
br label %16
16: ; preds = %13, %11
br label %17
17: ; preds = %16, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"vfork error\00"
@.str.1 = [8 x i8] c"/bin/ps\00"
@.str.2 = [3 x i8] c"ps\00"
@.str.3 = [3 x i8] c"ax\00"
@str = [15 x i8] c"this is parent\00"
define i32 @main() {
%1 = tail call i64 (...) @vfork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 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 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
br label %12
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @wait(i32* null)
br label %12
12: ; preds = %7, %9, %3
ret i32 0
}