#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*/ execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ puts(char *);
int main() {
  puts("begin==========");
  char *argv[] = {"/usr/bin/cal", "8", "2012", NULL};
  if (fork() == 0)
    execv("/usr/bin/cal", argv);
  else
    puts("end==========");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cae(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2ca8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ca5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
cmp    $0x0,%rax
jne    119d <main+0x6d>
lea    -0x30(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1040 <execv@plt>
jmp    11a9 <main+0x79>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
movaps 0x2cc9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2cad(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1171 <main+0x41>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
jmp    1180 <main+0x50>
lea    0xe98(%rip),%rdi
mov    %rsp,%rsi
call   1040 <execv@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"begin==========\00"
@.str.1 = [13 x i8] c"/usr/bin/cal\00"
@.str.2 = [2 x i8] c"8\00"
@.str.3 = [5 x i8] c"2012\00"
@__const.main.argv = [4 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [14 x i8] c"end==========\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8*]
store i32 0, i32* %1
%3 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [4 x i8*]* %2 to i8*
%5 = call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
%9 = call i32 @execv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %8)
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@.str = [16 x i8] c"begin==========\00"
@.str.1 = [13 x i8] c"/usr/bin/cal\00"
@.str.2 = [2 x i8] c"8\00"
@.str.3 = [5 x i8] c"2012\00"
@__const.main.argv = [4 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [14 x i8] c"end==========\00"
define i32 @main() {
%1 = alloca [4 x i8*]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = bitcast [4 x i8*]* %1 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%8 = call i32 @execv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %7)
br label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
ret i32 0
}