#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 */
typedef int /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setresgid(int /*<<< orphan*/, int /*<<< orphan*/,
                     int /*<<< orphan*/);
scalar_t__ setresuid(int /*<<< orphan*/, int /*<<< orphan*/,
                     int /*<<< orphan*/);
int main(int argc, char **argv) {
  char **newargv = NULL;
  if (argc <= 1) {
    exit(1);
  }
  newargv = argv + 1;
  if (setresuid(((uid_t)0), ((uid_t)0), ((uid_t)0))) {
    perror("setresuid");
  }
  if (setresgid(((gid_t)0), ((gid_t)0), ((gid_t)0))) {
    perror("setresgid");
  }
  exit(execvp(newargv[0], newargv));
}


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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1182 <main+0x32>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <setresuid@plt>
cmp    $0x0,%rax
je     11af <main+0x5f>
lea    0xe56(%rip),%rdi
call   1050 <perror@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1040 <setresgid@plt>
cmp    $0x0,%rax
je     11d0 <main+0x80>
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <execvp@plt>
mov    %eax,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jg     1160 <main+0x10>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %rsi,%rbx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <setresuid@plt>
test   %rax,%rax
je     117f <main+0x2f>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
add    $0x8,%rbx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <setresgid@plt>
test   %rax,%rax
je     119f <main+0x4f>
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execvp@plt>
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"setresuid\00"
@.str.1 = [10 x i8] c"setresgid\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** null, i8*** %6
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8** %13, i8*** %6
%14 = call i64 @setresuid(i32 0, i32 0, i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = call i64 @setresgid(i32 0, i32 0, i32 0)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i8**, i8*** %6
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %6
%28 = call i32 @execvp(i8* %26, i8** %27)
%29 = call i32 @exit(i32 %28)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"setresuid\00"
@.str.1 = [10 x i8] c"setresgid\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = tail call i64 @setresuid(i32 0, i32 0, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = tail call i64 @setresgid(i32 0, i32 0, i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i8*, i8** %7
%19 = tail call i32 @execvp(i8* %18, i8** %7)
%20 = tail call i32 @exit(i32 %19)
unreachable
}