#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*/ execlp(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  char *pEchoParam[] = {"echo", "Hello", "world for execvp", "!", (char *)NULL};
  if (fork() == 0) {
    execlp("echo", "echo", "Hello", "world 1", "!", (char *)NULL);
    perror("exec one failed!\n");
    exit(0);
  }
  if (fork() == 0) {
    execvp("echo", pEchoParam);
    perror("exec one failed!\n");
    exit(0);
  }
  if (fork() == 0) {
    execlp("echo", "echo", "Hello", "world 3", "!", (char *)NULL);
    perror("exec one failed!\n");
    exit(0);
  }
  printf("end of process\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)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xe63(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe58(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe5e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    120f <main+0x9f>
lea    0xe26(%rip),%rsi
lea    0xe24(%rip),%rdx
lea    0xe36(%rip),%rcx
lea    0xe2d(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1080 <execlp@plt>
lea    0xe23(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1243 <main+0xd3>
lea    -0x40(%rbp),%rsi
lea    0xdd5(%rip),%rdi
call   1060 <execvp@plt>
lea    0xdef(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1290 <main+0x120>
lea    0xda5(%rip),%rsi
lea    0xda3(%rip),%rdx
lea    0xdcf(%rip),%rcx
lea    0xdac(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1080 <execlp@plt>
lea    0xda2(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movq   $0x0,0x20(%rsp)
lea    0xe8c(%rip),%rax
mov    %rax,(%rsp)
lea    0xe86(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe80(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe85(%rip),%rax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11d3 <main+0x73>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ea <main+0x8a>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11fb <main+0x9b>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
lea    0xe26(%rip),%rdi
lea    0xe24(%rip),%rdx
lea    0xe36(%rip),%rcx
jmp    1210 <main+0xb0>
lea    0xe0f(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
jmp    1222 <main+0xc2>
lea    0xdfe(%rip),%rdi
lea    0xdfc(%rip),%rdx
lea    0xe28(%rip),%rcx
lea    0xe05(%rip),%r8
mov    %rdi,%rsi
xor    %r9d,%r9d
call   1070 <execlp@plt>
lea    0xdfd(%rip),%rdi
call   1040 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"echo\00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [17 x i8] c"world for execvp\00"
@.str.3 = [2 x i8] c"!\00"
@.str.4 = [8 x i8] c"world 1\00"
@.str.5 = [18 x i8] c"exec one failed!\0A\00"
@.str.6 = [8 x i8] c"world 3\00"
@.str.7 = [16 x i8] c"end of process\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [5 x i8*]* %6 to i8*
%8 = bitcast i8* %7 to [5 x i8*]*
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8** %12
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* null)
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%24 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %23)
%25 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %19
%28 = call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* null)
%32 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"echo\00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [17 x i8] c"world for execvp\00"
@.str.3 = [2 x i8] c"!\00"
@.str.4 = [8 x i8] c"world 1\00"
@.str.5 = [18 x i8] c"exec one failed!\0A\00"
@.str.6 = [8 x i8] c"world 3\00"
@str = [15 x i8] c"end of process\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
%6 = bitcast i8** %5 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %10
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* null)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = tail call i64 (...) @fork()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7)
%22 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %17
%25 = tail call i64 (...) @fork()
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* null)
%29 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %24
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret i32 0
}