#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*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main() {
  double value;
  int fd;
  fd = creat("input.bin", 0666);
  if (fd < 0) {
    fprintf(stderr, "Can't open file for writing.  Aborting\n");
    exit(-1);
  }
  for (value = 0.0; value <= 100.0; value += 0.5) {
    int n_written = write(fd, (char *)&value, sizeof(double));
    if (n_written != sizeof(double)) {
      fprintf(stderr, "Error writing file.  Aborting.\n");
      close(fd);
      exit(-1);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119c <main+0x4c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe54(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     121c <main+0xcc>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x8,%rax
je     1200 <main+0xb0>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1205 <main+0xb5>
movsd  0xdfb(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11a4 <main+0x54>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
test   %eax,%eax
js     1203 <main+0xb3>
mov    %eax,%ebx
movq   $0x0,0x8(%rsp)
xorpd  %xmm0,%xmm0
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x8,%eax
jne    11dd <main+0x8d>
movsd  0x10(%rsp),%xmm0
addsd  0xe48(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe42(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1190 <main+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"input.bin\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Can't open file for writing. Aborting\0A\00"
@.str.2 = [32 x i8] c"Error writing file. Aborting.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 438)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
store double 0.000000e+00, double* %2
br label %13
13: ; preds = %30, %12
%14 = load double, double* %2
%15 = fcmp ole double %14, 1.000000e+02
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i32, i32* %3
%18 = bitcast double* %2 to i8*
%19 = call i32 @write(i32 %17, i8* %18, i32 8)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = icmp ne i64 %21, 8
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %16
br label %30
30: ; preds = %29
%31 = load double, double* %2
%32 = fadd double %31, 5.000000e-01
store double %32, double* %2
br label %13
33: ; preds = %13
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.bin\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Can't open file for writing. Aborting\0A\00"
@.str.2 = [32 x i8] c"Error writing file. Aborting.\0A\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 438)
%4 = icmp slt i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %0
store double 0.000000e+00, double* %1
br label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %5, %19
%11 = phi double [ 0.000000e+00, %5 ], [ %20, %19 ]
%12 = call i32 @write(i32 %3, i8* %2, i32 8)
%13 = icmp eq i32 %12, 8
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @close(i32 %3)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = fadd double %11, 5.000000e-01
store double %20, double* %1
%21 = fcmp ugt double %20, 1.000000e+02
br i1 %21, label %22, label %10
22: ; preds = %19
%23 = tail call i32 @close(i32 %3)
ret i32 0
}