#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 atoi(char *);
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(int argc, char *argv[]) {
  unsigned char a, c;
  int value;
  if (argc > 1)
    printf("%s\n", argv[1]);
  if (argc > 1 && atoi(argv[1]) == 1)
    value = 1;
  else
    value = 0;
  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");
  if (value == 1)
    c = 0x08;
  else
    c = 0x00;
  a = 0x00;
  outb(c ^ 0x0b, 0x378 + 2);
  outb(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);
  printf("\n");
  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)
cmpl   $0x1,-0x8(%rbp)
jle    11b6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11e2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
cmp    $0x1,%eax
jne    11e2 <main+0x62>
movl   $0x1,-0x18(%rbp)
jmp    11e9 <main+0x69>
movl   $0x0,-0x18(%rbp)
mov    $0x378,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     121e <main+0x9e>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe03(%rip),%rdi
call   1080 <perror@plt>
mov    $0x379,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     1253 <main+0xd3>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdce(%rip),%rdi
call   1080 <perror@plt>
mov    $0x37a,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioperm@plt>
cmp    $0x0,%rax
je     1288 <main+0x108>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd99(%rip),%rdi
call   1080 <perror@plt>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    12a9 <main+0x129>
movb   $0x8,-0x12(%rbp)
jmp    12ad <main+0x12d>
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
movzbl -0x12(%rbp),%eax
xor    $0xb,%eax
mov    $0x37a,%esi
movzbl %al,%edi
call   1050 <outb@plt>
mov    $0x378,%esi
movzbl -0x11(%rbp),%edi
call   1050 <outb@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
lea    0xd49(%rip),%rdi
call   1040 <fputs@plt>
movzbl -0x12(%rbp),%esi
movzbl -0x11(%rbp),%edx
movzbl -0x12(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x11(%rbp),%eax
add    %eax,%ecx
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x186a0,%edi
call   10a0 <usleep@plt>
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11c7 <main+0x27>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    $0x8,%ebp
cmp    $0x1,%eax
je     11c9 <main+0x29>
xor    %ebp,%ebp
mov    $0x378,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    1297 <main+0xf7>
mov    $0x379,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    12b4 <main+0x114>
mov    $0x37a,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
jne    12d1 <main+0x131>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
xor    $0xb,%al
movzbl %al,%edi
mov    $0x37a,%esi
call   1070 <outb@plt>
xor    %edi,%edi
mov    $0x378,%esi
call   1070 <outb@plt>
mov    0x2d92(%rip),%rbx
mov    (%rbx),%esi
lea    0xdb9(%rip),%rdi
call   1060 <fputs@plt>
mov    %ebp,%ecx
shl    $0x8,%ecx
lea    0xdaa(%rip),%rdi
mov    %ebp,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edi
call   1090 <fflush@plt>
mov    $0x186a0,%edi
call   10c0 <usleep@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
lea    0xd56(%rip),%rdi
call   10a0 <perror@plt>
jmp    11e6 <main+0x46>
lea    0xda8(%rip),%rdi
call   1040 <puts@plt>
lea    0xd39(%rip),%rdi
call   10a0 <perror@plt>
jmp    1203 <main+0x63>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xd1c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1220 <main+0x80>

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

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