#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*/ PRIO_PROCESS;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
scalar_t__ ioperm(int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setgid(int /*<<< orphan*/);
int /*<<< orphan*/ setpriority(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "   No target program name : aborting.\n");
    exit(-1);
  }
  setpriority(PRIO_PROCESS, 0, 0);
  if (ioperm(0x378, 3, 1))
    perror("Failed ioperm lp0 on");
  if (ioperm(0x278, 3, 1))
    perror("Failed ioperm lp1 on");
  if (ioperm(0x3BC, 3, 1))
    perror("Failed ioperm lp2 on");
  if (ioperm(0x3F8, 8, 1))
    perror("Failed ioperm ttyS0 on");
  if (ioperm(0x2F8, 8, 1))
    perror("Failed ioperm ttyS1 on");
  if (ioperm(0x3E8, 8, 1))
    perror("Failed ioperm ttyS2 on");
  if (ioperm(0x2E8, 8, 1))
    perror("Failed ioperm ttyS3 on");
  setgid(getgid());
  setuid(getuid());
  execvp(argv[1], &argv[1]);
  perror("   execv failed");
  fprintf(stderr, "   Target program was %s.\n", argv[1]);
  exit(-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e1 <main+0x41>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <setpriority@plt>
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     121d <main+0x7d>
lea    0xe0f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x278,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     1247 <main+0xa7>
lea    0xdfa(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3bc,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     1271 <main+0xd1>
lea    0xde5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3f8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     129b <main+0xfb>
lea    0xdd0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2f8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     12c5 <main+0x125>
lea    0xdbd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3e8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     12ef <main+0x14f>
lea    0xdaa(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2e8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     1319 <main+0x179>
lea    0xd97(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,%edi
call   1080 <setgid@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10a0 <execvp@plt>
lea    0xd71(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jg     11c7 <main+0x27>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    %rsi,%rbx
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <setpriority@plt>
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     1201 <main+0x61>
lea    0xe2b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x278,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     1226 <main+0x86>
lea    0xe1b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3bc,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     124b <main+0xab>
lea    0xe0b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3f8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     1270 <main+0xd0>
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2f8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     1295 <main+0xf5>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3e8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     12ba <main+0x11a>
lea    0xddf(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2e8,%edi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
je     12df <main+0x13f>
lea    0xdd1(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%edi
call   1080 <setgid@plt>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
lea    0x8(%rbx),%rsi
mov    0x8(%rbx),%rdi
call   10a0 <execvp@plt>
lea    0xdb3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c" No target program name : aborting.\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [21 x i8] c"Failed ioperm lp0 on\00"
@.str.2 = [21 x i8] c"Failed ioperm lp1 on\00"
@.str.3 = [21 x i8] c"Failed ioperm lp2 on\00"
@.str.4 = [23 x i8] c"Failed ioperm ttyS0 on\00"
@.str.5 = [23 x i8] c"Failed ioperm ttyS1 on\00"
@.str.6 = [23 x i8] c"Failed ioperm ttyS2 on\00"
@.str.7 = [23 x i8] c"Failed ioperm ttyS3 on\00"
@.str.8 = [16 x i8] c" execv failed\00"
@.str.9 = [27 x i8] c" Target program was %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = load i32, i32* @PRIO_PROCESS
%14 = call i32 @setpriority(i32 %13, i32 0, i32 0)
%15 = call i64 @ioperm(i32 888, i32 3, i32 1)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = call i64 @ioperm(i32 632, i32 3, i32 1)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = call i64 @ioperm(i32 956, i32 3, i32 1)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = call i64 @ioperm(i32 1016, i32 8, i32 1)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = call i64 @ioperm(i32 760, i32 8, i32 1)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = call i64 @ioperm(i32 1000, i32 8, i32 1)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = call i64 @ioperm(i32 744, i32 8, i32 1)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = call i32 (...) @getgid()
%51 = call i32 @setgid(i32 %50)
%52 = call i32 (...) @getuid()
%53 = call i32 @setuid(i32 %52)
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = call i32 @execvp(i8* %56, i8** %58)
%60 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c" No target program name : aborting.\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [21 x i8] c"Failed ioperm lp0 on\00"
@.str.2 = [21 x i8] c"Failed ioperm lp1 on\00"
@.str.3 = [21 x i8] c"Failed ioperm lp2 on\00"
@.str.4 = [23 x i8] c"Failed ioperm ttyS0 on\00"
@.str.5 = [23 x i8] c"Failed ioperm ttyS1 on\00"
@.str.6 = [23 x i8] c"Failed ioperm ttyS2 on\00"
@.str.7 = [23 x i8] c"Failed ioperm ttyS3 on\00"
@.str.8 = [16 x i8] c" execv failed\00"
@.str.9 = [27 x i8] c" Target program was %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @PRIO_PROCESS
%10 = tail call i32 @setpriority(i32 %9, i32 0, i32 0)
%11 = tail call i64 @ioperm(i32 888, i32 3, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = tail call i64 @ioperm(i32 632, i32 3, i32 1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = tail call i64 @ioperm(i32 956, i32 3, i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = tail call i64 @ioperm(i32 1016, i32 8, i32 1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = tail call i64 @ioperm(i32 760, i32 8, i32 1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = tail call i64 @ioperm(i32 1000, i32 8, i32 1)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = tail call i64 @ioperm(i32 744, i32 8, i32 1)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = tail call i32 (...) @getgid()
%47 = tail call i32 @setgid(i32 %46)
%48 = tail call i32 (...) @getuid()
%49 = tail call i32 @setuid(i32 %48)
%50 = getelementptr inbounds i8*, i8** %1, i64 1
%51 = load i8*, i8** %50
%52 = tail call i32 @execvp(i8* %51, i8** %50)
%53 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %50
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %55)
%57 = tail call i32 @exit(i32 -1)
unreachable
}