#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 */
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getuid();
int iopl(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int status;
  status = iopl(3);
  if (status < 0) {
    perror("iopl()");
    exit(2);
  }
  if (setuid(getuid()) < 0) {
    perror("setuid()");
    exit(2);
  }
  if (argc < 2) {
    fprintf(stderr, "Usage: %s program [arguments]\n", argv[0]);
    exit(1);
  }
  if (execvp(argv[1], &argv[1]) < 0) {
    perror(argv[1]);
    exit(2);
  }
  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)
mov    $0x3,%edi
call   1040 <iopl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b3 <main+0x43>
lea    0xe5c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%edi
call   1090 <setuid@plt>
cmp    $0x0,%rax
jge    11e1 <main+0x71>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1211 <main+0xa1>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1070 <execvp@plt>
cmp    $0x0,%rax
jge    1247 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x3,%edi
call   1040 <iopl@plt>
test   %eax,%eax
js     11bc <main+0x4c>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%edi
call   1090 <setuid@plt>
test   %rax,%rax
js     11c5 <main+0x55>
cmp    $0x1,%ebp
jle    11ce <main+0x5e>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1070 <execvp@plt>
test   %rax,%rax
js     11f0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
jmp    11f3 <main+0x83>
lea    0xe3b(%rip),%rdi
jmp    11f3 <main+0x83>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    (%rbx),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"iopl()\00"
@.str.1 = [9 x i8] c"setuid()\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Usage: %s program [arguments]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @iopl(i32 3)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 2)
unreachable
13: ; preds = %2
%14 = call i32 (...) @getuid()
%15 = call i64 @setuid(i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 2)
unreachable
20: ; preds = %13
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = call i64 @execvp(i8* %33, i8** %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %30
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @perror(i8* %41)
%43 = call i32 @exit(i32 2)
unreachable
44: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"iopl()\00"
@.str.1 = [9 x i8] c"setuid()\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Usage: %s program [arguments]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @iopl(i32 3)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %2
%9 = tail call i32 (...) @getuid()
%10 = tail call i64 @setuid(i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 2)
unreachable
15: ; preds = %8
%16 = icmp slt i32 %0, 2
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @execvp(i8* %24, i8** %23)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i8*, i8** %23
%29 = tail call i32 @perror(i8* %28)
%30 = tail call i32 @exit(i32 2)
unreachable
31: ; preds = %22
ret i32 0
}