#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_interrupt_on_pin(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_interrupt_on_pin(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 = 1; a < 17; a++) {
    set_interrupt_on_pin(0x20, a, 0);
    x = get_interrupt_on_pin(0x20, a);
    if (x != 0) {
      passed = false;
      break;
    }
    set_interrupt_on_pin(0x20, a, 1);
    x = get_interrupt_on_pin(0x20, a);
    if (x != 1) {
      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   1060 <setvbuf@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <IOPi_init@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x11,-0x1c(%rbp)
jge    122e <main+0xde>
mov    -0x1c(%rbp),%esi
mov    $0x20,%edi
xor    %edx,%edx
call   1040 <set_interrupt_on_pin@plt>
mov    -0x1c(%rbp),%esi
mov    $0x20,%edi
call   1030 <get_interrupt_on_pin@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e3 <main+0x93>
movl   $0x0,-0x14(%rbp)
jmp    122e <main+0xde>
mov    -0x1c(%rbp),%esi
mov    $0x20,%edi
mov    $0x1,%edx
call   1040 <set_interrupt_on_pin@plt>
mov    -0x1c(%rbp),%esi
mov    $0x20,%edi
call   1030 <get_interrupt_on_pin@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     121b <main+0xcb>
movl   $0x0,-0x14(%rbp)
jmp    122e <main+0xde>
jmp    1220 <main+0xd0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a4 <main+0x54>
cmpl   $0x0,-0x14(%rbp)
je     1249 <main+0xf9>
lea    0xdc1(%rip),%rdi
call   1050 <printf@plt>
jmp    1255 <main+0x105>
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <IOPi_init@plt>
mov    $0x1,%ebp
lea    0xe79(%rip),%rbx
lea    0xe7f(%rip),%r14
xchg   %ax,%ax
mov    $0x20,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1050 <set_interrupt_on_pin@plt>
mov    $0x20,%edi
mov    %ebp,%esi
call   1040 <get_interrupt_on_pin@plt>
test   %eax,%eax
jne    11db <main+0x8b>
mov    $0x20,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1050 <set_interrupt_on_pin@plt>
mov    $0x20,%edi
mov    %ebp,%esi
call   1040 <get_interrupt_on_pin@plt>
cmp    $0x1,%eax
jne    11db <main+0x8b>
add    $0x1,%ebp
cmp    $0x11,%ebp
jne    1190 <main+0x40>
mov    %r14,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
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 1, i32* %8
br label %13
13: ; preds = %33, %2
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 17
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i32, i32* %8
%18 = call i32 @set_interrupt_on_pin(i32 32, i32 %17, i32 0)
%19 = load i32, i32* %8
%20 = call i32 @get_interrupt_on_pin(i32 32, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
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_interrupt_on_pin(i32 32, i32 %25, i32 1)
%27 = load i32, i32* %8
%28 = call i32 @get_interrupt_on_pin(i32 32, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 1
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, 17
br i1 %9, label %19, label %10
10: ; preds = %2, %7
%11 = phi i32 [ 1, %2 ], [ %8, %7 ]
%12 = tail call i32 @set_interrupt_on_pin(i32 32, i32 %11, i32 0)
%13 = tail call i32 @get_interrupt_on_pin(i32 32, i32 %11)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @set_interrupt_on_pin(i32 32, i32 %11, i32 1)
%17 = tail call i32 @get_interrupt_on_pin(i32 32, i32 %11)
%18 = icmp eq i32 %17, 1
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
}