#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*/ execve(char *, char **, char **);
void execShScript(int argc, char *argv[], char *envp[]) {
  char *shArgv[argc + 1];
  int j;
  shArgv[0] = "/bin/sh";
  for (j = 0; j <= argc; j++)
    shArgv[j + 1] = argv[j];
  execve("/bin/sh", shArgv, envp);
}


x86 assembly (clang, -O0):
<execShScript>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
lea    0xeaa(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1197 <execShScript+0x87>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1160 <execShScript+0x50>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe5a(%rip),%rdi
call   1030 <execve@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execShScript>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdx,%r14
lea    0x1(%rdi),%eax
mov    %rsp,%rcx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
neg    %rax
lea    0xeb1(%rip),%rdx
mov    %rdx,(%rcx,%rax,1)
test   %edi,%edi
js     116d <execShScript+0x4d>
lea    0x8(%rbx),%rax
mov    %edi,%ecx
lea    0x8(,%rcx,8),%rdx
mov    %rax,%rdi
call   1040 <memcpy@plt>
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
define void @execShScript(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8*, i64 %12
store i64 %12, i64* %8
%15 = getelementptr inbounds i8*, i8** %14, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %15
store i32 0, i32* %9
br label %16
16: ; preds = %30, %3
%17 = load i32, i32* %9
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %14, i64 %28
store i8* %25, i8** %29
br label %30
30: ; preds = %20
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %16
33: ; preds = %16
%34 = load i8**, i8*** %6
%35 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %14, i8** %34)
%36 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
define void @execShScript(i32 %0, i8** nocapture %1, i8** %2) {
%4 = add nsw i32 %0, 1
%5 = zext i32 %4 to i64
%6 = alloca i8*, i64 %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = icmp slt i32 %0, 0
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = bitcast i8** %1 to i8*
%10 = getelementptr inbounds i8*, i8** %6, i64 1
%11 = bitcast i8** %10 to i8*
%12 = zext i32 %0 to i64
%13 = shl nuw nsw i64 %12, 3
%14 = add nuw nsw i64 %13, 8
br label %15
15: ; preds = %8, %3
%16 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6, i8** %2)
ret void
}