#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);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  double v1[2] = {2.0, 0.5};
  double v2[2] = {3.0, -1.0};
  double product = 0.0;
  int i = 0;
  FILE *fp = NULL;
  if ((fp = fopen("data.csv", "w")) == NULL) {
    printf("fopen failed\n");
    return 0;
  }
  for (i = 0; i < 2; i++) {
    product += v1[i] * v2[i];
  }
  fprintf(fp, "%lf\n", product);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11d2 <main+0x92>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <main+0xfc>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x2,-0x3c(%rbp)
jge    1217 <main+0xd7>
movslq -0x3c(%rbp),%rax
movsd  -0x20(%rbp,%rax,8),%xmm0
movslq -0x3c(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d9 <main+0x99>
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec0(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <main+0x3d>
mov    %rax,%rbx
lea    0xeb0(%rip),%rsi
movsd  0xe95(%rip),%xmm0
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1189 <main+0x49>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.v1 = [2 x double] [double 2.000000e+00, double 5.000000e-01]
@__const.main.v2 = [2 x double] [double 3.000000e+00, double -1.000000e+00]
@.str = [9 x i8] c"data.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"fopen failed\0A\00"
@.str.3 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x double]
%7 = alloca [2 x double]
%8 = alloca double
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [2 x double]* %6 to i8*
%12 = bitcast [2 x double]* %7 to i8*
store double 0.000000e+00, double* %8
store i32 0, i32* %9
store i32* null, i32** %10
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %41
17: ; preds = %2
store i32 0, i32* %9
br label %18
18: ; preds = %32, %17
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 %23
%25 = load double, double* %24
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 %27
%29 = load double, double* %28
%30 = load double, double* %8
%31 = call double @llvm.fmuladd.f64(double %25, double %29, double %30)
store double %31, double* %8
br label %32
32: ; preds = %21
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %18
35: ; preds = %18
%36 = load i32*, i32** %10
%37 = load double, double* %8
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %37)
%39 = load i32*, i32** %10
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %35, %15
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [5 x i8] c"%lf\0A\00"
@str = [13 x i8] c"fopen failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double 5.500000e+00)
%7 = tail call i32 @fclose(i32* %3)
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %5, %8
ret i32 0
}