#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int ofd;
  int i;
  char c;
  ofd = open("count.bin", O_WRONLY | O_CREAT);
  c = 0;
  for (i = 0; i < 16384; i++) {
    write(ofd, &c, 1);
    c++;
  }
  close(ofd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2ea9(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4000,-0xc(%rbp)
jge    119f <main+0x6f>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <main+0x3b>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    0x2eb2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
movb   $0x0,0xf(%rsp)
mov    $0xffffc000,%ebx
lea    0xf(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0x1(%rbx),%eax
mov    %al,0xf(%rsp)
inc    %ebx
jne    1170 <main+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"count.bin\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
store i8 0, i8* %4
store i32 0, i32* %3
br label %9
9: ; preds = %17, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 16384
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 @write(i32 %13, i8* %4, i32 1)
%15 = load i8, i8* %4
%16 = add i8 %15, 1
store i8 %16, i8* %4
br label %17
17: ; preds = %12
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %9
20: ; preds = %9
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [10 x i8] c"count.bin\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i8 0, i8* %1
br label %6
6: ; preds = %0, %6
%7 = phi i8 [ 0, %0 ], [ %10, %6 ]
%8 = phi i32 [ 0, %0 ], [ %11, %6 ]
%9 = call i32 @write(i32 %5, i8* %1, i32 1)
%10 = add i8 %7, 1
store i8 %10, i8* %1
%11 = add nuw nsw i32 %8, 1
%12 = icmp eq i32 %11, 16384
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = tail call i32 @close(i32 %5)
ret i32 0
}