#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, char *, int);
void write_gpio(int value, char *uiod, 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)) = 0;
  printf("The value %08x is going to write onto %s (channel %d)\n", value, uiod,
         channel);
  *((unsigned *)(virtual_address + gpio_data_off)) = value;
}


x86 assembly (clang, -O0):
<write_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1143 <write_gpio+0x33>
movl   $0x4,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    1151 <write_gpio+0x41>
movl   $0xc,-0x20(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_gpio>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %edi,%ebp
xor    %ebx,%ebx
cmp    $0x1,%ecx
setne  %bl
movl   $0x0,0x4(%r14,%rbx,8)
lea    0xecc(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,(%r14,%rbx,8)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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