#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 O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, unsigned int *, int);
int /*<<< orphan*/ write(int, unsigned int *, int);
int gpio_init(unsigned char gpio) {
  int fd;
  unsigned int reg_val[2];
  fd = open("/dev/regopt", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd < 0) {
    printf("can't open!\n");
    return -1;
  }
  reg_val[0] = 0X10000600;
  read(fd, reg_val, 8);
  reg_val[1] |= 1 << gpio;
  write(fd, reg_val, 8);
  reg_val[0] = 0X10000620;
  read(fd, reg_val, 8);
  reg_val[1] |= 1 << gpio;
  write(fd, reg_val, 8);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11aa <gpio_init+0x5a>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <gpio_init+0xdd>
movl   $0x10000600,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movzbl -0x5(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
movl   $0x10000620,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movzbl -0x5(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e8a(%rip),%rax
mov    0x2e73(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %edi,%r15d
mov    0x2e5d(%rip),%rax
or     (%rax),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11f1 <gpio_init+0xa1>
mov    %eax,%ebx
movl   $0x10000600,(%rsp)
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    $0x1,%ebp
mov    %r15d,%ecx
shl    %cl,%ebp
or     %ebp,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
movl   $0x10000620,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
or     %ebp,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1202 <gpio_init+0xb2>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/regopt\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [13 x i8] c"can't open!\0A\00"
define i32 @gpio_init(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca [2 x i32]
store i8 %0, i8* %3
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_NDELAY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
16: ; preds = %1
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
store i32 268436992, i32* %17
%18 = load i32, i32* %4
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%20 = call i32 @read(i32 %18, i32* %19, i32 8)
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = shl i32 1, %22
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* %4
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%29 = call i32 @write(i32 %27, i32* %28, i32 8)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
store i32 268437024, i32* %30
%31 = load i32, i32* %4
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%33 = call i32 @read(i32 %31, i32* %32, i32 8)
%34 = load i8, i8* %3
%35 = zext i8 %34 to i32
%36 = shl i32 1, %35
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%38 = load i32, i32* %37
%39 = or i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* %4
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%42 = call i32 @write(i32 %40, i32* %41, i32 8)
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
store i32 0, i32* %2
br label %45
45: ; preds = %16, %14
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/regopt\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@str = [12 x i8] c"can't open!\00"
define i32 @gpio_init(i8 zeroext %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %5, %4
%7 = load i32, i32* @O_NDELAY
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %27
13: ; preds = %1
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 268436992, i32* %14
%15 = call i32 @read(i32 %9, i32* %14, i32 8)
%16 = zext i8 %0 to i32
%17 = shl nuw i32 1, %16
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
%21 = call i32 @write(i32 %9, i32* %14, i32 8)
store i32 268437024, i32* %14
%22 = call i32 @read(i32 %9, i32* %14, i32 8)
%23 = load i32, i32* %18
%24 = or i32 %23, %17
store i32 %24, i32* %18
%25 = call i32 @write(i32 %9, i32* %14, i32 8)
%26 = tail call i32 @close(i32 %9)
br label %27
27: ; preds = %13, %11
%28 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %28
}