#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 /*<<< orphan*/ led;

/* Variables and functions */
int atoi(char *);
int open_dev(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int led_init() {
  int led = 0x00;
  int led1 = 0;
  int led2 = 0;
  int led3 = 0;
  char init[50] = "";
  int gpio_fd = open_dev("/dev/gpH0");
  read(gpio_fd, &led, sizeof(led));
  switch (led & 0x0e) {
  case 0x0e:
    led1 = 1;
    led2 = 1;
    led3 = 1;
    break;
  case 0x0c:
    led1 = 0;
    led2 = 1;
    led3 = 1;
    break;
  case 0x0a:
    led1 = 1;
    led2 = 0;
    led3 = 1;
    break;
  case 0x08:
    led1 = 0;
    led2 = 0;
    led3 = 1;
    break;
  case 0x06:
    led1 = 1;
    led2 = 1;
    led3 = 0;
    break;
  case 0x04:
    led1 = 0;
    led2 = 1;
    led3 = 0;
    break;
  case 0x02:
    led1 = 1;
    led2 = 0;
    led3 = 0;
    break;
  case 0x00:
    led1 = 0;
    led2 = 0;
    led3 = 0;
    break;
  default:
    break;
  }
  sprintf(init, "%d%d%d", led1, led2, led3);
  printf("%s", init);
  return atoi(init);
}


x86 assembly (clang, -O0):
<led_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movaps %xmm0,-0x50(%rbp)
movw   $0x0,-0x20(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <open_dev@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    -0x4(%rbp),%eax
and    $0xe,%eax
mov    %rax,-0x60(%rbp)
sub    $0xe,%eax
ja     12a0 <led_init+0x150>
mov    -0x60(%rbp),%rax
lea    0xe39(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    12a5 <led_init+0x155>
jmp    12a5 <led_init+0x155>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xd8c(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rsi
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1060 <atoi@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<led_init>:
push   %rbx
sub    $0x50,%rsp
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe83(%rip),%rdi
call   1030 <open_dev@plt>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
mov    0xc(%rsp),%eax
and    $0xe,%eax
lea    0xe73(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
lea    0xea5(%rip),%rdx
mov    (%rdx,%rax,4),%r8d
lea    0xed6(%rip),%rdx
mov    (%rdx,%rax,4),%edx
lea    0xe4a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe3d(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/gpH0\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @led_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = bitcast [50 x i8]* %5 to i8*
%8 = call i32 @open_dev(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = call i32 @read(i32 %9, i32* %1, i32 4)
%11 = load i32, i32* %1
%12 = and i32 %11, 14
switch i32 %12, label %21 [
i32 14, label %13
i32 12, label %14
i32 10, label %15
i32 8, label %16
i32 6, label %17
i32 4, label %18
i32 2, label %19
i32 0, label %20
]
13: ; preds = %0
store i32 1, i32* %2
store i32 1, i32* %3
store i32 1, i32* %4
br label %22
14: ; preds = %0
store i32 0, i32* %2
store i32 1, i32* %3
store i32 1, i32* %4
br label %22
15: ; preds = %0
store i32 1, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %22
16: ; preds = %0
store i32 0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %22
17: ; preds = %0
store i32 1, i32* %2
store i32 1, i32* %3
store i32 0, i32* %4
br label %22
18: ; preds = %0
store i32 0, i32* %2
store i32 1, i32* %3
store i32 0, i32* %4
br label %22
19: ; preds = %0
store i32 1, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %22
20: ; preds = %0
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %22
21: ; preds = %0
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14, %13
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%31 = call i32 @atoi(i8* %30)
ret i32 %31
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/gpH0\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
@.str.2 = [3 x i8] c"%s\00"
@switch.table.led_init = [15 x i32] [i32 0, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 0, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1]
@switch.table.led_init.3 = [15 x i32] [i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1]
@switch.table.led_init.4 = [15 x i32] [i32 0, i32 1, i32 1, i32 1, i32 0, i32 1, i32 1, i32 1, i32 0, i32 1, i32 1, i32 1, i32 0, i32 1, i32 1]
define i32 @led_init() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @open_dev(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @read(i32 %5, i32* %1, i32 4)
%7 = load i32, i32* %1
%8 = and i32 %7, 14
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [15 x i32], [15 x i32]* @switch.table.led_init, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = zext i32 %8 to i64
%13 = getelementptr inbounds [15 x i32], [15 x i32]* @switch.table.led_init.3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = zext i32 %8 to i64
%16 = getelementptr inbounds [15 x i32], [15 x i32]* @switch.table.led_init.4, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %11, i32 %14)
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = call i32 @atoi(i8* %4)
ret i32 %20
}