#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  int set = 0;
  while (set < 10) {
    if ((fp = fopen("/dev/myled0", "w")) == NULL) {
      printf("miss!\n");
      exit(EXIT_FAILURE);
    }
    fprintf(fp, "1\n");
    printf("%d\n", ++set);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11e2 <main+0x92>
lea    0xe89(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ad <main+0x5d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1166 <main+0x16>
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
mov    $0x1,%ebx
lea    0xe89(%rip),%r14
lea    0xe8e(%rip),%r15
lea    0xe89(%rip),%r12
lea    0xe85(%rip),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e5 <main+0x85>
mov    %rax,%rbp
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebx
cmp    $0xb,%ebx
jne    1190 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/myled0\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"miss!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"1\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
%15 = load i32*, i32** %2
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
br label %4
22: ; preds = %4
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/myled0\00"
@.str.1 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"1\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [6 x i8] c"miss!\00"
define i32 @main() {
br label %1
1: ; preds = %0, %9
%2 = phi i32 [ 0, %0 ], [ %11, %9 ]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %3)
%11 = add nuw nsw i32 %2, 1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fclose(i32* %3)
%14 = icmp eq i32 %11, 10
br i1 %14, label %15, label %1
15: ; preds = %9
ret i32 0
}