#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*/ CHECK(int, int, int, int, int, char *);
int /*<<< orphan*/ clear_bank_1(int);
int clear_bank_2(int);
int gpio_read(int);
int /*<<< orphan*/ gpio_write(int, int);
int /*<<< orphan*/ printf(char *);
int read_bank_1();
int read_bank_2();
int /*<<< orphan*/ set_bank_1(int);
int set_bank_2(int);
void t8() {
  int v, t, i;
  printf("Bank read/write tests.\n");
  gpio_write(4, 0);
  v = read_bank_1() & (1 << 4);
  CHECK(8, 1, v, 0, 0, "read bank 1");
  gpio_write(4, 1);
  v = read_bank_1() & (1 << 4);
  CHECK(8, 2, v, (1 << 4), 0, "read bank 1");
  clear_bank_1(1 << 4);
  v = gpio_read(4);
  CHECK(8, 3, v, 0, 0, "clear bank 1");
  set_bank_1(1 << 4);
  v = gpio_read(4);
  CHECK(8, 4, v, 1, 0, "set bank 1");
  t = 0;
  v = (1 << 16);
  for (i = 0; i < 100; i++) {
    if (read_bank_2() & v)
      t++;
  };
  CHECK(8, 5, t, 60, 75, "read bank 2");
  v = clear_bank_2(0);
  CHECK(8, 6, v, 0, 0, "clear bank 2");
  v = clear_bank_2(0xffffff);
  CHECK(8, 7, v, -42, 0, "clear bank 2");
  v = set_bank_2(0);
  CHECK(8, 8, v, 0, 0, "set bank 2");
  v = set_bank_2(0xffffff);
  CHECK(8, 9, v, -42, 0, "set bank 2");
}


x86 assembly (clang, -O0):
<t8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe51(%rip),%rdi
call   1060 <printf@plt>
mov    $0x4,%edi
xor    %esi,%esi
call   1070 <gpio_write@plt>
mov    $0x0,%al
call   10c0 <read_bank_1@plt>
and    $0x10,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x1,%esi
xor    %r8d,%r8d
lea    0xe34(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    $0x4,%edi
mov    $0x1,%esi
call   1070 <gpio_write@plt>
mov    $0x0,%al
call   10c0 <read_bank_1@plt>
and    $0x10,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x2,%esi
mov    $0x10,%ecx
xor    %r8d,%r8d
lea    0xdf4(%rip),%r9
call   1030 <CHECK@plt>
mov    $0x10,%edi
call   1040 <clear_bank_1@plt>
mov    $0x4,%edi
call   1090 <gpio_read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x3,%esi
xor    %r8d,%r8d
lea    0xdcd(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    $0x10,%edi
call   1050 <set_bank_1@plt>
mov    $0x4,%edi
call   1090 <gpio_read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x4,%esi
mov    $0x1,%ecx
xor    %r8d,%r8d
lea    0xd9f(%rip),%r9
call   1030 <CHECK@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x10000,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    12e5 <t8+0x145>
mov    $0x0,%al
call   1080 <read_bank_2@plt>
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
je     12d2 <t8+0x132>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12d7 <t8+0x137>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12ac <t8+0x10c>
mov    -0x8(%rbp),%edx
mov    $0x8,%edi
mov    $0x5,%esi
mov    $0x3c,%ecx
mov    $0x4b,%r8d
lea    0xd38(%rip),%r9
call   1030 <CHECK@plt>
xor    %edi,%edi
call   10a0 <clear_bank_2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x6,%esi
xor    %r8d,%r8d
lea    0xd1e(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    $0xffffff,%edi
call   10a0 <clear_bank_2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x7,%esi
mov    $0xffffffd6,%ecx
xor    %r8d,%r8d
lea    0xced(%rip),%r9
call   1030 <CHECK@plt>
xor    %edi,%edi
call   10b0 <set_bank_2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%esi
xor    %r8d,%r8d
lea    0xcd9(%rip),%r9
mov    %esi,%edi
mov    %r8d,%ecx
call   1030 <CHECK@plt>
mov    $0xffffff,%edi
call   10b0 <set_bank_2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x8,%edi
mov    $0x9,%esi
mov    $0xffffffd6,%ecx
xor    %r8d,%r8d
lea    0xca6(%rip),%r9
call   1030 <CHECK@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t8>:
push   %rbp
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%edi
xor    %esi,%esi
call   1070 <gpio_write@plt>
xor    %eax,%eax
call   10c0 <read_bank_1@plt>
and    $0x10,%eax
lea    0xe34(%rip),%rbx
mov    $0x8,%edi
mov    $0x1,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1030 <CHECK@plt>
mov    $0x4,%edi
mov    $0x1,%esi
call   1070 <gpio_write@plt>
xor    %eax,%eax
call   10c0 <read_bank_1@plt>
and    $0x10,%eax
mov    $0x8,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x10,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1030 <CHECK@plt>
mov    $0x10,%edi
call   1050 <clear_bank_1@plt>
mov    $0x4,%edi
call   1090 <gpio_read@plt>
lea    0xdd7(%rip),%r9
mov    $0x8,%edi
mov    $0x3,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
mov    $0x10,%edi
call   1060 <set_bank_1@plt>
mov    $0x4,%edi
call   1090 <gpio_read@plt>
lea    0xdb3(%rip),%r9
mov    $0x8,%edi
mov    $0x4,%esi
mov    %eax,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
mov    $0x64,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <read_bank_2@plt>
shr    $0x10,%eax
and    $0x1,%eax
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1290 <t8+0xf0>
lea    0xd79(%rip),%r9
mov    $0x8,%edi
mov    $0x5,%esi
mov    %ebx,%edx
mov    $0x3c,%ecx
mov    $0x4b,%r8d
call   1030 <CHECK@plt>
xor    %edi,%edi
call   10a0 <clear_bank_2@plt>
lea    0xd5b(%rip),%rbx
mov    $0x8,%edi
mov    $0x6,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1030 <CHECK@plt>
mov    $0xffffff,%edi
call   10a0 <clear_bank_2@plt>
mov    $0x8,%edi
mov    $0x7,%esi
mov    %eax,%edx
mov    $0xffffffd6,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1030 <CHECK@plt>
xor    %edi,%edi
call   10b0 <set_bank_2@plt>
lea    0xd1b(%rip),%rbx
mov    $0x8,%edi
mov    $0x8,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1030 <CHECK@plt>
mov    $0xffffff,%edi
call   10b0 <set_bank_2@plt>
mov    $0x8,%edi
mov    $0x9,%esi
mov    %eax,%edx
mov    $0xffffffd6,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <CHECK@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Bank read/write tests.\0A\00"
@.str.1 = [12 x i8] c"read bank 1\00"
@.str.2 = [13 x i8] c"clear bank 1\00"
@.str.3 = [11 x i8] c"set bank 1\00"
@.str.4 = [12 x i8] c"read bank 2\00"
@.str.5 = [13 x i8] c"clear bank 2\00"
@.str.6 = [11 x i8] c"set bank 2\00"
define void @t8() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gpio_write(i32 4, i32 0)
%6 = call i32 (...) @read_bank_1()
%7 = and i32 %6, 16
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = call i32 @CHECK(i32 8, i32 1, i32 %8, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @gpio_write(i32 4, i32 1)
%11 = call i32 (...) @read_bank_1()
%12 = and i32 %11, 16
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = call i32 @CHECK(i32 8, i32 2, i32 %13, i32 16, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @clear_bank_1(i32 16)
%16 = call i32 @gpio_read(i32 4)
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = call i32 @CHECK(i32 8, i32 3, i32 %17, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @set_bank_1(i32 16)
%20 = call i32 @gpio_read(i32 4)
store i32 %20, i32* %1
%21 = load i32, i32* %1
%22 = call i32 @CHECK(i32 8, i32 4, i32 %21, i32 1, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
store i32 65536, i32* %1
store i32 0, i32* %3
br label %23
23: ; preds = %35, %0
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 100
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = call i32 (...) @read_bank_2()
%28 = load i32, i32* %1
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %34
34: ; preds = %31, %26
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %23
38: ; preds = %23
%39 = load i32, i32* %2
%40 = call i32 @CHECK(i32 8, i32 5, i32 %39, i32 60, i32 75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @clear_bank_2(i32 0)
store i32 %41, i32* %1
%42 = load i32, i32* %1
%43 = call i32 @CHECK(i32 8, i32 6, i32 %42, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @clear_bank_2(i32 16777215)
store i32 %44, i32* %1
%45 = load i32, i32* %1
%46 = call i32 @CHECK(i32 8, i32 7, i32 %45, i32 -42, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @set_bank_2(i32 0)
store i32 %47, i32* %1
%48 = load i32, i32* %1
%49 = call i32 @CHECK(i32 8, i32 8, i32 %48, i32 0, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%50 = call i32 @set_bank_2(i32 16777215)
store i32 %50, i32* %1
%51 = load i32, i32* %1
%52 = call i32 @CHECK(i32 8, i32 9, i32 %51, i32 -42, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"read bank 1\00"
@.str.2 = [13 x i8] c"clear bank 1\00"
@.str.3 = [11 x i8] c"set bank 1\00"
@.str.4 = [12 x i8] c"read bank 2\00"
@.str.5 = [13 x i8] c"clear bank 2\00"
@.str.6 = [11 x i8] c"set bank 2\00"
@str = [23 x i8] c"Bank read/write tests.\00"
define void @t8() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @gpio_write(i32 4, i32 0)
%3 = tail call i32 (...) @read_bank_1()
%4 = and i32 %3, 16
%5 = tail call i32 @CHECK(i32 8, i32 1, i32 %4, i32 0, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @gpio_write(i32 4, i32 1)
%7 = tail call i32 (...) @read_bank_1()
%8 = and i32 %7, 16
%9 = tail call i32 @CHECK(i32 8, i32 2, i32 %8, i32 16, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @clear_bank_1(i32 16)
%11 = tail call i32 @gpio_read(i32 4)
%12 = tail call i32 @CHECK(i32 8, i32 3, i32 %11, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @set_bank_1(i32 16)
%14 = tail call i32 @gpio_read(i32 4)
%15 = tail call i32 @CHECK(i32 8, i32 4, i32 %14, i32 1, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %0, %16
%17 = phi i32 [ 0, %0 ], [ %23, %16 ]
%18 = phi i32 [ 0, %0 ], [ %22, %16 ]
%19 = tail call i32 (...) @read_bank_2()
%20 = lshr i32 %19, 16
%21 = and i32 %20, 1
%22 = add nuw nsw i32 %21, %18
%23 = add nuw nsw i32 %17, 1
%24 = icmp eq i32 %23, 100
br i1 %24, label %25, label %16
25: ; preds = %16
%26 = tail call i32 @CHECK(i32 8, i32 5, i32 %22, i32 60, i32 75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @clear_bank_2(i32 0)
%28 = tail call i32 @CHECK(i32 8, i32 6, i32 %27, i32 0, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 @clear_bank_2(i32 16777215)
%30 = tail call i32 @CHECK(i32 8, i32 7, i32 %29, i32 -42, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call i32 @set_bank_2(i32 0)
%32 = tail call i32 @CHECK(i32 8, i32 8, i32 %31, i32 0, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%33 = tail call i32 @set_bank_2(i32 16777215)
%34 = tail call i32 @CHECK(i32 8, i32 9, i32 %33, i32 -42, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}