#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*/ printf(char *, char);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int gpio_fd = 0;
  gpio_fd = open_dev("/dev/gpH0");
  ioctl(gpio_fd, 0x01, 0x0);
  ioctl(gpio_fd, 0x01, 0x1);
  ioctl(gpio_fd, 0x01, 0x2);
  ioctl(gpio_fd, 0x01, 0x3);
  ioctl(gpio_fd, 0x20, 0x0);
  ioctl(gpio_fd, 0x20, 0x1);
  ioctl(gpio_fd, 0x20, 0x2);
  ioctl(gpio_fd, 0x20, 0x3);
  ioctl(gpio_fd, 0x32, 0x0);
  ioctl(gpio_fd, 0x32, 0x1);
  ioctl(gpio_fd, 0x32, 0x2);
  ioctl(gpio_fd, 0x32, 0x3);
  ioctl(gpio_fd, 0x10, 0x0);
  ioctl(gpio_fd, 0x10, 0x1);
  ioctl(gpio_fd, 0x10, 0x2);
  ioctl(gpio_fd, 0x10, 0x3);
  char led = 0x02;
  while (1) {
    write(gpio_fd, &led, sizeof(led));
    printf("led=%#x\n", led);
    led = led << 1;
    if (led == (0x02 << 3)) {
      led = 0x02;
    }
    usleep(300000);
  }
  close(gpio_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe8c(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x20,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x20,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x20,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x32,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x10,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
movb   $0x2,-0x15(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xd61(%rip),%rdi
movsbl -0x15(%rbp),%esi
call   1050 <printf@plt>
movsbl -0x15(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x10,%eax
jne    12cd <main+0x17d>
movb   $0x2,-0x15(%rbp)
mov    $0x493e0,%edi
call   1070 <usleep@plt>
jmp    1291 <main+0x141>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    $0x2,%r12d
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x20,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x20,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x20,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x32,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x32,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x32,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x32,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x10,%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x10,%esi
mov    $0x1,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x10,%esi
mov    $0x2,%edx
call   1060 <ioctl@plt>
mov    %r14d,%edi
mov    $0x10,%esi
mov    $0x3,%edx
call   1060 <ioctl@plt>
movb   $0x2,0xf(%rsp)
mov    $0x2,%bl
lea    0xf(%rsp),%r15
lea    0xd73(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movsbl %bl,%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
add    %bl,%bl
cmp    $0x10,%bl
movzbl %bl,%ebx
cmove  %r12d,%ebx
mov    %bl,0xf(%rsp)
mov    $0x493e0,%edi
call   1070 <usleep@plt>
jmp    12a0 <main+0x150>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/gpH0\00"
@.str.1 = [9 x i8] c"led=%#x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, 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* %6
%9 = load i32, i32* %6
%10 = call i32 @ioctl(i32 %9, i32 1, i32 0)
%11 = load i32, i32* %6
%12 = call i32 @ioctl(i32 %11, i32 1, i32 1)
%13 = load i32, i32* %6
%14 = call i32 @ioctl(i32 %13, i32 1, i32 2)
%15 = load i32, i32* %6
%16 = call i32 @ioctl(i32 %15, i32 1, i32 3)
%17 = load i32, i32* %6
%18 = call i32 @ioctl(i32 %17, i32 32, i32 0)
%19 = load i32, i32* %6
%20 = call i32 @ioctl(i32 %19, i32 32, i32 1)
%21 = load i32, i32* %6
%22 = call i32 @ioctl(i32 %21, i32 32, i32 2)
%23 = load i32, i32* %6
%24 = call i32 @ioctl(i32 %23, i32 32, i32 3)
%25 = load i32, i32* %6
%26 = call i32 @ioctl(i32 %25, i32 50, i32 0)
%27 = load i32, i32* %6
%28 = call i32 @ioctl(i32 %27, i32 50, i32 1)
%29 = load i32, i32* %6
%30 = call i32 @ioctl(i32 %29, i32 50, i32 2)
%31 = load i32, i32* %6
%32 = call i32 @ioctl(i32 %31, i32 50, i32 3)
%33 = load i32, i32* %6
%34 = call i32 @ioctl(i32 %33, i32 16, i32 0)
%35 = load i32, i32* %6
%36 = call i32 @ioctl(i32 %35, i32 16, i32 1)
%37 = load i32, i32* %6
%38 = call i32 @ioctl(i32 %37, i32 16, i32 2)
%39 = load i32, i32* %6
%40 = call i32 @ioctl(i32 %39, i32 16, i32 3)
store i8 2, i8* %7
br label %41
41: ; preds = %2, %54
%42 = load i32, i32* %6
%43 = call i32 @write(i32 %42, i8* %7, i32 1)
%44 = load i8, i8* %7
%45 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %44)
%46 = load i8, i8* %7
%47 = sext i8 %46 to i32
%48 = shl i32 %47, 1
%49 = trunc i32 %48 to i8
store i8 %49, i8* %7
%50 = load i8, i8* %7
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 16
br i1 %52, label %53, label %54
53: ; preds = %41
store i8 2, i8* %7
br label %54
54: ; preds = %53, %41
%55 = call i32 @usleep(i32 300000)
br label %41
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/gpH0\00"
@.str.1 = [9 x i8] c"led=%#x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%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 0)
%6 = tail call i32 @ioctl(i32 %4, i32 1, i32 1)
%7 = tail call i32 @ioctl(i32 %4, i32 1, i32 2)
%8 = tail call i32 @ioctl(i32 %4, i32 1, i32 3)
%9 = tail call i32 @ioctl(i32 %4, i32 32, i32 0)
%10 = tail call i32 @ioctl(i32 %4, i32 32, i32 1)
%11 = tail call i32 @ioctl(i32 %4, i32 32, i32 2)
%12 = tail call i32 @ioctl(i32 %4, i32 32, i32 3)
%13 = tail call i32 @ioctl(i32 %4, i32 50, i32 0)
%14 = tail call i32 @ioctl(i32 %4, i32 50, i32 1)
%15 = tail call i32 @ioctl(i32 %4, i32 50, i32 2)
%16 = tail call i32 @ioctl(i32 %4, i32 50, i32 3)
%17 = tail call i32 @ioctl(i32 %4, i32 16, i32 0)
%18 = tail call i32 @ioctl(i32 %4, i32 16, i32 1)
%19 = tail call i32 @ioctl(i32 %4, i32 16, i32 2)
%20 = tail call i32 @ioctl(i32 %4, i32 16, i32 3)
store i8 2, i8* %3
br label %21
21: ; preds = %21, %2
%22 = phi i8 [ %27, %21 ], [ 2, %2 ]
%23 = call i32 @write(i32 %4, i8* %3, i32 1)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %22)
%25 = shl i8 %22, 1
%26 = icmp eq i8 %25, 16
%27 = select i1 %26, i8 2, i8 %25
store i8 %27, i8* %3
%28 = tail call i32 @usleep(i32 300000)
br label %21
}