#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*/ ENOMEM;
char **calloc(int, int);
int /*<<< orphan*/ errno;
int execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  char **new_argv;
  char *exec_path;
  int a;
  int rv;
  new_argv = calloc(argc, sizeof(char *));
  if (new_argv == 0) {
    exit(ENOMEM);
  }
  exec_path = argv[1];
  for (a = 2; a < argc - 1; a++) {
    new_argv[a - 2] = argv[a];
  }
  rv = execve(exec_path, new_argv, envp);
  if (rv == -1) {
    exit(errno);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1174 <main+0x44>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c3 <main+0x93>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1187 <main+0x57>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <execve@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    11ef <main+0xbf>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11a4 <main+0x64>
mov    %rax,%r12
mov    0x8(%r15),%r13
cmp    $0x4,%ebx
jl     1185 <main+0x45>
add    $0x10,%r15
add    $0xfffffffd,%ebx
shl    $0x3,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
je     11b2 <main+0x72>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%12 = load i32, i32* %5
%13 = call i8** @calloc(i32 %12, i32 8)
store i8** %13, i8*** %8
%14 = load i8**, i8*** %8
%15 = icmp eq i8** %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* @ENOMEM
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %9
store i32 2, i32* %10
br label %23
23: ; preds = %39, %19
%24 = load i32, i32* %10
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %42
28: ; preds = %23
%29 = load i8**, i8*** %6
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %8
%35 = load i32, i32* %10
%36 = sub nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
store i8* %33, i8** %38
br label %39
39: ; preds = %28
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %23
42: ; preds = %23
%43 = load i8*, i8** %9
%44 = load i8**, i8*** %8
%45 = load i8**, i8*** %7
%46 = call i32 @execve(i8* %43, i8** %44, i8** %45)
store i32 %46, i32* %11
%47 = load i32, i32* %11
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = load i32, i32* @errno
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
ret i32 0
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1, i8** %2) {
%4 = tail call i8** @calloc(i32 %0, i32 8)
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8** %4, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @ENOMEM
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = icmp sgt i32 %0, 3
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = getelementptr i8*, i8** %1, i64 2
%16 = bitcast i8** %15 to i8*
%17 = add nsw i32 %0, -3
%18 = zext i32 %17 to i64
%19 = shl nuw nsw i64 %18, 3
br label %20
20: ; preds = %14, %10
%21 = tail call i32 @execve(i8* %12, i8** %4, i8** %2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %20
ret i32 0
}