#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
void write_solution(int n, double *u, const char *fname) {
  int i;
  double h = 1.0 / n;
  FILE *fp = fopen(fname, "w+");
  for (i = 0; i <= n; ++i)
    fprintf(fp, "%g %g\n", i * h, u[i]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_solution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xeb0(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11b9 <write_solution+0x89>
mov    -0x30(%rbp),%rdi
cvtsi2sdl -0x1c(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe65(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1174 <write_solution+0x44>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_solution>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xebe(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r13
test   %r15d,%r15d
js     11ab <write_solution+0x7b>
cvtsi2sd %r15d,%xmm0
movsd  0xe99(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x1,%r15d
xor    %ebx,%ebx
lea    0xe8d(%rip),%r12
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edx
movsd  (%r14,%rbx,8),%xmm0
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <write_solution+0x50>
mov    %r13,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [7 x i8] c"%g %g\0A\00"
define void @write_solution(i32 %0, double* %1, i8* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32*
store i32 %0, i32* %4
store double* %1, double** %5
store i8* %2, i8** %6
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fdiv double 1.000000e+00, %11
store double %12, double* %8
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
store i32 0, i32* %7
br label %15
15: ; preds = %32, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = load i32*, i32** %9
%21 = load i32, i32* %7
%22 = sitofp i32 %21 to double
%23 = load double, double* %8
%24 = fmul double %22, %23
%25 = fptosi double %24 to i32
%26 = load double*, double** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %25, double %30)
br label %32
32: ; preds = %19
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %15
35: ; preds = %15
%36 = load i32*, i32** %9
%37 = call i32 @fclose(i32* %36)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [7 x i8] c"%g %g\0A\00"
define void @write_solution(i32 %0, double* nocapture %1, i8* nocapture %2) {
%4 = sitofp i32 %0 to double
%5 = fdiv double 1.000000e+00, %4
%6 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp slt i32 %0, 0
br i1 %7, label %22, label %8
8: ; preds = %3
%9 = add nuw i32 %0, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %20, %11 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = fmul double %5, %14
%16 = fptosi double %15 to i32
%17 = getelementptr inbounds double, double* %1, i64 %12
%18 = load double, double* %17
%19 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16, double %18)
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %11, %3
%23 = tail call i32 @fclose(i32* %6)
ret void
}