#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*/ IOPi_init(int, int);
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ invert_port(int, int, int);
int /*<<< orphan*/ mirror_interrupts(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read_interrupt_capture(int, int);
scalar_t__ read_interrupt_status(int, int);
int /*<<< orphan*/ set_interrupt_defaults(int, int, int);
int /*<<< orphan*/ set_interrupt_on_port(int, int, int);
int /*<<< orphan*/ set_interrupt_polarity(int, int);
int /*<<< orphan*/ set_interrupt_type(int, int, int);
int /*<<< orphan*/ set_port_direction(int, int, int);
int /*<<< orphan*/ set_port_pullups(int, int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  IOPi_init(0x20, 1);
  set_port_pullups(0x20, 0, 0xFF);
  set_port_pullups(0x20, 1, 0xFF);
  set_port_direction(0x20, 0, 0xFF);
  set_port_direction(0x20, 1, 0xFF);
  invert_port(0x20, 0, 0xFF);
  invert_port(0x20, 1, 0xFF);
  set_interrupt_polarity(0x20, 1);
  mirror_interrupts(0x20, 0);
  set_interrupt_defaults(0x20, 0, 0x00);
  set_interrupt_defaults(0x20, 1, 0x00);
  set_interrupt_type(0x20, 0, 0xFF);
  set_interrupt_type(0x20, 1, 0xFF);
  set_interrupt_on_port(0x20, 0, 0xFF);
  set_interrupt_on_port(0x20, 1, 0xFF);
  while (1) {
    if (read_interrupt_status(0x20, 0) != 0) {
      printf("Port 0: %x \n", read_interrupt_capture(0x20, 0));
    }
    if (read_interrupt_status(0x20, 1) != 0) {
      printf("Port 1: %x \n", read_interrupt_capture(0x20, 1));
    }
    usleep(200000);
  }
  (void)argc;
  (void)argv;
  return (0);
}


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)
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   10d0 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <set_port_pullups@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1040 <set_port_pullups@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10e0 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10e0 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1090 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   10f0 <set_interrupt_polarity@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1080 <mirror_interrupts@plt>
mov    $0x20,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <set_interrupt_defaults@plt>
mov    $0x20,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <set_interrupt_defaults@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_interrupt_type@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_interrupt_type@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10c0 <set_interrupt_on_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10c0 <set_interrupt_on_port@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <read_interrupt_status@plt>
cmp    $0x0,%rax
je     1345 <main+0x165>
mov    $0x20,%edi
xor    %esi,%esi
call   10a0 <read_interrupt_capture@plt>
mov    %eax,%esi
lea    0xcc0(%rip),%rdi
call   1050 <printf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1060 <read_interrupt_status@plt>
cmp    $0x0,%rax
je     137b <main+0x19b>
mov    $0x20,%edi
mov    $0x1,%esi
call   10a0 <read_interrupt_capture@plt>
mov    %eax,%esi
lea    0xc97(%rip),%rdi
call   1050 <printf@plt>
mov    $0x30d40,%edi
call   1100 <usleep@plt>
jmp    1315 <main+0x135>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   10d0 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <set_port_pullups@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1040 <set_port_pullups@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10e0 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10e0 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1090 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   10f0 <set_interrupt_polarity@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1080 <mirror_interrupts@plt>
mov    $0x20,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <set_interrupt_defaults@plt>
mov    $0x20,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <set_interrupt_defaults@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_interrupt_type@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_interrupt_type@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10c0 <set_interrupt_on_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10c0 <set_interrupt_on_port@plt>
lea    0xd05(%rip),%r14
lea    0xcf1(%rip),%rbx
jmp    132a <main+0x14a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x30d40,%edi
call   1100 <usleep@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <read_interrupt_status@plt>
test   %rax,%rax
je     1351 <main+0x171>
mov    $0x20,%edi
xor    %esi,%esi
call   10a0 <read_interrupt_capture@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1060 <read_interrupt_status@plt>
test   %rax,%rax
je     1320 <main+0x140>
mov    $0x20,%edi
mov    $0x1,%esi
call   10a0 <read_interrupt_capture@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
jmp    1320 <main+0x140>

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [13 x i8] c"Port 0: %x \0A\00"
@.str.1 = [13 x i8] c"Port 1: %x \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* @stdout
%7 = load i32, i32* @_IONBF
%8 = call i32 @setvbuf(i32 %6, i32* null, i32 %7, i32 0)
%9 = call i32 @IOPi_init(i32 32, i32 1)
%10 = call i32 @set_port_pullups(i32 32, i32 0, i32 255)
%11 = call i32 @set_port_pullups(i32 32, i32 1, i32 255)
%12 = call i32 @set_port_direction(i32 32, i32 0, i32 255)
%13 = call i32 @set_port_direction(i32 32, i32 1, i32 255)
%14 = call i32 @invert_port(i32 32, i32 0, i32 255)
%15 = call i32 @invert_port(i32 32, i32 1, i32 255)
%16 = call i32 @set_interrupt_polarity(i32 32, i32 1)
%17 = call i32 @mirror_interrupts(i32 32, i32 0)
%18 = call i32 @set_interrupt_defaults(i32 32, i32 0, i32 0)
%19 = call i32 @set_interrupt_defaults(i32 32, i32 1, i32 0)
%20 = call i32 @set_interrupt_type(i32 32, i32 0, i32 255)
%21 = call i32 @set_interrupt_type(i32 32, i32 1, i32 255)
%22 = call i32 @set_interrupt_on_port(i32 32, i32 0, i32 255)
%23 = call i32 @set_interrupt_on_port(i32 32, i32 1, i32 255)
br label %24
24: ; preds = %2, %36
%25 = call i64 @read_interrupt_status(i32 32, i32 0)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @read_interrupt_capture(i32 32, i32 0)
%29 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
%31 = call i64 @read_interrupt_status(i32 32, i32 1)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @read_interrupt_capture(i32 32, i32 1)
%35 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
%37 = call i32 @usleep(i32 200000)
br label %24
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [13 x i8] c"Port 0: %x \0A\00"
@.str.1 = [13 x i8] c"Port 1: %x \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IONBF
%5 = tail call i32 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = tail call i32 @IOPi_init(i32 32, i32 1)
%7 = tail call i32 @set_port_pullups(i32 32, i32 0, i32 255)
%8 = tail call i32 @set_port_pullups(i32 32, i32 1, i32 255)
%9 = tail call i32 @set_port_direction(i32 32, i32 0, i32 255)
%10 = tail call i32 @set_port_direction(i32 32, i32 1, i32 255)
%11 = tail call i32 @invert_port(i32 32, i32 0, i32 255)
%12 = tail call i32 @invert_port(i32 32, i32 1, i32 255)
%13 = tail call i32 @set_interrupt_polarity(i32 32, i32 1)
%14 = tail call i32 @mirror_interrupts(i32 32, i32 0)
%15 = tail call i32 @set_interrupt_defaults(i32 32, i32 0, i32 0)
%16 = tail call i32 @set_interrupt_defaults(i32 32, i32 1, i32 0)
%17 = tail call i32 @set_interrupt_type(i32 32, i32 0, i32 255)
%18 = tail call i32 @set_interrupt_type(i32 32, i32 1, i32 255)
%19 = tail call i32 @set_interrupt_on_port(i32 32, i32 0, i32 255)
%20 = tail call i32 @set_interrupt_on_port(i32 32, i32 1, i32 255)
br label %21
21: ; preds = %2, %33
%22 = tail call i64 @read_interrupt_status(i32 32, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i32 @read_interrupt_capture(i32 32, i32 0)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %21
%28 = tail call i64 @read_interrupt_status(i32 32, i32 1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = tail call i32 @read_interrupt_capture(i32 32, i32 1)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %27
%34 = tail call i32 @usleep(i32 200000)
br label %21
}