#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*/ execvp(char *, char **);
int /*<<< orphan*/ fail(char *);
void *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char **cmd_line = NULL;
  int i = 0;
  cmd_line = malloc(sizeof(char *) * (argc + 1));
  if (cmd_line == NULL)
    fail("Failed to allocate command line");
  cmd_line[0] = malloc(strlen(argv[0]) + 5);
  if (cmd_line[0] == NULL)
    fail("Failed to allocate command line");
  strcpy(cmd_line[0], argv[0]);
  strcat(cmd_line[0], ".run");
  for (i = 1; i < argc; i++)
    cmd_line[i] = argv[i];
  cmd_line[argc] = NULL;
  execvp(cmd_line[0], cmd_line);
  fail("Failed to execute application script");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x53>
lea    0xe52(%rip),%rdi
call   1040 <fail@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ed <main+0x8d>
lea    0xe18(%rip),%rdi
call   1040 <fail@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe12(%rip),%rsi
call   1080 <strcat@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124c <main+0xec>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121a <main+0xba>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <execvp@plt>
lea    0xdb2(%rip),%rdi
call   1040 <fail@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
lea    0x8(,%r14,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    119f <main+0x2f>
lea    0xe66(%rip),%rdi
call   1040 <fail@plt>
mov    (%r15),%rdi
call   1050 <strlen@plt>
lea    0x5(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r12)
test   %rax,%rax
jne    11c7 <main+0x57>
lea    0xe3e(%rip),%rdi
call   1040 <fail@plt>
mov    (%r15),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
cmp    $0x2,%r14d
jl     1202 <main+0x92>
mov    %r12,%rdi
add    $0x8,%rdi
add    $0x8,%r15
lea    -0x1(%r14),%edx
shl    $0x3,%rdx
mov    %r15,%rsi
call   1060 <memcpy@plt>
movslq %r14d,%rax
movq   $0x0,(%r12,%rax,8)
mov    (%r12),%rdi
mov    %r12,%rsi
call   1080 <execvp@plt>
lea    0xe05(%rip),%rdi
call   1040 <fail@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Failed to allocate command line\00"
@.str.1 = [5 x i8] c".run\00"
@.str.2 = [37 x i8] c"Failed to execute application script\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** null, i8*** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 8, %10
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
%14 = bitcast i8* %13 to i8**
store i8** %14, i8*** %6
%15 = load i8**, i8*** %6
%16 = icmp eq i8** %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 5
%25 = call i8* @malloc(i32 %24)
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 0
store i8* %25, i8** %27
%28 = load i8**, i8*** %6
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %19
%33 = call i32 @fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %19
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i8* %37, i8* %40)
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %46
46: ; preds = %60, %34
%47 = load i32, i32* %7
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %6
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
store i8* %55, i8** %59
br label %60
60: ; preds = %50
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %46
63: ; preds = %46
%64 = load i8**, i8*** %6
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
store i8* null, i8** %67
%68 = load i8**, i8*** %6
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = load i8**, i8*** %6
%72 = call i32 @execvp(i8* %70, i8** %71)
%73 = call i32 @fail(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [32 x i8] c"Failed to allocate command line\00"
@.str.1 = [5 x i8] c".run\00"
@.str.2 = [37 x i8] c"Failed to execute application script\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = shl i32 %0, 3
%4 = add i32 %3, 8
%5 = tail call i8* @malloc(i32 %4)
%6 = bitcast i8* %5 to i8**
%7 = icmp eq i8* %5, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %1
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 5
%14 = tail call i8* @malloc(i32 %13)
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i8*, i8** %1
%20 = tail call i32 @strcpy(i8* %14, i8* %19)
%21 = tail call i32 @strcat(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp sgt i32 %0, 1
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = getelementptr i8, i8* %5, i64 8
%25 = getelementptr i8*, i8** %1, i64 1
%26 = bitcast i8** %25 to i8*
%27 = add nsw i32 %0, -1
%28 = zext i32 %27 to i64
%29 = shl nuw nsw i64 %28, 3
br label %30
30: ; preds = %23, %18
%31 = sext i32 %0 to i64
%32 = getelementptr inbounds i8*, i8** %6, i64 %31
store i8* null, i8** %32
%33 = load i8*, i8** %6
%34 = tail call i32 @execvp(i8* %33, i8** %6)
%35 = tail call i32 @fail(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}