#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*/ STDIN_FILENO;
int /*<<< orphan*/ execve(char *, char **, int /*<<< orphan*/ *);
size_t read(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  char temp[1000];
  char *argarray[100];
  int i;
  for (i = 0; i < argc; i++) {
    argarray[i] = argv[i + 1];
  }
  temp[read(STDIN_FILENO, temp, 1000)] = '\0';
  argarray[i - 1] = temp;
  argarray[i] = NULL;
  execve(argv[1], argarray, NULL);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x730,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x724(%rbp)
mov    -0x724(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1189 <main+0x69>
mov    -0x10(%rbp),%rax
mov    -0x724(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x724(%rbp),%rax
mov    %rcx,-0x720(%rbp,%rax,8)
ff
mov    -0x724(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x724(%rbp)
jmp    1143 <main+0x23>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    -0x400(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <read@plt>
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rcx
mov    -0x724(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rcx,-0x720(%rbp,%rax,8)
ff
movslq -0x724(%rbp),%rax
movq   $0x0,-0x720(%rbp,%rax,8)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x720(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <execve@plt>
mov    $0x1,%eax
add    $0x730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x710,%rsp
mov    %rsi,%r14
test   %edi,%edi
jle    1158 <main+0x28>
mov    %edi,%ebp
lea    0x8(%r14),%rsi
mov    %edi,%edx
shl    $0x3,%rdx
mov    %rsp,%rdi
call   1050 <memcpy@plt>
jmp    115a <main+0x2a>
xor    %ebp,%ebp
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0x320(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1030 <read@plt>
movb   $0x0,0x320(%rsp,%rax,1)
movslq %ebp,%rax
mov    %rbx,-0x8(%rsp,%rax,8)
mov    %eax,%eax
movq   $0x0,(%rsp,%rax,8)
mov    0x8(%r14),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <execve@plt>
mov    $0x1,%eax
add    $0x710,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca [100 x i8*]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %9
9: ; preds = %23, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %14, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 %21
store i8* %19, i8** %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %9
26: ; preds = %9
%27 = load i32, i32* @STDIN_FILENO
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%29 = call i64 @read(i32 %27, i8* %28, i32 1000)
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 %34
store i8* %31, i8** %35
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 %37
store i8* null, i8** %38
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%43 = call i32 @execve(i8* %41, i8** %42, i32* null)
ret i32 1
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca [100 x i8*]
%5 = bitcast [100 x i8*]* %4 to i8*
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr i8*, i8** %1, i64 1
%10 = bitcast i8** %9 to i8*
%11 = zext i32 %0 to i64
%12 = shl nuw nsw i64 %11, 3
br label %13
13: ; preds = %8, %2
%14 = phi i32 [ 0, %2 ], [ %0, %8 ]
%15 = load i32, i32* @STDIN_FILENO
%16 = call i64 @read(i32 %15, i8* %6, i32 1000)
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = add nsw i32 %14, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8*], [100 x i8*]* %4, i64 0, i64 %19
store i8* %6, i8** %20
%21 = zext i32 %14 to i64
%22 = getelementptr inbounds [100 x i8*], [100 x i8*]* %4, i64 0, i64 %21
store i8* null, i8** %22
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [100 x i8*], [100 x i8*]* %4, i64 0, i64 0
%26 = call i32 @execve(i8* %24, i8** %25, i32* null)
ret i32 1
}