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

/* Variables and functions */
int bcm2835_read(int);
int /*<<< orphan*/ printk(char *, int);
int gpio_get_value(int which_one) {
  uint32_t address_offset, bit;
  uint32_t result;
  if (which_one > 54) {
    printk("GPIO%d too big\n", which_one);
    return -1;
  }
  bit = 1 << (which_one & 0x1f);
  address_offset = (which_one / 32) * 4;
  result = bcm2835_read(((0 + 0x200000) + 0x34) + address_offset);
  result = !!(result & bit);
  return result;
}


x86 assembly (clang, -O0):
<gpio_get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x36,-0x8(%rbp)
jle    1150 <gpio_get_value+0x30>
mov    -0x8(%rbp),%esi
lea    0xec1(%rip),%rdi
call   1030 <printk@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <gpio_get_value+0x80>
mov    -0x8(%rbp),%ecx
and    $0x1f,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x200034,%edi
call   1040 <bcm2835_read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_get_value>:
push   %rbx
mov    %edi,%ebx
cmp    $0x37,%edi
jl     113d <gpio_get_value+0x1d>
lea    0xed1(%rip),%rdi
mov    %ebx,%esi
call   1030 <printk@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0x1f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
sar    $0x5,%eax
lea    0x200034(,%rax,4),%edi
call   1040 <bcm2835_read@plt>
mov    %ebx,%ecx
shr    %cl,%eax
and    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"GPIO%d too big\0A\00"
define i32 @gpio_get_value(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 54
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 -1, i32* %2
br label %30
12: ; preds = %1
%13 = load i32, i32* %3
%14 = and i32 %13, 31
%15 = shl i32 1, %14
store i32 %15, i32* %5
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 32
%18 = mul nsw i32 %17, 4
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = add nsw i32 2097204, %19
%21 = call i32 @bcm2835_read(i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
%27 = xor i1 %26, true
%28 = zext i1 %27 to i32
store i32 %28, i32* %6
%29 = load i32, i32* %6
store i32 %29, i32* %2
br label %30
30: ; preds = %12, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [16 x i8] c"GPIO%d too big\0A\00"
define i32 @gpio_get_value(i32 %0) {
%2 = icmp sgt i32 %0, 54
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
5: ; preds = %1
%6 = and i32 %0, 31
%7 = sdiv i32 %0, 32
%8 = shl nsw i32 %7, 2
%9 = add nsw i32 %8, 2097204
%10 = tail call i32 @bcm2835_read(i32 %9)
%11 = lshr i32 %10, %6
%12 = and i32 %11, 1
br label %13
13: ; preds = %5, %3
%14 = phi i32 [ -1, %3 ], [ %12, %5 ]
ret i32 %14
}