#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 **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ setgid(int /*<<< orphan*/);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2)
    return 0;
  setuid(0);
  setgid(0);
  char *script_args[argc + 2];
  script_args[0] = "ruby";
  fprintf(stderr, "Helper script_args[0] = %s\n", script_args[0]);
  script_args[1] = "--";
  fprintf(stderr, "Helper script_args[1] = %s\n", script_args[1]);
  int i;
  for (i = 1; i < argc; i++) {
    script_args[i + 1] = argv[i];
    fprintf(stderr, "Helper script_args[%i] = %s\n", i + 1, script_args[i + 1]);
  }
  script_args[argc + 1] = NULL;
  fprintf(stderr, "Helper script_args[%i] = NULL\n", argc + 1);
  execvp("ruby", script_args);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    12b0 <main+0x170>
xor    %edi,%edi
mov    %edi,-0x34(%rbp)
call   1060 <setuid@plt>
mov    -0x34(%rbp),%edi
call   1040 <setgid@plt>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x20(%rbp)
lea    0xe4f(%rip),%rcx
mov    %rcx,(%rax)
mov    0x2e25(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x30(%rbp),%rax
lea    0xe48(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    0x2dfc(%rip),%rcx
mov    (%rcx),%edi
mov    0x8(%rax),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1260 <main+0x120>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    0x2db1(%rip),%rcx
mov    (%rcx),%edi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ff <main+0xbf>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
add    $0x1,%edx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x30(%rbp),%rsi
lea    0xd63(%rip),%rdi
call   1050 <execvp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jl     126a <main+0x12a>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
xor    %edi,%edi
call   1060 <setuid@plt>
xor    %edi,%edi
call   1040 <setgid@plt>
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r14
mov    %ebx,-0x2c(%rbp)
mov    %ebx,%r13d
lea    0x1f(,%r13,8),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r14,%r12
sub    %rbx,%r12
mov    %r12,%rsp
lea    0xe6a(%rip),%rdx
mov    %rdx,(%r12)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
neg    %rbx
lea    0xe66(%rip),%rdx
mov    %rdx,0x8(%r14,%rbx,1)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r14d
sub    %r13,%r14
mov    $0x2,%ebx
lea    0xe54(%rip),%r13
nopl   0x0(%rax)
mov    -0x8(%r15,%rbx,8),%rcx
mov    %rcx,(%r12,%rbx,8)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
jne    11f0 <main+0xb0>
mov    -0x2c(%rbp),%edx
movslq %edx,%rax
add    $0x1,%edx
movq   $0x0,0x8(%r12,%rax,8)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xdb0(%rip),%rdi
mov    %r12,%rsi
call   1050 <execvp@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ruby\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Helper script_args[0] = %s\0A\00"
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [28 x i8] c"Helper script_args[1] = %s\0A\00"
@.str.4 = [29 x i8] c"Helper script_args[%i] = %s\0A\00"
@.str.5 = [31 x i8] c"Helper script_args[%i] = NULL\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %67
12: ; preds = %2
%13 = call i32 @setuid(i32 0)
%14 = call i32 @setgid(i32 0)
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8*, i64 %17
store i64 %17, i64* %7
%20 = getelementptr inbounds i8*, i8** %19, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %20
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds i8*, i8** %19, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %25
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds i8*, i8** %19, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 1, i32* %8
br label %30
30: ; preds = %53, %12
%31 = load i32, i32* %8
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %56
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %19, i64 %42
store i8* %39, i8** %43
%44 = load i32, i32* @stderr
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %19, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %46, i8* %51)
br label %53
53: ; preds = %34
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %30
56: ; preds = %30
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %19, i64 %59
store i8* null, i8** %60
%61 = load i32, i32* @stderr
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %19)
store i32 0, i32* %3
%66 = load i8*, i8** %6
br label %67
67: ; preds = %56, %11
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [5 x i8] c"ruby\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Helper script_args[0] = %s\0A\00"
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [28 x i8] c"Helper script_args[1] = %s\0A\00"
@.str.4 = [29 x i8] c"Helper script_args[%i] = %s\0A\00"
@.str.5 = [31 x i8] c"Helper script_args[%i] = NULL\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %34, label %4
4: ; preds = %2
%5 = tail call i32 @setuid(i32 0)
%6 = tail call i32 @setgid(i32 0)
%7 = add nuw nsw i32 %0, 2
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8*, i64 %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %13
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %4, %17
%18 = phi i64 [ 1, %4 ], [ %21, %17 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = add nuw nsw i64 %18, 1
%22 = getelementptr inbounds i8*, i8** %10, i64 %21
store i8* %20, i8** %22
%23 = load i32, i32* @stderr
%24 = trunc i64 %21 to i32
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %24, i8* %20)
%26 = icmp eq i64 %21, %16
br i1 %26, label %27, label %17
27: ; preds = %17
%28 = add nsw i32 %0, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %10, i64 %29
store i8* null, i8** %30
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%33 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %10)
br label %34
34: ; preds = %2, %27
ret i32 0
}