#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 */
char **calloc(int, int);
int execv(char *, char **);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
char *strdup(char *);
int main(int argc, char **argv) {
  int i;
  char **newArgv;
  newArgv = calloc(sizeof(char *), argc + 1);
  newArgv[0] = strdup("/usr/bin/phong.py");
  newArgv[1] = strdup("sudo");
  for (i = 1; i < argc; i++) {
    newArgv[i + 1] = strdup(argv[i]);
  }
  newArgv[argc + 1] = NULL;
  setreuid(geteuid(), getuid());
  return execv(newArgv[0], newArgv);
}


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    -0x8(%rbp),%esi
add    $0x1,%esi
mov    $0x8,%edi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe6f(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
lea    0xe6b(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fd <main+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <main+0x5e>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1060 <setreuid@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <execv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x1(%rbp),%r15d
mov    $0x8,%edi
mov    %r15d,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
lea    0xe78(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,(%r12)
lea    0xe7a(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,0x8(%r12)
cmp    $0x2,%ebp
jl     11c8 <main+0x68>
mov    %ebp,%ebp
add    $0xffffffffffffffff,%rbp
xor    %ebx,%ebx
nop
mov    0x8(%r14,%rbx,8),%rdi
call   1070 <strdup@plt>
mov    %rax,0x10(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x50>
movslq %r15d,%rax
movq   $0x0,(%r12,%rax,8)
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <setreuid@plt>
mov    (%r12),%rdi
mov    %r12,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <execv@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/usr/bin/phong.py\00"
@.str.1 = [5 x i8] c"sudo\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = call i8** @calloc(i32 8, i32 %9)
store i8** %10, i8*** %7
%11 = call i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = load i8**, i8*** %7
%13 = getelementptr inbounds i8*, i8** %12, i64 0
store i8* %11, i8** %13
%14 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8**, i8*** %7
%16 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* %14, i8** %16
store i32 1, i32* %6
br label %17
17: ; preds = %33, %2
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @strdup(i8* %26)
%28 = load i8**, i8*** %7
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
store i8* %27, i8** %32
br label %33
33: ; preds = %21
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %17
36: ; preds = %17
%37 = load i8**, i8*** %7
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %37, i64 %40
store i8* null, i8** %41
%42 = call i32 (...) @geteuid()
%43 = call i32 (...) @getuid()
%44 = call i32 @setreuid(i32 %42, i32 %43)
%45 = load i8**, i8*** %7
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %7
%49 = call i32 @execv(i8* %47, i8** %48)
ret i32 %49
}

LLVM IR (-O2):
@.str = [18 x i8] c"/usr/bin/phong.py\00"
@.str.1 = [5 x i8] c"sudo\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, 1
%4 = tail call i8** @calloc(i32 8, i32 %3)
%5 = tail call dereferenceable_or_null(18) i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = tail call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = getelementptr inbounds i8*, i8** %4, i64 1
store i8* %6, i8** %7
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 1, %9 ], [ %16, %11 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i8* @strdup(i8* %14)
%16 = add nuw nsw i64 %12, 1
%17 = getelementptr inbounds i8*, i8** %4, i64 %16
store i8* %15, i8** %17
%18 = icmp eq i64 %16, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %2
%20 = sext i32 %3 to i64
%21 = getelementptr inbounds i8*, i8** %4, i64 %20
store i8* null, i8** %21
%22 = tail call i32 (...) @geteuid()
%23 = tail call i32 (...) @getuid()
%24 = tail call i32 @setreuid(i32 %22, i32 %23)
%25 = load i8*, i8** %4
%26 = tail call i32 @execv(i8* %25, i8** %4)
ret i32 %26
}