#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*/ printf(char *, int, int);
void read_gpio(int *value, void *virtual_address, int channel) {
  int gpio_tri_off;
  int gpio_data_off;
  if (channel == 1) {
    gpio_tri_off = 0x04;
    gpio_data_off = 0x00;
  } else {
    gpio_tri_off = 0x0C;
    gpio_data_off = 0x08;
  }
  *((unsigned *)(virtual_address + gpio_tri_off)) = 255;
  *value = *((unsigned *)(virtual_address + gpio_data_off));
  printf("The value on channel %d GPIO input is: %08x\n", channel, *value);
}


x86 assembly (clang, -O0):
<read_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1140 <read_gpio+0x30>
movl   $0x4,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    114e <read_gpio+0x3e>
movl   $0xc,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movl   $0xff,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_gpio>:
xor    %eax,%eax
cmp    $0x1,%edx
setne  %al
movl   $0xff,0x4(%rsi,%rax,8)
mov    (%rsi,%rax,8),%eax
mov    %eax,(%rdi)
lea    0xed4(%rip),%rdi
mov    %edx,%esi
mov    %eax,%edx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"The value on channel %d GPIO input is: %08x\0A\00"
define void @read_gpio(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 4, i32* %7
store i32 0, i32* %8
br label %13
12: ; preds = %3
store i32 12, i32* %7
store i32 8, i32* %8
br label %13
13: ; preds = %12, %11
%14 = load i8*, i8** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr i8, i8* %14, i64 %16
%18 = bitcast i8* %17 to i32*
store i32 255, i32* %18
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr i8, i8* %19, i64 %21
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
%25 = load i32*, i32** %4
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"The value on channel %d GPIO input is: %08x\0A\00"
define void @read_gpio(i32* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 1
%5 = select i1 %4, i64 4, i64 12
%6 = select i1 %4, i64 0, i64 8
%7 = getelementptr i8, i8* %1, i64 %5
%8 = bitcast i8* %7 to i32*
store i32 255, i32* %8
%9 = getelementptr i8, i8* %1, i64 %6
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
store i32 %11, i32* %0
%12 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %11)
ret void
}