#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 *, ...);
int /*<<< orphan*/ printf(char *, char *);
int write_result(char *fn, double *m, double dx, long n) {
  long i;
  double x;
  FILE *fp;
  if ((fp = fopen(fn, "w")) == NULL) {
    printf("Can't write to file: %s\n", fn);
    return (1);
  }
  fprintf(fp, "#x\tm\n");
  x = 0.0;
  for (i = 0; i < n; i++) {
    fprintf(fp, "%.9e\t%.9e\n", x, m[i * 2] - m[i * 2 + 1]);
    fprintf(fp, "%.9e\t%.9e\n", x + dx, m[i * 2] + m[i * 2 + 1]);
    x = x + dx;
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<write_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1193 <write_result+0x53>
mov    -0x10(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126c <write_result+0x12c>
mov    -0x40(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    125c <write_result+0x11c>
mov    -0x40(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
subsd  0x8(%rax,%rcx,8),%xmm1
lea    0xe2b(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
addsd  0x8(%rax,%rcx,8),%xmm1
lea    0xdec(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
movsd  -0x38(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11b5 <write_result+0x75>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_result>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
movsd  %xmm0,0x10(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121a <write_result+0xca>
mov    %rax,%r15
lea    0xe92(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
test   %r14,%r14
jle    120e <write_result+0xbe>
add    $0x8,%rbx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe6c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movsd  -0x8(%rbx),%xmm1
subsd  (%rbx),%xmm1
mov    %r15,%rdi
mov    %r12,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  -0x8(%rbx),%xmm1
addsd  (%rbx),%xmm1
mov    %r15,%rdi
mov    %r12,%rsi
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%al
call   1050 <fprintf@plt>
add    $0x10,%rbx
add    $0xffffffffffffffff,%r14
jne    11c0 <write_result+0x70>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    122e <write_result+0xde>
lea    0xde1(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [25 x i8] c"Can't write to file: %s\0A\00"
@.str.2 = [6 x i8] c"#x\09m\0A\00"
@.str.3 = [11 x i8] c"%.9e\09%.9e\0A\00"
define i32 @write_result(i8* %0, double* %1, double %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca double*
%8 = alloca double
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca i32*
store i8* %0, i8** %6
store double* %1, double** %7
store double %2, double* %8
store i64 %3, i64* %9
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %5
br label %68
19: ; preds = %4
%20 = load i32*, i32** %12
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store double 0.000000e+00, double* %11
store i64 0, i64* %10
br label %22
22: ; preds = %62, %19
%23 = load i64, i64* %10
%24 = load i64, i64* %9
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %65
26: ; preds = %22
%27 = load i32*, i32** %12
%28 = load double, double* %11
%29 = load double*, double** %7
%30 = load i64, i64* %10
%31 = mul nsw i64 %30, 2
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %7
%35 = load i64, i64* %10
%36 = mul nsw i64 %35, 2
%37 = add nsw i64 %36, 1
%38 = getelementptr inbounds double, double* %34, i64 %37
%39 = load double, double* %38
%40 = fsub double %33, %39
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %28, double %40)
%42 = load i32*, i32** %12
%43 = load double, double* %11
%44 = load double, double* %8
%45 = fadd double %43, %44
%46 = load double*, double** %7
%47 = load i64, i64* %10
%48 = mul nsw i64 %47, 2
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %7
%52 = load i64, i64* %10
%53 = mul nsw i64 %52, 2
%54 = add nsw i64 %53, 1
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = fadd double %50, %56
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %45, double %57)
%59 = load double, double* %11
%60 = load double, double* %8
%61 = fadd double %59, %60
store double %61, double* %11
br label %62
62: ; preds = %26
%63 = load i64, i64* %10
%64 = add nsw i64 %63, 1
store i64 %64, i64* %10
br label %22
65: ; preds = %22
%66 = load i32*, i32** %12
%67 = call i32 @fclose(i32* %66)
store i32 0, i32* %5
br label %68
68: ; preds = %65, %16
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [25 x i8] c"Can't write to file: %s\0A\00"
@.str.2 = [6 x i8] c"#x\09m\0A\00"
@.str.3 = [11 x i8] c"%.9e\09%.9e\0A\00"
define i32 @write_result(i8* %0, double* nocapture %1, double %2, i64 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %32
9: ; preds = %4
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %5)
%11 = icmp sgt i64 %3, 0
br i1 %11, label %12, label %30
12: ; preds = %9, %12
%13 = phi double [ %23, %12 ], [ 0.000000e+00, %9 ]
%14 = phi i64 [ %28, %12 ], [ 0, %9 ]
%15 = shl nuw nsw i64 %14, 1
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = load double, double* %16
%18 = or i64 %15, 1
%19 = getelementptr inbounds double, double* %1, i64 %18
%20 = load double, double* %19
%21 = fsub double %17, %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %13, double %21)
%23 = fadd double %13, %2
%24 = load double, double* %16
%25 = load double, double* %19
%26 = fadd double %24, %25
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %23, double %26)
%28 = add nuw nsw i64 %14, 1
%29 = icmp eq i64 %28, %3
br i1 %29, label %30, label %12
30: ; preds = %12, %9
%31 = tail call i32 @fclose(i32* %5)
br label %32
32: ; preds = %30, %7
%33 = phi i32 [ 1, %7 ], [ 0, %30 ]
ret i32 %33
}