#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);
int execl(char *, char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int vfork();
int main(int argc, char *argv[]) {
  int pid;
  int result;
  if (pid = vfork())
    fprintf(stderr, "parent: I see kid with pid = %d\n", pid);
  else {
    sleep(5);
    result = execl("/bin/sh", "/bin/sh", "-c", "sleep 10; date", 0);
    fprintf(stderr, "result: %d\n", result);
    _exit(1);
  }
  sleep(5);
  fprintf(stderr, "parent exit\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
call   1050 <vfork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     118f <main+0x3f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11e0 <main+0x90>
mov    $0x5,%edi
call   1070 <sleep@plt>
lea    0xe81(%rip),%rsi
lea    0xe82(%rip),%rdx
lea    0xe7e(%rip),%rcx
xor    %r8d,%r8d
mov    %rsi,%rdi
call   1060 <execl@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
call   1050 <vfork@plt>
test   %eax,%eax
je     119f <main+0x4f>
mov    %eax,%edx
mov    0x2e7a(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe90(%rip),%rsi
xor    %r14d,%r14d
mov    %r14d,%eax
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    0x0(%rbp),%edi
lea    0xeb8(%rip),%rsi
mov    %r14d,%eax
call   1040 <fprintf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x5,%edi
call   1070 <sleep@plt>
lea    0xe71(%rip),%rdi
lea    0xe72(%rip),%rdx
lea    0xe6e(%rip),%rcx
xor    %ebx,%ebx
mov    %rdi,%rsi
mov    %ebx,%r8d
call   1060 <execl@plt>
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%edi
lea    0xe60(%rip),%rsi
mov    %eax,%edx
mov    %ebx,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"parent: I see kid with pid = %d\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [15 x i8] c"sleep 10; date\00"
@.str.4 = [12 x i8] c"result: %d\0A\00"
@.str.5 = [13 x i8] c"parent exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i32 @vfork()
store i32 %7, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* %5
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %20
13: ; preds = %2
%14 = call i32 @sleep(i32 5)
%15 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), 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 ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 0)
store i32 %15, i32* %6
%16 = load i32, i32* @stderr
%17 = load i32, i32* %6
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 @_exit(i32 1)
unreachable
20: ; preds = %9
%21 = call i32 @sleep(i32 5)
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"parent: I see kid with pid = %d\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [15 x i8] c"sleep 10; date\00"
@.str.4 = [12 x i8] c"result: %d\0A\00"
@.str.5 = [13 x i8] c"parent exit\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = call i32 @vfork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3)
%8 = call i32 @sleep(i32 5)
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
11: ; preds = %2
%12 = call i32 @sleep(i32 5)
%13 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), 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 ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 0)
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%16 = call i32 @_exit(i32 1)
unreachable
}