#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*/ EXIT_FAILURE;
int /*<<< orphan*/ check_int(unsigned long, int, int, int, char *, char *,
                             char *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int iopl(int);
int /*<<< orphan*/ outb(unsigned long, unsigned long);
int /*<<< orphan*/ perror(char *);
unsigned long strtol(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  unsigned long val;
  unsigned long port = 0x80;
  char *endptr;
  int err;
  if (argc != 2 && argc != 3) {
    usage(argv[0], NULL);
    exit(EXIT_FAILURE);
  }
  val = strtol(argv[1], &endptr, 0);
  err = errno;
  check_int(val, 0x00, 0xff, err, argv[1], endptr, argv[0]);
  if (argc > 2) {
    port = strtol(argv[2], &endptr, 0);
    err = errno;
    check_int(port, 0x0000, 0xffff, err, argv[2], endptr, argv[0]);
  }
  err = iopl(3);
  if (err == -1) {
    perror("Not root");
    exit(EXIT_FAILURE);
  }
  outb(val, port);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x80,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c0 <main+0x50>
cmpl   $0x3,-0x8(%rbp)
je     11c0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <usage@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x28(%rbp),%r9
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
xor    %esi,%esi
mov    $0xff,%edx
mov    %rax,(%rsp)
call   1030 <check_int@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1264 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x28(%rbp),%r9
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
xor    %esi,%esi
mov    $0xffff,%edx
mov    %rax,(%rsp)
call   1030 <check_int@plt>
mov    $0x3,%edi
call   1040 <iopl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1295 <main+0x125>
lea    0xd7e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <outb@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1236 <main+0xc6>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
mov    0x2e37(%rip),%r12
mov    (%r12),%ecx
mov    (%rbx),%rax
mov    0x8(%rbx),%r8
mov    0x8(%rsp),%r9
mov    %rax,(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <check_int@plt>
mov    $0x80,%r15d
cmp    $0x3,%ebp
jb     120d <main+0x9d>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%r15
mov    (%r12),%ecx
mov    (%rbx),%rax
mov    0x10(%rbx),%r8
mov    0x8(%rsp),%r9
mov    %rax,(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1030 <check_int@plt>
mov    $0x3,%edi
call   1040 <iopl@plt>
cmp    $0xffffffff,%eax
je     1242 <main+0xd2>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <outb@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdi
xor    %esi,%esi
call   1070 <usage@plt>
jmp    124e <main+0xde>
lea    0xdb7(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"Not root\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 128, i64* %7
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18, i32* null)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strtol(i8* %25, i8** %8, i32 0)
store i64 %26, i64* %6
%27 = load i32, i32* @errno
store i32 %27, i32* %9
%28 = load i64, i64* %6
%29 = load i32, i32* %9
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8*, i8** %8
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @check_int(i64 %28, i32 0, i32 255, i32 %29, i8* %32, i8* %33, i8* %36)
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 2
br i1 %39, label %40, label %56
40: ; preds = %22
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i64 @strtol(i8* %43, i8** %8, i32 0)
store i64 %44, i64* %7
%45 = load i32, i32* @errno
store i32 %45, i32* %9
%46 = load i64, i64* %7
%47 = load i32, i32* %9
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = load i8*, i8** %8
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @check_int(i64 %46, i32 0, i32 65535, i32 %47, i8* %50, i8* %51, i8* %54)
br label %56
56: ; preds = %40, %22
%57 = call i32 @iopl(i32 3)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %56
%65 = load i64, i64* %6
%66 = load i64, i64* %7
%67 = call i32 @outb(i64 %65, i64 %66)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"Not root\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @usage(i8* %8, i32* null)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtol(i8* %14, i8** %3, i32 0)
%16 = load i32, i32* @errno
%17 = load i8*, i8** %13
%18 = load i8*, i8** %3
%19 = load i8*, i8** %1
%20 = tail call i32 @check_int(i64 %15, i32 0, i32 255, i32 %16, i8* %17, i8* %18, i8* %19)
%21 = icmp ugt i32 %0, 2
br i1 %21, label %22, label %31
22: ; preds = %12
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @strtol(i8* %24, i8** %3, i32 0)
%26 = load i32, i32* @errno
%27 = load i8*, i8** %23
%28 = load i8*, i8** %3
%29 = load i8*, i8** %1
%30 = tail call i32 @check_int(i64 %25, i32 0, i32 65535, i32 %26, i8* %27, i8* %28, i8* %29)
br label %31
31: ; preds = %22, %12
%32 = phi i64 [ %25, %22 ], [ 128, %12 ]
%33 = tail call i32 @iopl(i32 3)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = tail call i32 @outb(i64 %15, i64 %32)
ret i32 0
}