#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*/ execl(char *, char *, char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  pid = fork();
  if (pid > 0) {
    int status;
    wait(&status);
    printf("exec end\n");
  } else if (pid == 0) {
    sleep(3);
    execl("/bin/echo", "echo", "ok", (char *)0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    118f <main+0x3f>
lea    -0x14(%rbp),%rdi
call   1060 <wait@plt>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
jmp    11c7 <main+0x77>
cmpq   $0x0,-0x10(%rbp)
jne    11c2 <main+0x72>
mov    $0x3,%edi
call   1050 <sleep@plt>
lea    0xe5f(%rip),%rdi
lea    0xe5d(%rip),%rsi
lea    0xe5b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <execl@plt>
jmp    11c7 <main+0x77>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1175 <main+0x25>
lea    0x4(%rsp),%rdi
call   1060 <wait@plt>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
jmp    119d <main+0x4d>
jne    119d <main+0x4d>
mov    $0x3,%edi
call   1050 <sleep@plt>
lea    0xe78(%rip),%rdi
lea    0xe76(%rip),%rsi
lea    0xe74(%rip),%rdx
xor    %ecx,%ecx
call   1040 <execl@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"exec end\0A\00"
@.str.1 = [10 x i8] c"/bin/echo\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"ok\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @wait(i32* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %0
%11 = load i64, i64* %2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @sleep(i32 3)
%15 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 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
16: ; preds = %13, %10
br label %17
17: ; preds = %16, %7
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"/bin/echo\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"ok\00"
@str = [9 x i8] c"exec end\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i64 (...) @fork()
%3 = icmp sgt i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = bitcast i32* %1 to i8*
%6 = call i32 @wait(i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %13
8: ; preds = %0
%9 = icmp eq i64 %2, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @sleep(i32 3)
%12 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 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 %13
13: ; preds = %8, %10, %4
ret i32 0
}