#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 /*<<< orphan*/ bcm2835_write(int, int);
int /*<<< orphan*/ printk(char *, int);
int gpio_set_value(int which_one, int value) {
  uint32_t address_offset, bit;
  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;
  if (value == 0) {
    bcm2835_write(((0 + 0x200000) + 0x28) + address_offset, bit);
  } else if (value == 1) {
    bcm2835_write(((0 + 0x200000) + 0x1c) + address_offset, bit);
  } else {
    printk("Invalid GPIO value %d\n", value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<gpio_set_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x36,-0x8(%rbp)
jle    1153 <gpio_set_value+0x33>
mov    -0x8(%rbp),%esi
lea    0xebe(%rip),%rdi
call   1030 <printk@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <gpio_set_value+0xaf>
mov    -0x8(%rbp),%ecx
and    $0x1f,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
shl    $0x2,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1194 <gpio_set_value+0x74>
mov    -0x10(%rbp),%edi
add    $0x200028,%edi
mov    -0x14(%rbp),%esi
call   1040 <bcm2835_write@plt>
jmp    11c8 <gpio_set_value+0xa8>
cmpl   $0x1,-0xc(%rbp)
jne    11b4 <gpio_set_value+0x94>
mov    -0x10(%rbp),%edi
add    $0x20001c,%edi
mov    -0x14(%rbp),%esi
call   1040 <bcm2835_write@plt>
jmp    11c3 <gpio_set_value+0xa3>
mov    -0xc(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1030 <printk@plt>
jmp    11c8 <gpio_set_value+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_set_value>:
push   %rax
mov    %edi,%ecx
cmp    $0x37,%edi
jl     113d <gpio_set_value+0x1d>
lea    0xed1(%rip),%rdi
mov    %ecx,%esi
call   1030 <printk@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    $0x1,%eax
shl    %cl,%eax
lea    0x1f(%rcx),%edi
test   %ecx,%ecx
cmovns %ecx,%edi
sar    $0x5,%edi
shl    $0x2,%edi
cmp    $0x1,%esi
je     1163 <gpio_set_value+0x43>
test   %esi,%esi
jne    1172 <gpio_set_value+0x52>
add    $0x200028,%edi
jmp    1169 <gpio_set_value+0x49>
add    $0x20001c,%edi
mov    %eax,%esi
call   1040 <bcm2835_write@plt>
jmp    117e <gpio_set_value+0x5e>
lea    0xe97(%rip),%rdi
call   1030 <printk@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"GPIO%d too big\0A\00"
@.str.1 = [23 x i8] c"Invalid GPIO value %d\0A\00"
define i32 @gpio_set_value(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 54
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %4
%12 = call i32 @printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %3
br label %40
13: ; preds = %2
%14 = load i32, i32* %4
%15 = and i32 %14, 31
%16 = shl i32 1, %15
store i32 %16, i32* %7
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 32
%19 = mul nsw i32 %18, 4
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i32, i32* %6
%24 = add nsw i32 2097192, %23
%25 = load i32, i32* %7
%26 = call i32 @bcm2835_write(i32 %24, i32 %25)
br label %39
27: ; preds = %13
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %6
%32 = add nsw i32 2097180, %31
%33 = load i32, i32* %7
%34 = call i32 @bcm2835_write(i32 %32, i32 %33)
br label %38
35: ; preds = %27
%36 = load i32, i32* %5
%37 = call i32 @printk(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %30
br label %39
39: ; preds = %38, %22
store i32 0, i32* %3
br label %40
40: ; preds = %39, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [16 x i8] c"GPIO%d too big\0A\00"
@.str.1 = [23 x i8] c"Invalid GPIO value %d\0A\00"
define i32 @gpio_set_value(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 54
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %19
6: ; preds = %2
%7 = and i32 %0, 31
%8 = shl nuw i32 1, %7
%9 = sdiv i32 %0, 32
%10 = shl nsw i32 %9, 2
switch i32 %1, label %17 [
i32 0, label %11
i32 1, label %14
]
11: ; preds = %6
%12 = add nsw i32 %10, 2097192
%13 = tail call i32 @bcm2835_write(i32 %12, i32 %8)
br label %19
14: ; preds = %6
%15 = add nsw i32 %10, 2097180
%16 = tail call i32 @bcm2835_write(i32 %15, i32 %8)
br label %19
17: ; preds = %6
%18 = tail call i32 @printk(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %19
19: ; preds = %11, %17, %14, %4
%20 = phi i32 [ -1, %4 ], [ 0, %14 ], [ 0, %17 ], [ 0, %11 ]
ret i32 %20
}