#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ ioperm(int, int, int);
int /*<<< orphan*/ outb(unsigned char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main() {
  unsigned char c;
  int a;
  if (ioperm(0x378, 1, 1)) {
    printf("Couldn't get the port.\n");
    perror("ioperm problem:");
  }
  if (ioperm(0x378 + 1, 1, 1)) {
    printf("Couldn't get the port.\n");
    perror("ioperm problem:");
  }
  if (ioperm(0x378 + 2, 1, 1)) {
    printf("Couldn't get the port.\n");
    perror("ioperm problem:");
  }
  printf("\n");
  while (1 > 0) {
    for (c = 0x00; c <= 0x0f; c++) {
      outb(c ^ 0x0b, 0x378 + 2);
      for (a = 0; a < 256; a++) {
        outb((unsigned char)a, 0x378);
        fputs("\r", stdout);
        printf("Present values are c = %X    a = %2X        Total: %4d         "
               "                 ",
               c, a, 256 * (int)c + (int)a);
        fflush(stdout);
        usleep(100000);
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x378,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     11b4 <main+0x44>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
call   1080 <perror@plt>
mov    $0x379,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     11e9 <main+0x79>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe34(%rip),%rdi
call   1080 <perror@plt>
mov    $0x37a,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     121e <main+0xae>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0xf,%eax
jg     12e1 <main+0x171>
movzbl -0x5(%rbp),%eax
xor    $0xb,%eax
mov    $0x37a,%esi
movzbl %al,%edi
call   1050 <outb@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    12cf <main+0x15f>
mov    -0xc(%rbp),%eax
mov    $0x378,%esi
movzbl %al,%edi
call   1050 <outb@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xda3(%rip),%rdi
call   1040 <fputs@plt>
movzbl -0x5(%rbp),%esi
mov    -0xc(%rbp),%edx
movzbl -0x5(%rbp),%ecx
shl    $0x8,%ecx
add    -0xc(%rbp),%ecx
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1258 <main+0xe8>
jmp    12d4 <main+0x164>
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
jmp    1230 <main+0xc0>
jmp    122c <main+0xbc>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x378,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    12ad <main+0x11d>
mov    $0x379,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    12ca <main+0x13a>
mov    $0x37a,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    12e7 <main+0x157>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2ddd(%rip),%r12
lea    0xe06(%rip),%r14
lea    0xe01(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %r13d,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%eax
xor    $0xb,%al
movzbl %al,%edi
mov    $0x37a,%esi
call   1070 <outb@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl %bl,%edi
mov    $0x378,%esi
call   1070 <outb@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1060 <fputs@plt>
lea    (%rbx,%r13,1),%ecx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
call   1090 <fflush@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
add    $0x1,%ebx
cmp    $0x100,%ebx
jne    1250 <main+0xc0>
add    $0x1,%ebp
add    $0x100,%r13d
cmp    $0x10,%ebp
jne    1230 <main+0xa0>
jmp    1220 <main+0x90>
lea    0xdaf(%rip),%rdi
call   1040 <puts@plt>
lea    0xd40(%rip),%rdi
call   10a0 <perror@plt>
jmp    11b8 <main+0x28>
lea    0xd92(%rip),%rdi
call   1040 <puts@plt>
lea    0xd23(%rip),%rdi
call   10a0 <perror@plt>
jmp    11d5 <main+0x45>
lea    0xd75(%rip),%rdi
call   1040 <puts@plt>
lea    0xd06(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f2 <main+0x62>

LLVM IR (-O0):
@.str = [24 x i8] c"Couldn't get the port.\0A\00"
@.str.1 = [16 x i8] c"ioperm problem:\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c"\0D\00"
@stdout = global i32 0
@.str.4 = [81 x i8] c"Present values are c = %X a = %2X Total: %4d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @ioperm(i32 888, i32 1, i32 1)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %6, %0
%10 = call i64 @ioperm(i32 889, i32 1, i32 1)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %9
%16 = call i64 @ioperm(i32 890, i32 1, i32 1)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %62
store i8 0, i8* %2
br label %24
24: ; preds = %59, %23
%25 = load i8, i8* %2
%26 = zext i8 %25 to i32
%27 = icmp sle i32 %26, 15
br i1 %27, label %28, label %62
28: ; preds = %24
%29 = load i8, i8* %2
%30 = zext i8 %29 to i32
%31 = xor i32 %30, 11
%32 = trunc i32 %31 to i8
%33 = call i32 @outb(i8 zeroext %32, i32 890)
store i32 0, i32* %3
br label %34
34: ; preds = %55, %28
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 256
br i1 %36, label %37, label %58
37: ; preds = %34
%38 = load i32, i32* %3
%39 = trunc i32 %38 to i8
%40 = call i32 @outb(i8 zeroext %39, i32 888)
%41 = load i32, i32* @stdout
%42 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i8, i8* %2
%44 = zext i8 %43 to i32
%45 = load i32, i32* %3
%46 = load i8, i8* %2
%47 = zext i8 %46 to i32
%48 = mul nsw i32 256, %47
%49 = load i32, i32* %3
%50 = add nsw i32 %48, %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %45, i32 %50)
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
%54 = call i32 @usleep(i32 100000)
br label %55
55: ; preds = %37
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %34
58: ; preds = %34
br label %59
59: ; preds = %58
%60 = load i8, i8* %2
%61 = add i8 %60, 1
store i8 %61, i8* %2
br label %24
62: ; preds = %24
br label %23
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"ioperm problem:\00"
@.str.3 = [2 x i8] c"\0D\00"
@stdout = global i32 0
@.str.4 = [81 x i8] c"Present values are c = %X a = %2X Total: %4d \00"
@str.6 = [23 x i8] c"Couldn't get the port.\00"
define i32 @main() {
%1 = tail call i64 @ioperm(i32 888, i32 1, i32 1)
%2 = icmp eq i64 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %3, %0
%7 = tail call i64 @ioperm(i32 889, i32 1, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %6
%13 = tail call i64 @ioperm(i32 890, i32 1, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%17 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %12
%19 = tail call i32 @putchar(i32 10)
br label %20
20: ; preds = %40, %18
br label %21
21: ; preds = %20, %40
%22 = phi i32 [ 0, %20 ], [ %41, %40 ]
%23 = trunc i32 %22 to i8
%24 = xor i8 %23, 11
%25 = tail call i32 @outb(i8 zeroext %24, i32 890)
%26 = shl nuw nsw i32 %22, 8
br label %27
27: ; preds = %21, %27
%28 = phi i32 [ 0, %21 ], [ %38, %27 ]
%29 = trunc i32 %28 to i8
%30 = tail call i32 @outb(i8 zeroext %29, i32 888)
%31 = load i32, i32* @stdout
%32 = tail call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i32 %28, %26
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %28, i32 %33)
%35 = load i32, i32* @stdout
%36 = tail call i32 @fflush(i32 %35)
%37 = tail call i32 @usleep(i32 100000)
%38 = add nuw nsw i32 %28, 1
%39 = icmp eq i32 %38, 256
br i1 %39, label %40, label %27
40: ; preds = %27
%41 = add nuw nsw i32 %22, 1
%42 = icmp eq i32 %41, 16
br i1 %42, label %20, label %21
}