#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 led_ctl(int num) {
  int gpio_fd = 0;
  int led = 0x00;
  char *data = NULL;
  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):
<led_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe92(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
mov    %edx,-0x2c(%rbp)
mov    %edx,%esi
call   1050 <ioctl@plt>
mov    -0x2c(%rbp),%esi
mov    -0x8(%rbp),%edi
mov    $0x2,%edx
call   1050 <ioctl@plt>
mov    -0x2c(%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    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     1243 <led_ctl+0xf3>
mov    -0x28(%rbp),%rax
lea    0xe17(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
xor    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1248 <led_ctl+0xf8>
mov    -0xc(%rbp),%eax
xor    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    1248 <led_ctl+0xf8>
mov    -0xc(%rbp),%eax
xor    $0x8,%eax
mov    %eax,-0xc(%rbp)
jmp    1248 <led_ctl+0xf8>
mov    -0xc(%rbp),%eax
and    $0xe,%eax
cmp    $0xe,%eax
jne    1237 <led_ctl+0xe7>
movl   $0x1,-0xc(%rbp)
jmp    123e <led_ctl+0xee>
movl   $0xe,-0xc(%rbp)
jmp    1248 <led_ctl+0xf8>
jmp    1248 <led_ctl+0xf8>
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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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 <led_ctl+0xac>
lea    0xe3e(%rip),%rax
movslq (%rax,%r14,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xorb   $0x2,0x4(%rsp)
jmp    11fc <led_ctl+0xac>
xorb   $0x8,0x4(%rsp)
jmp    11fc <led_ctl+0xac>
mov    0x4(%rsp),%eax
not    %eax
test   $0xe,%al
jne    11f4 <led_ctl+0xa4>
movl   $0x1,0x4(%rsp)
jmp    11fc <led_ctl+0xac>
xorb   $0x4,0x4(%rsp)
jmp    11fc <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 @led_ctl(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i8* null, i8** %5
%7 = load i32, i32* %2
store i32 %7, i32* %6
%8 = call i32 @open_dev(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @ioctl(i32 %9, i32 1, i32 1)
%11 = load i32, i32* %3
%12 = call i32 @ioctl(i32 %11, i32 1, i32 2)
%13 = load i32, i32* %3
%14 = call i32 @ioctl(i32 %13, i32 1, i32 3)
%15 = load i32, i32* %3
%16 = call i32 @read(i32 %15, i32* %4, i32 4)
%17 = load i32, i32* %6
switch i32 %17, label %34 [
i32 1, label %18
i32 2, label %21
i32 3, label %24
i32 4, label %27
]
18: ; preds = %1
%19 = load i32, i32* %4
%20 = xor i32 %19, 2
store i32 %20, i32* %4
br label %35
21: ; preds = %1
%22 = load i32, i32* %4
%23 = xor i32 %22, 4
store i32 %23, i32* %4
br label %35
24: ; preds = %1
%25 = load i32, i32* %4
%26 = xor i32 %25, 8
store i32 %26, i32* %4
br label %35
27: ; preds = %1
%28 = load i32, i32* %4
%29 = and i32 %28, 14
%30 = icmp eq i32 %29, 14
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %4
br label %33
32: ; preds = %27
store i32 14, i32* %4
br label %33
33: ; preds = %32, %31
br label %35
34: ; preds = %1
br label %35
35: ; preds = %34, %33, %24, %21, %18
%36 = load i32, i32* %3
%37 = call i32 @write(i32 %36, i32* %4, i32 4)
%38 = load i32, i32* %3
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/gpH0\00"
define i32 @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
}