#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 i2c_read_leuint08(int, int, int, int *);
int gpio_BTN(int bus, int chip_addr, uint8_t *btn) {
  uint8_t value;
  int err = i2c_read_leuint08(bus, chip_addr, 0x13, &value);
  if (err == 1) {
    uint8_t tmp = (value & 0x60);
    switch (tmp) {
    case 64:
      *btn = 1;
      break;
    case 32:
      *btn = 2;
      break;
    case 0:
      *btn = 3;
      break;
    default:
      *btn = 0;
      break;
    }
    return 0;
  }
  return err;
}


x86 assembly (clang, -O0):
<gpio_BTN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x13,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <i2c_read_leuint08@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11c4 <gpio_BTN+0xb4>
mov    -0x1c(%rbp),%eax
and    $0x60,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     119f <gpio_BTN+0x8f>
jmp    115f <gpio_BTN+0x4f>
mov    -0x28(%rbp),%eax
sub    $0x20,%eax
je     1190 <gpio_BTN+0x80>
jmp    1170 <gpio_BTN+0x60>
mov    -0x28(%rbp),%eax
sub    $0x40,%eax
jne    11ae <gpio_BTN+0x9e>
jmp    1181 <gpio_BTN+0x71>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11b8 <gpio_BTN+0xa8>
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
jmp    11b8 <gpio_BTN+0xa8>
mov    -0x18(%rbp),%rax
movl   $0x3,(%rax)
jmp    11b8 <gpio_BTN+0xa8>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11ca <gpio_BTN+0xba>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_BTN>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
lea    0xc(%rsp),%rcx
mov    $0x13,%edx
call   1030 <i2c_read_leuint08@plt>
cmp    $0x1,%eax
jne    115a <gpio_BTN+0x4a>
mov    0xc(%rsp),%eax
and    $0x60,%eax
je     1146 <gpio_BTN+0x36>
cmp    $0x40,%eax
je     114d <gpio_BTN+0x3d>
cmp    $0x20,%eax
jne    1154 <gpio_BTN+0x44>
mov    $0x2,%eax
jmp    1156 <gpio_BTN+0x46>
mov    $0x3,%eax
jmp    1156 <gpio_BTN+0x46>
mov    $0x1,%eax
jmp    1156 <gpio_BTN+0x46>
xor    %eax,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @gpio_BTN(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @i2c_read_leuint08(i32 %11, i32 %12, i32 19, i32* %8)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %29
16: ; preds = %3
%17 = load i32, i32* %8
%18 = and i32 %17, 96
store i32 %18, i32* %10
%19 = load i32, i32* %10
switch i32 %19, label %26 [
i32 64, label %20
i32 32, label %22
i32 0, label %24
]
20: ; preds = %16
%21 = load i32*, i32** %7
store i32 1, i32* %21
br label %28
22: ; preds = %16
%23 = load i32*, i32** %7
store i32 2, i32* %23
br label %28
24: ; preds = %16
%25 = load i32*, i32** %7
store i32 3, i32* %25
br label %28
26: ; preds = %16
%27 = load i32*, i32** %7
store i32 0, i32* %27
br label %28
28: ; preds = %26, %24, %22, %20
store i32 0, i32* %4
br label %31
29: ; preds = %3
%30 = load i32, i32* %9
store i32 %30, i32* %4
br label %31
31: ; preds = %29, %28
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @gpio_BTN(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @i2c_read_leuint08(i32 %0, i32 %1, i32 19, i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = load i32, i32* %4
%10 = and i32 %9, 96
switch i32 %10, label %13 [
i32 64, label %14
i32 32, label %11
i32 0, label %12
]
11: ; preds = %8
br label %14
12: ; preds = %8
br label %14
13: ; preds = %8
br label %14
14: ; preds = %8, %13, %12, %11
%15 = phi i32 [ 2, %11 ], [ 3, %12 ], [ 0, %13 ], [ 1, %8 ]
store i32 %15, i32* %2
br label %16
16: ; preds = %14, %3
%17 = phi i32 [ %6, %3 ], [ 0, %14 ]
ret i32 %17
}