#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 */
long _load_32(int);
int /*<<< orphan*/ _store_32(int, long);
unsigned char _gpio_detect(unsigned char gpio_number) {
  long int value;
  if (gpio_number >= 32) {
    gpio_number -= 32;
    value = _load_32(0x3F200000 | 0x44);
    if (value & 1 << gpio_number) {
      value = 1 << gpio_number;
      _store_32(0x3F200000 | 0x44, value);
      return ((unsigned char)1);
    } else {
      return ((unsigned char)0);
    }
  } else {
    value = _load_32(0x3F200000 | 0x40);
    if (value & 1 << gpio_number) {
      value = 1 << gpio_number;
      _store_32(0x3F200000 | 0x40, value);
      return ((unsigned char)1);
    } else {
      return ((unsigned char)0);
    }
  }
}


x86 assembly (clang, -O0):
<_gpio_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x20,%eax
jl     11a5 <_gpio_detect+0x85>
movzbl -0x2(%rbp),%eax
sub    $0x20,%eax
mov    %al,-0x2(%rbp)
mov    $0x3f200044,%edi
call   1040 <_load_32@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl -0x2(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     119c <_gpio_detect+0x7c>
movzbl -0x2(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x3f200044,%edi
call   1030 <_store_32@plt>
movb   $0x1,-0x1(%rbp)
jmp    1200 <_gpio_detect+0xe0>
movb   $0x0,-0x1(%rbp)
jmp    1200 <_gpio_detect+0xe0>
mov    $0x3f200040,%edi
call   1040 <_load_32@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl -0x2(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11fc <_gpio_detect+0xdc>
movzbl -0x2(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x3f200040,%edi
call   1030 <_store_32@plt>
movb   $0x1,-0x1(%rbp)
jmp    1200 <_gpio_detect+0xe0>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gpio_detect>:
push   %rbx
mov    %edi,%ebx
cmp    $0x20,%bl
jb     114a <_gpio_detect+0x2a>
mov    $0x3f200044,%edi
call   1040 <_load_32@plt>
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%edx
movslq %edx,%rsi
test   %rsi,%rax
je     1173 <_gpio_detect+0x53>
mov    $0x3f200044,%edi
jmp    116a <_gpio_detect+0x4a>
mov    $0x3f200040,%edi
call   1040 <_load_32@plt>
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%edx
movslq %edx,%rsi
test   %rsi,%rax
je     1173 <_gpio_detect+0x53>
mov    $0x3f200040,%edi
call   1030 <_store_32@plt>
mov    $0x1,%al
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @_gpio_detect(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i64
store i8 %0, i8* %3
%5 = load i8, i8* %3
%6 = zext i8 %5 to i32
%7 = icmp sge i32 %6, 32
br i1 %7, label %8, label %29
8: ; preds = %1
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = sub nsw i32 %10, 32
%12 = trunc i32 %11 to i8
store i8 %12, i8* %3
%13 = call i64 @_load_32(i32 1059061828)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = shl i32 1, %16
%18 = sext i32 %17 to i64
%19 = and i64 %14, %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %8
%22 = load i8, i8* %3
%23 = zext i8 %22 to i32
%24 = shl i32 1, %23
%25 = sext i32 %24 to i64
store i64 %25, i64* %4
%26 = load i64, i64* %4
%27 = call i32 @_store_32(i32 1059061828, i64 %26)
store i8 1, i8* %2
br label %46
28: ; preds = %8
store i8 0, i8* %2
br label %46
29: ; preds = %1
%30 = call i64 @_load_32(i32 1059061824)
store i64 %30, i64* %4
%31 = load i64, i64* %4
%32 = load i8, i8* %3
%33 = zext i8 %32 to i32
%34 = shl i32 1, %33
%35 = sext i32 %34 to i64
%36 = and i64 %31, %35
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %29
%39 = load i8, i8* %3
%40 = zext i8 %39 to i32
%41 = shl i32 1, %40
%42 = sext i32 %41 to i64
store i64 %42, i64* %4
%43 = load i64, i64* %4
%44 = call i32 @_store_32(i32 1059061824, i64 %43)
store i8 1, i8* %2
br label %46
45: ; preds = %29
store i8 0, i8* %2
br label %46
46: ; preds = %45, %38, %28, %21
%47 = load i8, i8* %2
ret i8 %47
}

LLVM IR (-O2):
define zeroext i8 @_gpio_detect(i8 zeroext %0) {
%2 = icmp ugt i8 %0, 31
br i1 %2, label %3, label %13
3: ; preds = %1
%4 = add i8 %0, -32
%5 = tail call i64 @_load_32(i32 1059061828)
%6 = zext i8 %4 to i32
%7 = shl nuw i32 1, %6
%8 = sext i32 %7 to i64
%9 = and i64 %5, %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %3
%12 = tail call i32 @_store_32(i32 1059061828, i64 %8)
br label %22
13: ; preds = %1
%14 = zext i8 %0 to i32
%15 = tail call i64 @_load_32(i32 1059061824)
%16 = shl nuw i32 1, %14
%17 = sext i32 %16 to i64
%18 = and i64 %15, %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = tail call i32 @_store_32(i32 1059061824, i64 %17)
br label %22
22: ; preds = %13, %3, %20, %11
%23 = phi i8 [ 1, %11 ], [ 1, %20 ], [ 0, %3 ], [ 0, %13 ]
ret i8 %23
}