#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int open_dev(char *);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ write(int, int *, int);
int key_led_ctl(int num) {
  int gpio_fd = 0;
  int led = 0x00;
  int lednum = num;
  gpio_fd = open_dev("/dev/gpH0");
  ioctl(gpio_fd, 0x01, 0x1);
  ioctl(gpio_fd, 0x01, 0x2);
  ioctl(gpio_fd, 0x01, 0x3);
  read(gpio_fd, &led, sizeof(led));
  switch (lednum) {
  case 1:
    led ^= 0x02;
    break;
  case 2:
    led ^= 0x04;
    break;
  case 3:
    led ^= 0x08;
    break;
  case 4:
    if ((led & 0x0e) == 0x0e) {
      led = 0x01;
    } else {
      led = 0x0e;
    }
    break;
  default:
    break;
  }
  write(gpio_fd, &led, sizeof(led));
  close(gpio_fd);
  return 0;
}


x86 assembly (clang, -O0):
<key_led_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    %edx,%esi
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%edi
mov    $0x2,%edx
call   1050 <ioctl@plt>
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%edi
mov    $0x3,%edx
call   1050 <ioctl@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     123b <key_led_ctl+0xeb>
mov    -0x18(%rbp),%rax
lea    0xe1f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
xor    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1240 <key_led_ctl+0xf0>
mov    -0xc(%rbp),%eax
xor    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1240 <key_led_ctl+0xf0>
mov    -0xc(%rbp),%eax
xor    $0x8,%eax
mov    %eax,-0xc(%rbp)
jmp    1240 <key_led_ctl+0xf0>
mov    -0xc(%rbp),%eax
and    $0xe,%eax
cmp    $0xe,%eax
jne    122f <key_led_ctl+0xdf>
movl   $0x1,-0xc(%rbp)
jmp    1236 <key_led_ctl+0xe6>
movl   $0xe,-0xc(%rbp)
jmp    1240 <key_led_ctl+0xf0>
jmp    1240 <key_led_ctl+0xf0>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_led_ctl>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
movl   $0x0,0x4(%rsp)
lea    0xeaa(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <ioctl@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
add    $0xffffffff,%r14d
cmp    $0x3,%r14d
ja     11fc <key_led_ctl+0xac>
lea    0xe3e(%rip),%rax
movslq (%rax,%r14,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xorb   $0x2,0x4(%rsp)
jmp    11fc <key_led_ctl+0xac>
xorb   $0x8,0x4(%rsp)
jmp    11fc <key_led_ctl+0xac>
mov    0x4(%rsp),%eax
not    %eax
test   $0xe,%al
jne    11f4 <key_led_ctl+0xa4>
movl   $0x1,0x4(%rsp)
jmp    11fc <key_led_ctl+0xac>
xorb   $0x4,0x4(%rsp)
jmp    11fc <key_led_ctl+0xac>
movl   $0xe,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/gpH0\00"
define i32 @key_led_ctl(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* %2
store i32 %6, i32* %5
%7 = call i32 @open_dev(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @ioctl(i32 %8, i32 1, i32 1)
%10 = load i32, i32* %3
%11 = call i32 @ioctl(i32 %10, i32 1, i32 2)
%12 = load i32, i32* %3
%13 = call i32 @ioctl(i32 %12, i32 1, i32 3)
%14 = load i32, i32* %3
%15 = call i32 @read(i32 %14, i32* %4, i32 4)
%16 = load i32, i32* %5
switch i32 %16, label %33 [
i32 1, label %17
i32 2, label %20
i32 3, label %23
i32 4, label %26
]
17: ; preds = %1
%18 = load i32, i32* %4
%19 = xor i32 %18, 2
store i32 %19, i32* %4
br label %34
20: ; preds = %1
%21 = load i32, i32* %4
%22 = xor i32 %21, 4
store i32 %22, i32* %4
br label %34
23: ; preds = %1
%24 = load i32, i32* %4
%25 = xor i32 %24, 8
store i32 %25, i32* %4
br label %34
26: ; preds = %1
%27 = load i32, i32* %4
%28 = and i32 %27, 14
%29 = icmp eq i32 %28, 14
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 1, i32* %4
br label %32
31: ; preds = %26
store i32 14, i32* %4
br label %32
32: ; preds = %31, %30
br label %34
33: ; preds = %1
br label %34
34: ; preds = %33, %32, %23, %20, %17
%35 = load i32, i32* %3
%36 = call i32 @write(i32 %35, i32* %4, i32 4)
%37 = load i32, i32* %3
%38 = call i32 @close(i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/gpH0\00"
define i32 @key_led_ctl(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i32 @open_dev(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @ioctl(i32 %4, i32 1, i32 1)
%6 = tail call i32 @ioctl(i32 %4, i32 1, i32 2)
%7 = tail call i32 @ioctl(i32 %4, i32 1, i32 3)
%8 = call i32 @read(i32 %4, i32* %2, i32 4)
switch i32 %0, label %24 [
i32 1, label %9
i32 2, label %12
i32 3, label %15
i32 4, label %18
]
9: ; preds = %1
%10 = load i32, i32* %2
%11 = xor i32 %10, 2
store i32 %11, i32* %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %2
%14 = xor i32 %13, 4
store i32 %14, i32* %2
br label %24
15: ; preds = %1
%16 = load i32, i32* %2
%17 = xor i32 %16, 8
store i32 %17, i32* %2
br label %24
18: ; preds = %1
%19 = load i32, i32* %2
%20 = and i32 %19, 14
%21 = icmp eq i32 %20, 14
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %2
br label %24
23: ; preds = %18
store i32 14, i32* %2
br label %24
24: ; preds = %1, %22, %23, %15, %12, %9
%25 = call i32 @write(i32 %4, i32* %2, i32 4)
%26 = tail call i32 @close(i32 %4)
ret i32 0
}