#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 **);
char **malloc(int);
int child(int argc, char **argv) {
  char **newargs = malloc(sizeof(char *) * argc);
  int i;
  for (i = 0; i < argc - 1; i++) {
    newargs[i] = argv[i + 1];
  }
  newargs[argc - 1] = NULL;
  execvp(argv[1], newargs);
  return 0;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1185 <child+0x65>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%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    1149 <child+0x29>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <execvp@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    -0x1(%rbx),%ebp
cmp    $0x2,%ebx
jl     1165 <child+0x35>
lea    0x8(%r14),%rsi
mov    %ebp,%edx
shl    $0x3,%rdx
mov    %r15,%rdi
call   1030 <memcpy@plt>
movslq %ebp,%rax
movq   $0x0,(%r15,%rax,8)
mov    0x8(%r14),%rdi
mov    %r15,%rsi
call   1050 <execvp@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @child(i32 %0, i8** nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call i8** @malloc(i32 %3)
%5 = add i32 %0, -1
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = bitcast i8** %4 to i8*
%9 = getelementptr i8*, i8** %1, i64 1
%10 = bitcast i8** %9 to i8*
%11 = zext i32 %5 to i64
%12 = shl nuw nsw i64 %11, 3
br label %13
13: ; preds = %7, %2
%14 = sext i32 %5 to i64
%15 = getelementptr inbounds i8*, i8** %4, i64 %14
store i8* null, i8** %15
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @execvp(i8* %17, i8** %4)
ret i32 0
}