#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_polarity(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_interrupt_polarity(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);
  set_interrupt_polarity(0x20, 0);
  x = get_interrupt_polarity(0x20);
  if (x != 0) {
    passed = false;
  }
  set_interrupt_polarity(0x20, 1);
  x = get_interrupt_polarity(0x20);
  if (x != 1) {
    passed = false;
  }
  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   1050 <setvbuf@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <set_interrupt_polarity@plt>
mov    $0x20,%edi
call   1040 <get_interrupt_polarity@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c7 <main+0x77>
movl   $0x0,-0x14(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1070 <set_interrupt_polarity@plt>
mov    $0x20,%edi
call   1040 <get_interrupt_polarity@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     11f4 <main+0xa4>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     120f <main+0xbf>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
jmp    121b <main+0xcb>
lea    0xdf8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <set_interrupt_polarity@plt>
mov    $0x20,%edi
call   1040 <get_interrupt_polarity@plt>
mov    %eax,%ebx
mov    $0x20,%edi
mov    $0x1,%esi
call   1070 <set_interrupt_polarity@plt>
mov    $0x20,%edi
call   1040 <get_interrupt_polarity@plt>
xor    $0x1,%eax
lea    0xe4d(%rip),%rcx
lea    0xe53(%rip),%rdi
or     %ebx,%eax
cmovne %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdout
%9 = load i32, i32* @_IONBF
%10 = call i32 @setvbuf(i32 %8, i32* null, i32 %9, i32 0)
store i32 1, i32* %6
store i32 0, i32* %7
%11 = call i32 @IOPi_init(i32 32, i32 0)
%12 = call i32 @set_interrupt_polarity(i32 32, i32 0)
%13 = call i32 @get_interrupt_polarity(i32 32)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %16, %2
%18 = call i32 @set_interrupt_polarity(i32 32, i32 1)
%19 = call i32 @get_interrupt_polarity(i32 32)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %6
br label %23
23: ; preds = %22, %17
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
%31 = load i32, i32* %4
%32 = 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)
%7 = tail call i32 @set_interrupt_polarity(i32 32, i32 0)
%8 = tail call i32 @get_interrupt_polarity(i32 32)
%9 = icmp ne i32 %8, 0
%10 = tail call i32 @set_interrupt_polarity(i32 32, i32 1)
%11 = tail call i32 @get_interrupt_polarity(i32 32)
%12 = icmp ne i32 %11, 1
%13 = select i1 %12, i1 true, i1 %9
%14 = select i1 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.2, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
ret i32 0
}