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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  puts("Vocore blink test program...");
  FILE *fp = fopen(
      "/sys/devices/gpio-leds.5/leds/vocore:green:status/brightness", "w");
  if (fp == NULL) {
    puts("Error opening status LED for writing.");
    return (0);
  }
  int i;
  for (i = 0; i < 25; i++) {
    if (i % 2) {
      fwrite("255", 1, 3, fp);
      printf("ON ");
    } else {
      fwrite("0", 1, 1, fp);
      printf("OFF ");
    }
    fflush(fp);
    fflush(stdout);
    sleep(1);
  }
  fclose(fp);
  puts("\nEnd of blink test program.");
}


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)
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
lea    0xe84(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cc <main+0x5c>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <main+0x114>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x19,-0x1c(%rbp)
jge    126f <main+0xff>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     121c <main+0xac>
mov    -0x18(%rbp),%rcx
lea    0xe86(%rip),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1080 <fwrite@plt>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
jmp    123f <main+0xcf>
mov    -0x18(%rbp),%rcx
lea    0xe63(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fflush@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%rdi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <main+0x63>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1249 <main+0xc9>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xecb(%rip),%r15
mov    0x2e1a(%rip),%r12
lea    0xeb5(%rip),%r14
lea    0xeb2(%rip),%r13
jmp    1218 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
mov    $0x30,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    (%r12),%rdi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
add    $0x1,%ebp
cmp    $0x19,%ebp
je     1238 <main+0xb8>
test   $0x1,%bpl
je     11e0 <main+0x60>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %r13,%rdi
jmp    11f0 <main+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe48(%rip),%rdi
jmp    1250 <main+0xd0>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Vocore blink test program...\00"
@.str.1 = [61 x i8] c"/sys/devices/gpio-leds.5/leds/vocore:green:status/brightness\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [38 x i8] c"Error opening status LED for writing.\00"
@.str.4 = [4 x i8] c"255\00"
@.str.5 = [4 x i8] c"ON \00"
@.str.6 = [2 x i8] c"0\00"
@.str.7 = [5 x i8] c"OFF \00"
@stdout = global i32* null
@.str.8 = [28 x i8] c"\0AEnd of blink test program.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = call i32* @fopen(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %43
14: ; preds = %2
store i32 0, i32* %7
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 25
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load i32, i32* %7
%20 = srem i32 %19, 2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32*, i32** %6
%24 = call i32 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 3, i32* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %30
26: ; preds = %18
%27 = load i32*, i32** %6
%28 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 1, i32* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %26, %22
%31 = load i32*, i32** %6
%32 = call i32 @fflush(i32* %31)
%33 = load i32*, i32** @stdout
%34 = call i32 @fflush(i32* %33)
%35 = call i32 @sleep(i32 1)
br label %36
36: ; preds = %30
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %15
39: ; preds = %15
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %39, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [29 x i8] c"Vocore blink test program...\00"
@.str.1 = [61 x i8] c"/sys/devices/gpio-leds.5/leds/vocore:green:status/brightness\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [38 x i8] c"Error opening status LED for writing.\00"
@.str.4 = [4 x i8] c"255\00"
@.str.5 = [4 x i8] c"ON \00"
@.str.7 = [5 x i8] c"OFF \00"
@stdout = global i32* null
@.str.8 = [28 x i8] c"\0AEnd of blink test program.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %25, label %6
6: ; preds = %2, %14
%7 = phi i32 [ %21, %14 ], [ 0, %2 ]
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 3, i32* %4)
br label %14
12: ; preds = %6
%13 = tail call i32 @fputc(i32 48, i32* %4)
br label %14
14: ; preds = %12, %10
%15 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %12 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %10 ]
%16 = tail call i32 @printf(i8* dereferenceable(1) %15)
%17 = tail call i32 @fflush(i32* %4)
%18 = load i32*, i32** @stdout
%19 = tail call i32 @fflush(i32* %18)
%20 = tail call i32 @sleep(i32 1)
%21 = add nuw nsw i32 %7, 1
%22 = icmp eq i32 %21, 25
br i1 %22, label %23, label %6
23: ; preds = %14
%24 = tail call i32 @fclose(i32* %4)
br label %25
25: ; preds = %2, %23
%26 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), %23 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), %2 ]
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
ret i32 0
}