#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*/ execv(char *, char **);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ setregid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  setreuid(0, 0);
  setregid(0, 0);
  char *bash[] = {"/bin/bash", NULL};
  if (argc > 1)
    execvp(argv[1], argv + 1);
  else
    execv(bash[0], bash);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1030 <setreuid@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1040 <setregid@plt>
mov    0x2ca1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c9e(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1050 <execvp@plt>
jmp    11af <main+0x6f>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <execv@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
xor    %esi,%esi
call   1030 <setreuid@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <setregid@plt>
movaps 0x2cac(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%ebp
jl     117f <main+0x3f>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1050 <execvp@plt>
jmp    118e <main+0x4e>
lea    0xe7a(%rip),%rdi
mov    %rsp,%rsi
call   1060 <execv@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/bin/bash\00"
@__const.main.bash = [2 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @setreuid(i32 0, i32 0)
%8 = call i32 @setregid(i32 0, i32 0)
%9 = bitcast [2 x i8*]* %6 to i8*
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = call i32 @execvp(i8* %15, i8** %17)
br label %24
19: ; preds = %2
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%23 = call i32 @execv(i8* %21, i8** %22)
br label %24
24: ; preds = %19, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/bash\00"
@__const.main.bash = [2 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* null]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i8*]
%4 = tail call i32 @setreuid(i32 0, i32 0)
%5 = tail call i32 @setregid(i32 0, i32 0)
%6 = bitcast [2 x i8*]* %3 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @execvp(i8* %10, i8** %9)
br label %15
12: ; preds = %2
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%14 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %13)
br label %15
15: ; preds = %12, %8
ret i32 0
}