#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;
  int i;
  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)
cmpl   $0x1,-0x8(%rbp)
jg     117a <main+0x2a>
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     11a7 <main+0x57>
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1040 <setresgid@plt>
cmp    $0x0,%rax
je     11c8 <main+0x78>
lea    0xe47(%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**
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
store i8** %14, i8*** %6
%15 = call i64 @setresuid(i32 0, i32 0, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = call i64 @setresgid(i32 0, i32 0, i32 0)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %6
%29 = call i32 @execvp(i8* %27, i8** %28)
%30 = call i32 @exit(i32 %29)
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
}