#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ IOPi_init(int, int /*<<< orphan*/);
int /*<<< orphan*/ _IONBF;
int get_bus_pullups(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ set_bus_pullups(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;
  uint16_t x = 0;
  IOPi_init(0x20, 0);
  printf("Testing get_bus_pullups\n");
  for (uint16_t a = 0; a < 65535; a++) {
    printf("\r%d of 65534", a);
    set_bus_pullups(0x20, a);
    x = get_bus_pullups(0x20);
    if (x != a) {
      passed = false;
      break;
    }
  }
  if (!passed) {
    printf("\nTest Failed \n");
  } else {
    printf("\nTest Passed \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>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xffff,-0x1c(%rbp)
jge    1215 <main+0xc5>
mov    -0x1c(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    $0x20,%edi
call   1040 <set_bus_pullups@plt>
mov    $0x20,%edi
call   1050 <get_bus_pullups@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1202 <main+0xb2>
movl   $0x0,-0x14(%rbp)
jmp    1215 <main+0xc5>
jmp    1207 <main+0xb7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b2 <main+0x62>
cmpl   $0x0,-0x14(%rbp)
jne    1232 <main+0xe2>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0xf0>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1080 <IOPi_init@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5f(%rip),%rbx
lea    0xe7d(%rip),%r14
lea    0xe84(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
mov    %ebp,%esi
call   1050 <set_bus_pullups@plt>
mov    $0x20,%edi
call   1060 <get_bus_pullups@plt>
cmp    %eax,%ebp
jne    11f4 <main+0x94>
add    $0x1,%ebp
cmp    $0xffff,%ebp
jne    11c0 <main+0x60>
mov    %r15,%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [25 x i8] c"Testing get_bus_pullups\0A\00"
@.str.1 = [13 x i8] c"\0D%d of 65534\00"
@.str.2 = [15 x i8] c"\0ATest Failed \0A\00"
@.str.3 = [15 x i8] c"\0ATest Passed \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)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %14
14: ; preds = %28, %2
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 65535
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %8
%21 = call i32 @set_bus_pullups(i32 32, i32 %20)
%22 = call i32 @get_bus_pullups(i32 32)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 0, i32* %6
br label %31
27: ; preds = %17
br label %28
28: ; preds = %27
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %14
31: ; preds = %26, %14
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = load i32, i32* %4
%40 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str.1 = [13 x i8] c"\0D%d of 65534\00"
@str = [24 x i8] c"Testing get_bus_pullups\00"
@str.4 = [14 x i8] c"\0ATest Failed \00"
@str.5 = [14 x i8] c"\0ATest 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %11
%9 = add nuw nsw i32 %12, 1
%10 = icmp eq i32 %9, 65535
br i1 %10, label %17, label %11
11: ; preds = %2, %8
%12 = phi i32 [ 0, %2 ], [ %9, %8 ]
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @set_bus_pullups(i32 32, i32 %12)
%15 = tail call i32 @get_bus_pullups(i32 32)
%16 = icmp eq i32 %15, %12
br i1 %16, label %8, label %17
17: ; preds = %8, %11
%18 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0), %11 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %8 ]
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
ret i32 0
}