#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*/ clearenv();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  if (setuid(0))
    printf("%s\n", strerror(errno));
  if (setgid(0))
    printf("%s\n", strerror(errno));
  clearenv();
  char cmd[1024] = {0};
  int i;
  for (i = 1; i < argc; i++) {
    sprintf(cmd, "%s%s ", cmd, argv[i]);
  }
  system(cmd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1090 <setuid@plt>
cmp    $0x0,%rax
je     11c7 <main+0x47>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <setgid@plt>
cmp    $0x0,%rax
je     11f5 <main+0x75>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <clearenv@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x1,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1265 <main+0xe5>
lea    -0x410(%rbp),%rdi
lea    -0x410(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x414(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdb8(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1219 <main+0x99>
lea    -0x410(%rbp),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %edi,%edi
call   1090 <setuid@plt>
test   %rax,%rax
je     11bd <main+0x3d>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe4b(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <setgid@plt>
test   %rax,%rax
je     11e6 <main+0x66>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe22(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <clearenv@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
cmp    $0x2,%ebp
jl     123b <main+0xbb>
mov    %ebp,%r12d
mov    $0x1,%ebp
lea    0xdf4(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbp,8),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1220 <main+0xa0>
mov    %rsp,%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%s%s \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @setuid(i32 0)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %2
%15 = call i64 @setgid(i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %17, %14
%22 = call i32 (...) @clearenv()
%23 = bitcast [1024 x i8]* %6 to i8*
store i32 1, i32* %7
br label %24
24: ; preds = %37, %21
%25 = load i32, i32* %7
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %24
40: ; preds = %24
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i32 @system(i8* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"%s%s \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = tail call i64 @setuid(i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6, %2
%11 = tail call i64 @setgid(i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %10
%18 = tail call i32 (...) @clearenv()
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = icmp sgt i32 %0, 1
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = zext i32 %0 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 1, %21 ], [ %28, %23 ]
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %26)
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, %22
br i1 %29, label %30, label %23
30: ; preds = %23, %17
%31 = call i32 @system(i8* %19)
ret i32 0
}