#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 *const *, char **);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[], char *envp[]) {
  printf("in main...%d\n", getpid());
  char *const argv2[] = {"main", "hahah", "hehe", NULL};
  execve("./main", argv2, envp);
  printf("out main...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c98(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c95(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c92(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c8f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rdi
call   1050 <execve@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xeaa(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movaps 0x2caa(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c8e(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe9c(%rip),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1060 <execve@plt>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"in main...%d\0A\00"
@.str.1 = [5 x i8] c"main\00"
@.str.2 = [6 x i8] c"hahah\00"
@.str.3 = [5 x i8] c"hehe\00"
@__const.main.argv2 = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 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 = [7 x i8] c"./main\00"
@.str.5 = [13 x i8] c"out main...\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [4 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = call i32 (...) @getpid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = bitcast [4 x i8*]* %8 to i8*
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%13 = load i8**, i8*** %7
%14 = call i32 @execve(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %12, i8** %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"in main...%d\0A\00"
@.str.1 = [5 x i8] c"main\00"
@.str.2 = [6 x i8] c"hahah\00"
@.str.3 = [5 x i8] c"hehe\00"
@__const.main.argv2 = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 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 = [7 x i8] c"./main\00"
@str = [12 x i8] c"out main...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = alloca [4 x i8*]
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = bitcast [4 x i8*]* %4 to i8*
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%9 = call i32 @execve(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %8, i8** %2)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}