#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 *);
void writeResults(double Y[][12], int n, double dt, char *outputFileName,
                  double command[]) {
  FILE *fPtr;
  int i, j;
  double t = 0;
  if ((fPtr = fopen(outputFileName, "w")) == NULL) {
    printf("File results could not be opened.\n");
  } else {
    for (i = 0; i < n; i++) {
      fprintf(fPtr, "%lg ", t);
      t = t + dt;
      for (j = 0; j < 12; j++) {
        fprintf(fPtr, "%lg ", Y[i][j]);
      }
      fprintf(fPtr, "%lg", command[i]);
      fprintf(fPtr, "\n");
    }
    fclose(fPtr);
  }
}


x86 assembly (clang, -O0):
<writeResults>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1193 <writeResults+0x53>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
jmp    125d <writeResults+0x11d>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1254 <writeResults+0x114>
mov    -0x30(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
lea    0xe6f(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  -0x40(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0xc,-0x38(%rbp)
jge    1215 <writeResults+0xd5>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   $0x60,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe25(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11d3 <writeResults+0x93>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdfd(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <writeResults+0x5a>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeResults>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
movsd  %xmm0,0x10(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8d(%rip),%rsi
mov    %rdx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12f7 <writeResults+0x1a7>
mov    %rax,%r15
test   %ebp,%ebp
jle    12e1 <writeResults+0x191>
mov    %ebp,%ebp
add    $0x58,%rbx
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r13d,%r13d
lea    0xe5a(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x58(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x50(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x48(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x40(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x38(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x30(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x28(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x20(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x18(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x10(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  -0x8(%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  (%rbx),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%r13,8),%xmm0
mov    %r15,%rdi
lea    0xd4b(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0x1,%r13
add    $0x60,%rbx
cmp    %r13,%rbp
jne    11b0 <writeResults+0x60>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xd0d(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%lg \00"
@.str.3 = [4 x i8] c"%lg\00"
@str = [34 x i8] c"File results could not be opened.\00"
define void @writeResults([12 x double]* nocapture %0, i32 %1, double %2, i8* nocapture %3, double* nocapture %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %61
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %14
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %63
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %59, %14 ]
%16 = phi double [ 0.000000e+00, %10 ], [ %54, %14 ]
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %16)
%18 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 0
%19 = load double, double* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 1
%22 = load double, double* %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 2
%25 = load double, double* %24
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 3
%28 = load double, double* %27
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %28)
%30 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 4
%31 = load double, double* %30
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %31)
%33 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 5
%34 = load double, double* %33
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %34)
%36 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 6
%37 = load double, double* %36
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %37)
%39 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 7
%40 = load double, double* %39
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %40)
%42 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 8
%43 = load double, double* %42
%44 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %43)
%45 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 9
%46 = load double, double* %45
%47 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %46)
%48 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 10
%49 = load double, double* %48
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = getelementptr inbounds [12 x double], [12 x double]* %0, i64 %15, i64 11
%52 = load double, double* %51
%53 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %52)
%54 = fadd double %16, %2
%55 = getelementptr inbounds double, double* %4, i64 %15
%56 = load double, double* %55
%57 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %56)
%58 = tail call i32 @fputc(i32 10, i32* %6)
%59 = add nuw nsw i64 %15, 1
%60 = icmp eq i64 %59, %11
br i1 %60, label %61, label %14
61: ; preds = %14, %8
%62 = tail call i32 @fclose(i32* %6)
br label %63
63: ; preds = %61, %12
ret void
}