#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*/ IOPi_init(int, int);
int /*<<< orphan*/ invert_port(int, int, int);
int read_pin(int, int);
int /*<<< orphan*/ set_port_direction(int, int, int);
int /*<<< orphan*/ set_port_pullups(int, int, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_pin(int, int, int);
int main(int argc, char **argv) {
  IOPi_init(0x20, 1);
  IOPi_init(0x21, 1);
  set_port_direction(0x20, 0, 0x00);
  set_port_direction(0x20, 1, 0x00);
  set_port_direction(0x21, 0, 0xFF);
  set_port_direction(0x21, 1, 0xFF);
  set_port_pullups(0x21, 0, 0xFF);
  invert_port(0x21, 0, 0xFF);
  set_port_pullups(0x21, 1, 0xFF);
  invert_port(0x21, 1, 0xFF);
  int led = 0;
  int button_last_state = 0;
  write_pin(0x20, 11, 0);
  while (1) {
    if (read_pin(0x21, 15) == 1) {
      if (button_last_state == 0) {
        if (led == 0) {
          led = 1;
        } else {
          led = 0;
        }
        write_pin(0x20, 11, led);
      }
      button_last_state = 1;
    } else {
      button_last_state = 0;
    }
    usleep(100000);
  }
  (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    $0x20,%edi
mov    $0x1,%esi
call   1070 <IOPi_init@plt>
mov    $0x21,%edi
mov    $0x1,%esi
call   1070 <IOPi_init@plt>
mov    $0x20,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <invert_port@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1050 <invert_port@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x20,%edi
mov    $0xb,%esi
xor    %edx,%edx
call   1060 <write_pin@plt>
mov    $0x21,%edi
mov    $0xf,%esi
call   1040 <read_pin@plt>
cmp    $0x1,%eax
jne    12ae <main+0x13e>
cmpl   $0x0,-0x18(%rbp)
jne    12a2 <main+0x132>
cmpl   $0x0,-0x14(%rbp)
jne    1289 <main+0x119>
movl   $0x1,-0x14(%rbp)
jmp    1290 <main+0x120>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x20,%edi
mov    $0xb,%esi
call   1060 <write_pin@plt>
movl   $0x1,-0x18(%rbp)
jmp    12b5 <main+0x145>
movl   $0x0,-0x18(%rbp)
mov    $0x186a0,%edi
call   1090 <usleep@plt>
jmp    1251 <main+0xe1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x20,%edi
mov    $0x1,%esi
call   1070 <IOPi_init@plt>
mov    $0x21,%edi
mov    $0x1,%esi
call   1070 <IOPi_init@plt>
xor    %r14d,%r14d
mov    $0x20,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <set_port_direction@plt>
mov    $0x20,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1080 <set_port_direction@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x21,%edi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <invert_port@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <set_port_pullups@plt>
mov    $0x21,%edi
mov    $0x1,%esi
mov    $0xff,%edx
call   1050 <invert_port@plt>
mov    $0x20,%edi
mov    $0xb,%esi
xor    %edx,%edx
call   1060 <write_pin@plt>
xor    %ebx,%ebx
jmp    124e <main+0xde>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    %ebp,%ebx
mov    $0x21,%edi
mov    $0xf,%esi
call   1040 <read_pin@plt>
cmp    $0x1,%eax
jne    1240 <main+0xd0>
mov    $0x1,%ebp
test   %ebx,%ebx
jne    1242 <main+0xd2>
xor    %ebx,%ebx
test   %r14d,%r14d
sete   %bl
mov    $0x20,%edi
mov    $0xb,%esi
mov    %ebx,%edx
call   1060 <write_pin@plt>
mov    %ebx,%r14d
jmp    1242 <main+0xd2>

LLVM IR (-O0):
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 = call i32 @IOPi_init(i32 32, i32 1)
%9 = call i32 @IOPi_init(i32 33, i32 1)
%10 = call i32 @set_port_direction(i32 32, i32 0, i32 0)
%11 = call i32 @set_port_direction(i32 32, i32 1, i32 0)
%12 = call i32 @set_port_direction(i32 33, i32 0, i32 255)
%13 = call i32 @set_port_direction(i32 33, i32 1, i32 255)
%14 = call i32 @set_port_pullups(i32 33, i32 0, i32 255)
%15 = call i32 @invert_port(i32 33, i32 0, i32 255)
%16 = call i32 @set_port_pullups(i32 33, i32 1, i32 255)
%17 = call i32 @invert_port(i32 33, i32 1, i32 255)
store i32 0, i32* %6
store i32 0, i32* %7
%18 = call i32 @write_pin(i32 32, i32 11, i32 0)
br label %19
19: ; preds = %2, %35
%20 = call i32 @read_pin(i32 33, i32 15)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %6
br label %30
29: ; preds = %25
store i32 0, i32* %6
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %6
%32 = call i32 @write_pin(i32 32, i32 11, i32 %31)
br label %33
33: ; preds = %30, %22
store i32 1, i32* %7
br label %35
34: ; preds = %19
store i32 0, i32* %7
br label %35
35: ; preds = %34, %33
%36 = call i32 @usleep(i32 100000)
br label %19
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @IOPi_init(i32 32, i32 1)
%4 = tail call i32 @IOPi_init(i32 33, i32 1)
%5 = tail call i32 @set_port_direction(i32 32, i32 0, i32 0)
%6 = tail call i32 @set_port_direction(i32 32, i32 1, i32 0)
%7 = tail call i32 @set_port_direction(i32 33, i32 0, i32 255)
%8 = tail call i32 @set_port_direction(i32 33, i32 1, i32 255)
%9 = tail call i32 @set_port_pullups(i32 33, i32 0, i32 255)
%10 = tail call i32 @invert_port(i32 33, i32 0, i32 255)
%11 = tail call i32 @set_port_pullups(i32 33, i32 1, i32 255)
%12 = tail call i32 @invert_port(i32 33, i32 1, i32 255)
%13 = tail call i32 @write_pin(i32 32, i32 11, i32 0)
br label %14
14: ; preds = %25, %2
%15 = phi i32 [ 0, %2 ], [ %26, %25 ]
%16 = phi i32 [ 0, %2 ], [ %27, %25 ]
%17 = tail call i32 @read_pin(i32 33, i32 15)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = icmp eq i32 %16, 0
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = icmp eq i32 %15, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @write_pin(i32 32, i32 11, i32 %23)
br label %25
25: ; preds = %14, %19, %21
%26 = phi i32 [ %23, %21 ], [ %15, %19 ], [ %15, %14 ]
%27 = phi i32 [ 1, %21 ], [ 1, %19 ], [ 0, %14 ]
%28 = tail call i32 @usleep(i32 100000)
br label %14
}