#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
double sqrt(int);
int main(int argc, char *argv[]) {
  int i;
  double result;
  if (argc < 2) {
    return 1;
  }
  FILE *fout = fopen(argv[1], "w");
  if (!fout) {
    return 1;
  }
  fprintf(fout, "double sqrtTable[] = {\n");
  for (i = 0; i < 10; i++) {
    result = sqrt(i);
    fprintf(fout, "%g, \n", result);
  }
  fprintf(fout, "0}; \n");
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1212 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119b <main+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1212 <main+0xd2>
mov    -0x28(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11f0 <main+0xb0>
mov    -0x14(%rbp),%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe3f(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <main+0x74>
mov    -0x28(%rbp),%rdi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebp
cmp    $0x2,%edi
jl     12a4 <main+0x154>
mov    0x8(%rsi),%rdi
lea    0xe93(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     12a4 <main+0x154>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
xor    %ebp,%ebp
xor    %edi,%edi
call   1060 <sqrt@plt>
lea    0xe73(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x4,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x6,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x7,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x8,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x9,%edi
call   1060 <sqrt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
lea    0xd96(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"double sqrtTable[] = {\0A\00"
@.str.2 = [6 x i8] c"%g, \0A\00"
@.str.3 = [6 x i8] c"0}; \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %40
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %12
store i32 1, i32* %3
br label %40
20: ; preds = %12
%21 = load i32*, i32** %8
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %23
23: ; preds = %32, %20
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call double @sqrt(i32 %27)
store double %28, double* %7
%29 = load i32*, i32** %8
%30 = load double, double* %7
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %23
35: ; preds = %23
%36 = load i32*, i32** %8
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %35, %19, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"double sqrtTable[] = {\0A\00"
@.str.2 = [6 x i8] c"%g, \0A\00"
@.str.3 = [6 x i8] c"0}; \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %33, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %4
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 23, i64 1, i32* %7)
%11 = tail call double @sqrt(i32 0)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %11)
%13 = tail call double @sqrt(i32 1)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = tail call double @sqrt(i32 2)
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %15)
%17 = tail call double @sqrt(i32 3)
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = tail call double @sqrt(i32 4)
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = tail call double @sqrt(i32 5)
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %21)
%23 = tail call double @sqrt(i32 6)
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = tail call double @sqrt(i32 7)
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = tail call double @sqrt(i32 8)
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %27)
%29 = tail call double @sqrt(i32 9)
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 5, i64 1, i32* %7)
%32 = tail call i32 @fclose(i32* %7)
br label %33
33: ; preds = %9, %4, %2
%34 = phi i32 [ 1, %2 ], [ 0, %9 ], [ 1, %4 ]
ret i32 %34
}