#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*/ puts(char *);
void c_savevtk_scalar(int arrayRow, int arrayCol, double *array, char *filename,
                      char *colorMap, double dx, double dy) {
  FILE *fptr = fopen(filename, "w");
  if (fptr == NULL) {
    puts("no file exists");
  } else {
    fprintf(fptr, "# vtk DataFile Version 2.0\n");
    fprintf(fptr, "Comment goes here\n");
    fprintf(fptr, "ASCII\n");
    fprintf(fptr, "\n");
    fprintf(fptr, "DATASET STRUCTURED_POINTS\n");
    fprintf(fptr, "DIMENSIONS    %d   %d   %d\n", arrayRow, arrayCol, 1);
    fprintf(fptr, "\n");
    fprintf(fptr, "ORIGIN    0.000   0.000   0.000\n");
    fprintf(fptr, "SPACING   %f%f   1.000\n", dx, dy);
    fprintf(fptr, "\n");
    fprintf(fptr, "POINT_DATA   %d\n", arrayCol * arrayCol * 1);
    fprintf(fptr, "SCALARS %s double\n", colorMap);
    fprintf(fptr, "LOOKUP_TABLE default\n");
    fprintf(fptr, "\n");
    for (int i = 0; i < arrayRow; i++) {
      for (int j = 0; j < arrayCol; j++) {
        fprintf(fptr, "%f ", array[i * arrayCol + j]);
      }
      fprintf(fptr, "\n");
    }
    fclose(fptr);
  }
}


x86 assembly (clang, -O0):
<c_savevtk_scalar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1194 <c_savevtk_scalar+0x54>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
jmp    1339 <c_savevtk_scalar+0x1f9>
mov    -0x38(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe63(%rip),%rsi
mov    $0x1,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe5a(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%edx
imul   -0x8(%rbp),%edx
shl    $0x0,%edx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1330 <c_savevtk_scalar+0x1f0>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1310 <c_savevtk_scalar+0x1d0>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdf6(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12ce <c_savevtk_scalar+0x18e>
mov    -0x38(%rbp),%rdi
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12bb <c_savevtk_scalar+0x17b>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_savevtk_scalar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %r8,%r12
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
lea    0xe75(%rip),%rsi
mov    %rcx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1364 <c_savevtk_scalar+0x204>
mov    %rax,%r13
lea    0xe6b(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe6e(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xe68(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
lea    0xe49(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xe4b(%rip),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    $0x1,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
lea    0xe3e(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xe46(%rip),%rsi
mov    %r13,%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x2,%al
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
mov    %ebp,(%rsp)
imul   %ebp,%ebp
lea    0xe2f(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe2d(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe2c(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
test   %r15d,%r15d
jle    134e <c_savevtk_scalar+0x1ee>
mov    (%rsp),%eax
movslq %eax,%rcx
mov    %r15d,%edx
mov    %rdx,0x10(%rsp)
mov    %eax,%r14d
shl    $0x3,%rcx
mov    %rcx,0x8(%rsp)
xor    %r15d,%r15d
lea    0xdfa(%rip),%rbp
jmp    131d <c_savevtk_scalar+0x1bd>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x1,%r15
add    0x8(%rsp),%rbx
cmp    0x10(%rsp),%r15
je     134e <c_savevtk_scalar+0x1ee>
cmpl   $0x0,(%rsp)
jle    1300 <c_savevtk_scalar+0x1a0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
movsd  (%rbx,%r12,8),%xmm0
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    1330 <c_savevtk_scalar+0x1d0>
jmp    1300 <c_savevtk_scalar+0x1a0>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xc97(%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 = [15 x i8] c"no file exists\00"
@.str.2 = [28 x i8] c"# vtk DataFile Version 2.0\0A\00"
@.str.3 = [19 x i8] c"Comment goes here\0A\00"
@.str.4 = [7 x i8] c"ASCII\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [27 x i8] c"DATASET STRUCTURED_POINTS\0A\00"
@.str.7 = [28 x i8] c"DIMENSIONS %d %d %d\0A\00"
@.str.8 = [33 x i8] c"ORIGIN 0.000 0.000 0.000\0A\00"
@.str.9 = [24 x i8] c"SPACING %f%f 1.000\0A\00"
@.str.10 = [17 x i8] c"POINT_DATA %d\0A\00"
@.str.11 = [19 x i8] c"SCALARS %s double\0A\00"
@.str.12 = [22 x i8] c"LOOKUP_TABLE default\0A\00"
@.str.13 = [4 x i8] c"%f \00"
define void @c_savevtk_scalar(i32 %0, i32 %1, double* %2, i8* %3, i8* %4, double %5, double %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca double
%14 = alloca double
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store double* %2, double** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store double %5, double* %13
store double %6, double* %14
%18 = load i8*, i8** %11
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %15
%20 = load i32*, i32** %15
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %7
%23 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %95
24: ; preds = %7
%25 = load i32*, i32** %15
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32*, i32** %15
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32*, i32** %15
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %15
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32*, i32** %15
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32*, i32** %15
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %36, i32 %37, i32 1)
%39 = load i32*, i32** %15
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32*, i32** %15
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%43 = load i32*, i32** %15
%44 = load double, double* %13
%45 = load double, double* %14
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), double %44, double %45)
%47 = load i32*, i32** %15
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32*, i32** %15
%50 = load i32, i32* %9
%51 = load i32, i32* %9
%52 = mul nsw i32 %50, %51
%53 = mul nsw i32 %52, 1
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %53)
%55 = load i32*, i32** %15
%56 = load i8*, i8** %12
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %15
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%60 = load i32*, i32** %15
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %16
br label %62
62: ; preds = %89, %24
%63 = load i32, i32* %16
%64 = load i32, i32* %8
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %92
66: ; preds = %62
store i32 0, i32* %17
br label %67
67: ; preds = %83, %66
%68 = load i32, i32* %17
%69 = load i32, i32* %9
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %86
71: ; preds = %67
%72 = load i32*, i32** %15
%73 = load double*, double** %10
%74 = load i32, i32* %16
%75 = load i32, i32* %9
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %17
%78 = add nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %73, i64 %79
%81 = load double, double* %80
%82 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double %81)
br label %83
83: ; preds = %71
%84 = load i32, i32* %17
%85 = add nsw i32 %84, 1
store i32 %85, i32* %17
br label %67
86: ; preds = %67
%87 = load i32*, i32** %15
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %89
89: ; preds = %86
%90 = load i32, i32* %16
%91 = add nsw i32 %90, 1
store i32 %91, i32* %16
br label %62
92: ; preds = %62
%93 = load i32*, i32** %15
%94 = call i32 @fclose(i32* %93)
br label %95
95: ; preds = %92, %22
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [15 x i8] c"no file exists\00"
@.str.2 = [28 x i8] c"# vtk DataFile Version 2.0\0A\00"
@.str.3 = [19 x i8] c"Comment goes here\0A\00"
@.str.4 = [7 x i8] c"ASCII\0A\00"
@.str.6 = [27 x i8] c"DATASET STRUCTURED_POINTS\0A\00"
@.str.7 = [28 x i8] c"DIMENSIONS %d %d %d\0A\00"
@.str.8 = [33 x i8] c"ORIGIN 0.000 0.000 0.000\0A\00"
@.str.9 = [24 x i8] c"SPACING %f%f 1.000\0A\00"
@.str.10 = [17 x i8] c"POINT_DATA %d\0A\00"
@.str.11 = [19 x i8] c"SCALARS %s double\0A\00"
@.str.12 = [22 x i8] c"LOOKUP_TABLE default\0A\00"
@.str.13 = [4 x i8] c"%f \00"
define void @c_savevtk_scalar(i32 %0, i32 %1, double* nocapture %2, i8* nocapture %3, i8* %4, double %5, double %6) {
%8 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %52
12: ; preds = %7
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %8)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 18, i64 1, i32* %8)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 6, i64 1, i32* %8)
%16 = tail call i32 @fputc(i32 10, i32* %8)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i64 26, i64 1, i32* %8)
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %0, i32 %1, i32 1)
%19 = tail call i32 @fputc(i32 10, i32* %8)
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 32, i64 1, i32* %8)
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), double %5, double %6)
%22 = tail call i32 @fputc(i32 10, i32* %8)
%23 = mul nsw i32 %1, %1
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %23)
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %4)
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i64 21, i64 1, i32* %8)
%27 = tail call i32 @fputc(i32 10, i32* %8)
%28 = icmp sgt i32 %0, 0
br i1 %28, label %29, label %38
29: ; preds = %12
%30 = icmp sgt i32 %1, 0
%31 = sext i32 %1 to i64
%32 = zext i32 %0 to i64
%33 = zext i32 %1 to i64
br label %34
34: ; preds = %29, %40
%35 = phi i64 [ 0, %29 ], [ %42, %40 ]
br i1 %30, label %36, label %40
36: ; preds = %34
%37 = mul nsw i64 %35, %31
br label %44
38: ; preds = %40, %12
%39 = tail call i32 @fclose(i32* %8)
br label %52
40: ; preds = %44, %34
%41 = tail call i32 @fputc(i32 10, i32* %8)
%42 = add nuw nsw i64 %35, 1
%43 = icmp eq i64 %42, %32
br i1 %43, label %38, label %34
44: ; preds = %36, %44
%45 = phi i64 [ 0, %36 ], [ %50, %44 ]
%46 = add nsw i64 %45, %37
%47 = getelementptr inbounds double, double* %2, i64 %46
%48 = load double, double* %47
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), double %48)
%50 = add nuw nsw i64 %45, 1
%51 = icmp eq i64 %50, %33
br i1 %51, label %40, label %44
52: ; preds = %38, %10
ret void
}