#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main() {
  char buf[16];
  int fd = open("/proc/my_led1", O_RDONLY);
  while (1) {
    lseek(fd, 0L, SEEK_SET);
    read(fd, buf, 16);
    for (int i = 1; i < 9; i++) {
      printf("%c", buf[i]);
    }
    fflush(stdout);
    sleep(1);
    printf("\r");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <lseek@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <read@plt>
movl   $0x1,-0x28(%rbp)
cmpl   $0x9,-0x28(%rbp)
jge    11e3 <main+0x83>
movslq -0x28(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b4 <main+0x54>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1187 <main+0x27>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e4f(%rip),%r15
mov    %rsp,%r14
mov    0x2e3d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <read@plt>
movsbl 0x1(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x2(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x3(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x4(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x5(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x6(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x8(%rsp),%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0xd,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x40>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/my_led1\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@stdout = global i32 0
@.str.2 = [2 x i8] c"\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
br label %7
7: ; preds = %0, %27
%8 = load i32, i32* %3
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @lseek(i32 %8, i64 0, i32 %9)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 16)
store i32 1, i32* %4
br label %14
14: ; preds = %24, %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 9
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %14
27: ; preds = %14
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
%30 = call i32 @sleep(i32 1)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %7
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/my_led1\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 1
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 2
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 3
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 4
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 5
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 6
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 7
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 8
br label %13
13: ; preds = %13, %0
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @lseek(i32 %4, i64 0, i32 %14)
%16 = call i32 @read(i32 %4, i8* %2, i32 16)
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = tail call i32 @putchar(i32 %18)
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = tail call i32 @putchar(i32 %21)
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = tail call i32 @putchar(i32 %24)
%26 = load i8, i8* %8
%27 = sext i8 %26 to i32
%28 = tail call i32 @putchar(i32 %27)
%29 = load i8, i8* %9
%30 = sext i8 %29 to i32
%31 = tail call i32 @putchar(i32 %30)
%32 = load i8, i8* %10
%33 = sext i8 %32 to i32
%34 = tail call i32 @putchar(i32 %33)
%35 = load i8, i8* %11
%36 = sext i8 %35 to i32
%37 = tail call i32 @putchar(i32 %36)
%38 = load i8, i8* %12
%39 = sext i8 %38 to i32
%40 = tail call i32 @putchar(i32 %39)
%41 = load i32, i32* @stdout
%42 = tail call i32 @fflush(i32 %41)
%43 = tail call i32 @sleep(i32 1)
%44 = tail call i32 @putchar(i32 13)
br label %13
}