#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ IOPi_init(int, int /*<<< orphan*/);
int /*<<< orphan*/ _IONBF;
int get_port_direction(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_port_direction(int, int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  bool passed = true;
  uint8_t x = 0;
  IOPi_init(0x20, 0);
  for (uint8_t a = 0; a < 255; a++) {
    set_port_direction(0x20, 0, a);
    x = get_port_direction(0x20, 0);
    if (x != a) {
      passed = false;
      break;
    }
    set_port_direction(0x20, 1, a);
    x = get_port_direction(0x20, 1);
    if (x != a) {
      passed = false;
      break;
    }
  }
  if (passed) {
    printf("Test passed \n");
  } else {
    printf("Test Failed \n");
  }
  (void)argc;
  (void)argv;
  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)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x20,%edi
xor    %esi,%esi
call   1050 <IOPi_init@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xff,-0x1c(%rbp)
jge    1236 <main+0xe6>
mov    -0x1c(%rbp),%edx
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <get_port_direction@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11e7 <main+0x97>
movl   $0x0,-0x14(%rbp)
jmp    1236 <main+0xe6>
mov    -0x1c(%rbp),%edx
mov    $0x20,%edi
mov    $0x1,%esi
call   1070 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1060 <get_port_direction@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1223 <main+0xd3>
movl   $0x0,-0x14(%rbp)
jmp    1236 <main+0xe6>
jmp    1228 <main+0xd8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a4 <main+0x54>
cmpl   $0x0,-0x14(%rbp)
je     1251 <main+0x101>
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
jmp    125d <main+0x10d>
lea    0xdb6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1050 <IOPi_init@plt>
lea    0xe7b(%rip),%r14
lea    0xe81(%rip),%r15
nopl   0x0(%rax)
mov    $0x20,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1070 <set_port_direction@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <get_port_direction@plt>
cmp    %eax,%ebx
jne    11e0 <main+0x90>
mov    $0x20,%edi
mov    $0x1,%esi
mov    %ebx,%edx
call   1070 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
call   1060 <get_port_direction@plt>
cmp    %eax,%ebx
jne    11e0 <main+0x90>
add    $0x1,%ebx
cmp    $0xff,%ebx
jne    1190 <main+0x40>
mov    %r15,%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [14 x i8] c"Test passed \0A\00"
@.str.1 = [14 x i8] c"Test Failed \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @stdout
%10 = load i32, i32* @_IONBF
%11 = call i32 @setvbuf(i32 %9, i32* null, i32 %10, i32 0)
store i32 1, i32* %6
store i32 0, i32* %7
%12 = call i32 @IOPi_init(i32 32, i32 0)
store i32 0, i32* %8
br label %13
13: ; preds = %33, %2
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 255
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i32, i32* %8
%18 = call i32 @set_port_direction(i32 32, i32 0, i32 %17)
%19 = call i32 @get_port_direction(i32 32, i32 0)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 0, i32* %6
br label %36
24: ; preds = %16
%25 = load i32, i32* %8
%26 = call i32 @set_port_direction(i32 32, i32 1, i32 %25)
%27 = call i32 @get_port_direction(i32 32, i32 1)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 0, i32* %6
br label %36
32: ; preds = %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %13
36: ; preds = %31, %23, %13
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %43
41: ; preds = %36
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
%44 = load i32, i32* %4
%45 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@str = [13 x i8] c"Test Failed \00"
@str.2 = [13 x i8] c"Test passed \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 0)
br label %10
7: ; preds = %15
%8 = add nuw nsw i32 %11, 1
%9 = icmp eq i32 %8, 255
br i1 %9, label %19, label %10
10: ; preds = %2, %7
%11 = phi i32 [ 0, %2 ], [ %8, %7 ]
%12 = tail call i32 @set_port_direction(i32 32, i32 0, i32 %11)
%13 = tail call i32 @get_port_direction(i32 32, i32 0)
%14 = icmp eq i32 %13, %11
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @set_port_direction(i32 32, i32 1, i32 %11)
%17 = tail call i32 @get_port_direction(i32 32, i32 1)
%18 = icmp eq i32 %17, %11
br i1 %18, label %7, label %19
19: ; preds = %15, %10, %7
%20 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %15 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
ret i32 0
}