#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 **);
void exec_child(int argc, char *argv[]) {
  char *new_arg[argc];
  for (int i = 1; i < argc; ++i)
    new_arg[i - 1] = argv[i];
  new_arg[argc - 1] = 0;
  execvp(new_arg[0], new_arg);
}


x86 assembly (clang, -O0):
<exec_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1184 <exec_child+0x74>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114d <exec_child+0x3d>
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
movq   $0x0,(%rsi,%rax,8)
mov    (%rsi),%rdi
call   1030 <execvp@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_child>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    %edi,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jle    1160 <exec_child+0x40>
add    $0x8,%rsi
add    $0xffffffff,%r14d
lea    0x0(,%r14,8),%rdx
mov    %rbx,%rdi
call   1030 <memcpy@plt>
jmp    1164 <exec_child+0x44>
add    $0xffffffff,%r14d
movslq %r14d,%rax
movq   $0x0,(%rbx,%rax,8)
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1040 <execvp@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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