#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write_header(int /*<<< orphan*/ *, int);
void write_proto_header(void) {
  int i;
  FILE *fp = fopen("z88dk/header.proto", "w");
  if (fp == NULL) {
    perror("z88dk/header.proto");
    exit(1);
  }
  for (i = 0; i < 99; i++)
    write_header(fp, i);
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_proto_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xead(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <write_proto_header+0x40>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x63,-0x4(%rbp)
jge    11bb <write_proto_header+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1070 <write_header@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <write_proto_header+0x47>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_proto_header>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1190 <write_proto_header+0x40>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <write_header@plt>
add    $0x1,%ebp
cmp    $0x63,%ebp
jne    1170 <write_proto_header+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe69(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"z88dk/header.proto\00"
@.str.1 = [2 x i8] c"w\00"
define void @write_proto_header() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
store i32 0, i32* %1
br label %10
10: ; preds = %17, %9
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 99
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = load i32, i32* %1
%16 = call i32 @write_header(i32* %14, i32 %15)
br label %17
17: ; preds = %13
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %10
20: ; preds = %10
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"z88dk/header.proto\00"
@.str.1 = [2 x i8] c"w\00"
define void @write_proto_header() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0, %6
%7 = phi i32 [ %9, %6 ], [ 0, %0 ]
%8 = tail call i32 @write_header(i32* %1, i32 %7)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %9, 99
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = tail call i32 @fclose(i32* %1)
ret void
}