#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 EXIT_SUCCESS;
unsigned long atoi(char *);
scalar_t__ do_ioperm(unsigned long, unsigned long);
scalar_t__ do_read_devport(unsigned long, unsigned long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  unsigned long addr = 0x378, nports = 2;
  if (argc > 1)
    addr = strtoul(argv[1], NULL, 0);
  if (argc > 2)
    nports = atoi(argv[2]);
  if (do_read_devport(addr, nports))
    fprintf(stderr, "reading /dev/port method failed");
  if (do_ioperm(addr, nports))
    fprintf(stderr, "ioperm method failed");
  return EXIT_SUCCESS;
}


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   $0x378,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1197 <main+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11b2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <do_read_devport@plt>
cmp    $0x0,%rax
je     11de <main+0x8e>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <do_ioperm@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2,%r14d
mov    $0x378,%ebx
cmp    $0x2,%edi
jl     118d <main+0x3d>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbx
cmp    $0x2,%ebp
je     118d <main+0x3d>
mov    0x10(%r15),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <do_read_devport@plt>
test   %rax,%rax
je     11b2 <main+0x62>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <do_ioperm@plt>
test   %rax,%rax
je     11d7 <main+0x87>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"reading /dev/port method failed\00"
@.str.1 = [21 x i8] c"ioperm method failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 888, i64* %6
store i64 2, i64* %7
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strtoul(i8* %13, i32* null, i32 0)
store i64 %14, i64* %6
br label %15
15: ; preds = %10, %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @atoi(i8* %21)
store i64 %22, i64* %7
br label %23
23: ; preds = %18, %15
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = call i64 @do_read_devport(i64 %24, i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %28, %23
%32 = load i64, i64* %6
%33 = load i64, i64* %7
%34 = call i64 @do_ioperm(i64 %32, i64 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %36, %31
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"reading /dev/port method failed\00"
@.str.1 = [21 x i8] c"ioperm method failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strtoul(i8* nocapture %6, i32* null, i32 0)
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
br label %13
13: ; preds = %2, %9, %4
%14 = phi i64 [ %7, %9 ], [ %7, %4 ], [ 888, %2 ]
%15 = phi i64 [ %12, %9 ], [ 2, %4 ], [ 2, %2 ]
%16 = tail call i64 @do_read_devport(i64 %14, i64 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %13
%22 = tail call i64 @do_ioperm(i64 %14, i64 %15)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}