#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*/ clearscreen();
int /*<<< orphan*/ invert_port(int, int, int);
int /*<<< orphan*/ printf(char *, int);
int read_port(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_direction(0x20, 0, 0xFF);
  set_port_direction(0x20, 1, 0xFF);
  set_port_pullups(0x20, 0, 0xFF);
  invert_port(0x20, 0, 0xFF);
  set_port_pullups(0x20, 1, 0xFF);
  invert_port(0x20, 1, 0xFF);
  while (1) {
    clearscreen();
    printf("Port 0 %x \n", read_port(0x20, 0));
    printf("Port 1 %x \n", read_port(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    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1080 <setvbuf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1090 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10a0 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10a0 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1070 <invert_port@plt>
mov    $0x0,%al
call   1050 <clearscreen@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <read_port@plt>
mov    %eax,%esi
lea    0xda3(%rip),%rdi
call   1060 <printf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1040 <read_port@plt>
mov    %eax,%esi
lea    0xd92(%rip),%rdi
call   1060 <printf@plt>
mov    $0x30d40,%edi
call   10b0 <usleep@plt>
jmp    1241 <main+0xb1>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1080 <setvbuf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1090 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   10a0 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   10a0 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x20,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <invert_port@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x20,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1070 <invert_port@plt>
lea    0xdcc(%rip),%r14
lea    0xdd1(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <clearscreen@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <read_port@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1040 <read_port@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x30d40,%edi
call   10b0 <usleep@plt>
jmp    1240 <main+0xb0>

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [12 x i8] c"Port 0 %x \0A\00"
@.str.1 = [12 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_direction(i32 32, i32 0, i32 255)
%11 = call i32 @set_port_direction(i32 32, i32 1, i32 255)
%12 = call i32 @set_port_pullups(i32 32, i32 0, i32 255)
%13 = call i32 @invert_port(i32 32, i32 0, i32 255)
%14 = call i32 @set_port_pullups(i32 32, i32 1, i32 255)
%15 = call i32 @invert_port(i32 32, i32 1, i32 255)
br label %16
16: ; preds = %2, %16
%17 = call i32 (...) @clearscreen()
%18 = call i32 @read_port(i32 32, i32 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @read_port(i32 32, i32 1)
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @usleep(i32 200000)
br label %16
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [12 x i8] c"Port 0 %x \0A\00"
@.str.1 = [12 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_direction(i32 32, i32 0, i32 255)
%8 = tail call i32 @set_port_direction(i32 32, i32 1, i32 255)
%9 = tail call i32 @set_port_pullups(i32 32, i32 0, i32 255)
%10 = tail call i32 @invert_port(i32 32, i32 0, i32 255)
%11 = tail call i32 @set_port_pullups(i32 32, i32 1, i32 255)
%12 = tail call i32 @invert_port(i32 32, i32 1, i32 255)
br label %13
13: ; preds = %2, %13
%14 = tail call i32 (...) @clearscreen()
%15 = tail call i32 @read_port(i32 32, i32 0)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @read_port(i32 32, i32 1)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = tail call i32 @usleep(i32 200000)
br label %13
}