#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*/ execve(char *, char **, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  int res;
  res = fork();
  if (res > 0) {
    char *argv[] = {
        "/bin/echo",
        "hello",
        "world",
        NULL,
    };
    char *envp[] = {
        NULL,
    };
    fprintf(stderr, "child!\n");
    execve("/bin/echo", argv, envp);
  } else {
    fprintf(stderr, "parent: %d\n", res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11cf <main+0x8f>
mov    0x2c86(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c83(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c7d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    0xe3b(%rip),%rdi
call   1040 <execve@plt>
jmp    11e9 <main+0xa9>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jle    118f <main+0x5f>
movaps 0x2cba(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c9e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe82(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <execve@plt>
jmp    11a8 <main+0x78>
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7f(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/bin/echo\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [6 x i8] c"world\00"
@__const.main.argv = [4 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [8 x i8] c"child!\0A\00"
@.str.4 = [12 x i8] c"parent: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8*]
%4 = alloca [1 x i8*]
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = bitcast [4 x i8*]* %3 to i8*
%10 = bitcast [1 x i8*]* %4 to i8*
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%14 = getelementptr inbounds [1 x i8*], [1 x i8*]* %4, i64 0, i64 0
%15 = call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %13, i8** %14)
br label %20
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/echo\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [6 x i8] c"world\00"
@__const.main.argv = [4 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [8 x i8] c"child!\0A\00"
@.str.4 = [12 x i8] c"parent: %d\0A\00"
define i32 @main() {
%1 = alloca [4 x i8*]
%2 = alloca [1 x i8*]
%3 = tail call i32 (...) @fork()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = bitcast [4 x i8*]* %1 to i8*
%7 = bitcast [1 x i8*]* %2 to i8*
%8 = bitcast [1 x i8*]* %2 to i64*
store i64 0, i64* %8
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%12 = getelementptr inbounds [1 x i8*], [1 x i8*]* %2, i64 0, i64 0
%13 = call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %11, i8** %12)
br label %17
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %3)
br label %17
17: ; preds = %14, %5
ret i32 0
}