#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 *, ...);
int write_result_vtk(char *outFileName, int startIdx, int endIdx, int nodeCnt,
                     int **points, int **elems, double *vector) {
  int i, j;
  int cellCnt = endIdx - startIdx + 1;
  FILE *fp = fopen(outFileName, "w");
  if (fp == NULL) {
    printf("Error opening file %s for writing\n", outFileName);
    return -1;
  }
  fprintf(fp, "# vtk DataFile Version 3.0\n");
  fprintf(fp, "vtk output\n");
  fprintf(fp, "ASCII\n");
  fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");
  fprintf(fp, "POINTS %d float\n", nodeCnt);
  printf("nodeCnt = %d, startInd= %d, endInd = %d, cellCnt=%d\n", nodeCnt,
         startIdx, endIdx, cellCnt);
  for (i = 1; i <= nodeCnt; i++) {
    fprintf(fp, "%d %d %d\n", points[0][i], points[1][i], points[2][i]);
  }
  fprintf(fp, "\nCELLS %d %d\n", cellCnt, 9 * cellCnt);
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "8 %d %d %d %d %d %d %d %d\n", elems[0][i] - 1, elems[1][i] - 1,
            elems[3][i] - 1, elems[2][i] - 1, elems[4][i] - 1, elems[5][i] - 1,
            elems[7][i] - 1, elems[6][i] - 1);
  }
  fprintf(fp, "\nCELL_TYPES %d\n", cellCnt);
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "11\n");
  }
  fprintf(fp, "\nCELL_DATA %d\n", cellCnt);
  fprintf(fp, "SCALARS scalars float\nLOOKUP_TABLE default\n");
  for (i = startIdx; i <= endIdx; i++) {
    fprintf(fp, "%f ", vector[i]);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_result_vtk>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11ab <write_result_vtk+0x6b>
mov    -0x18(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    1433 <write_result_vtk+0x2f3>
mov    -0x50(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x44(%rbp),%r8d
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1283 <write_result_vtk+0x143>
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r8d
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122a <write_result_vtk+0xea>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
imul   $0x9,-0x44(%rbp),%ecx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1376 <write_result_vtk+0x236>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
sub    $0x1,%edx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
sub    $0x1,%ecx
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r8d
sub    $0x1,%r8d
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r9d
sub    $0x1,%r9d
mov    -0x38(%rbp),%rax
mov    0x20(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%ebx
sub    $0x1,%ebx
mov    -0x38(%rbp),%rax
mov    0x28(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r11d
sub    $0x1,%r11d
mov    -0x38(%rbp),%rax
mov    0x38(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%r10d
sub    $0x1,%r10d
mov    -0x38(%rbp),%rax
mov    0x30(%rax),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,4),%eax
sub    $0x1,%eax
lea    0xd73(%rip),%rsi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12a2 <write_result_vtk+0x162>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     13bd <write_result_vtk+0x27d>
mov    -0x50(%rbp),%rdi
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1391 <write_result_vtk+0x251>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1423 <write_result_vtk+0x2e3>
mov    -0x50(%rbp),%rdi
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd1f(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13ea <write_result_vtk+0x2aa>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_result_vtk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r15
mov    %r8,%rbx
mov    %ecx,%ebp
mov    %rdx,0x10(%rsp)
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12ca <write_result_vtk+0x17a>
mov    %rax,%r13
mov    0x10(%rsp),%r12
sub    %r14d,%r12d
add    $0x1,%r12d
lea    0xe89(%rip),%rdi
mov    %r14d,0xc(%rsp)
mov    $0x1,%r14d
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xe81(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
lea    0xe74(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
lea    0xe62(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
lea    0xe64(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe62(%rip),%rdi
mov    %ebp,%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%rcx
mov    %r12,0x20(%rsp)
mov    %r12d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    127d <write_result_vtk+0x12d>
add    $0x1,%ebp
lea    0xe8e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%rax
mov    0x8(%rbx),%rcx
mov    (%rax,%r14,4),%edx
mov    (%rcx,%r14,4),%ecx
mov    0x10(%rbx),%rax
mov    (%rax,%r14,4),%r8d
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1250 <write_result_vtk+0x100>
mov    0x20(%rsp),%rbx
lea    (%rbx,%rbx,8),%ecx
lea    0xe29(%rip),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%rsp),%r12
mov    %r12d,%eax
mov    0xc(%rsp),%r14d
sub    %r14d,%eax
mov    %rax,0x18(%rsp)
jge    12e5 <write_result_vtk+0x195>
lea    0xe28(%rip),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%r15
jmp    142a <write_result_vtk+0x2da>
lea    0xd31(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    14a6 <write_result_vtk+0x356>
movslq %r14d,%r14
shl    $0x2,%r14
mov    0x18(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x18(%rsp)
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%edx
add    $0xffffffff,%edx
mov    0x8(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%ecx
add    $0xffffffff,%ecx
mov    0x18(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%r8d
add    $0xffffffff,%r8d
mov    0x10(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%r9d
add    $0xffffffff,%r9d
mov    0x20(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%r10d
add    $0xffffffff,%r10d
mov    0x28(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%r11d
add    $0xffffffff,%r11d
mov    0x38(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%ebx
add    $0xffffffff,%ebx
mov    0x30(%r15),%rax
add    %r14,%rax
mov    (%rax,%rbp,4),%r12d
add    $0xffffffff,%r12d
mov    %r13,%rdi
lea    0xd48(%rip),%rsi
xor    %eax,%eax
push   %r12
push   %rbx
push   %r11
push   %r10
call   1050 <fprintf@plt>
add    $0x20,%rsp
add    $0x1,%rbp
cmp    %ebp,0x18(%rsp)
jne    1300 <write_result_vtk+0x1b0>
lea    0xd3c(%rip),%rsi
mov    %r13,%rdi
mov    0x20(%rsp),%r15
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%rsp),%r12
mov    %r12d,%ebp
mov    0xc(%rsp),%r14d
sub    %r14d,%ebp
jge    13f8 <write_result_vtk+0x2a8>
lea    0xd25(%rip),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xd20(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
jmp    149c <write_result_vtk+0x34c>
add    $0x1,%ebp
lea    0xcec(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r13,%rcx
call   1070 <fwrite@plt>
add    $0xffffffff,%ebp
jne    1410 <write_result_vtk+0x2c0>
lea    0xcc1(%rip),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xcbc(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
sub    %r14d,%r12d
jl     149c <write_result_vtk+0x34c>
mov    0x60(%rsp),%rax
movslq %r14d,%rcx
lea    (%rax,%rcx,8),%rbp
add    $0x1,%r12d
xor    %ebx,%ebx
lea    0xcb8(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x0(%rbp,%rbx,8),%xmm0
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1480 <write_result_vtk+0x330>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.2 = [28 x i8] c"# vtk DataFile Version 3.0\0A\00"
@.str.3 = [12 x i8] c"vtk output\0A\00"
@.str.4 = [7 x i8] c"ASCII\0A\00"
@.str.5 = [27 x i8] c"DATASET UNSTRUCTURED_GRID\0A\00"
@.str.6 = [17 x i8] c"POINTS %d float\0A\00"
@.str.7 = [53 x i8] c"nodeCnt = %d, startInd= %d, endInd = %d, cellCnt=%d\0A\00"
@.str.8 = [10 x i8] c"%d %d %d\0A\00"
@.str.9 = [14 x i8] c"\0ACELLS %d %d\0A\00"
@.str.10 = [27 x i8] c"8 %d %d %d %d %d %d %d %d\0A\00"
@.str.11 = [16 x i8] c"\0ACELL_TYPES %d\0A\00"
@.str.12 = [4 x i8] c"11\0A\00"
@.str.13 = [15 x i8] c"\0ACELL_DATA %d\0A\00"
@.str.14 = [44 x i8] c"SCALARS scalars float\0ALOOKUP_TABLE default\0A\00"
@.str.15 = [4 x i8] c"%f \00"
define i32 @write_result_vtk(i8* %0, i32 %1, i32 %2, i32 %3, i32** %4, i32** %5, double* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32**
%14 = alloca i32**
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32** %4, i32*** %13
store i32** %5, i32*** %14
store double* %6, double** %15
%20 = load i32, i32* %11
%21 = load i32, i32* %10
%22 = sub nsw i32 %20, %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %18
%24 = load i8*, i8** %9
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %19
%26 = load i32*, i32** %19
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %7
%29 = load i8*, i8** %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 -1, i32* %8
br label %200
31: ; preds = %7
%32 = load i32*, i32** %19
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32*, i32** %19
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32*, i32** %19
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32*, i32** %19
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32*, i32** %19
%41 = load i32, i32* %12
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %12
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = load i32, i32* %18
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %44, i32 %45, i32 %46)
store i32 1, i32* %16
br label %48
48: ; preds = %76, %31
%49 = load i32, i32* %16
%50 = load i32, i32* %12
%51 = icmp sle i32 %49, %50
br i1 %51, label %52, label %79
52: ; preds = %48
%53 = load i32*, i32** %19
%54 = load i32**, i32*** %13
%55 = getelementptr inbounds i32*, i32** %54, i64 0
%56 = load i32*, i32** %55
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = load i32**, i32*** %13
%62 = getelementptr inbounds i32*, i32** %61, i64 1
%63 = load i32*, i32** %62
%64 = load i32, i32* %16
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = load i32**, i32*** %13
%69 = getelementptr inbounds i32*, i32** %68, i64 2
%70 = load i32*, i32** %69
%71 = load i32, i32* %16
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %60, i32 %67, i32 %74)
br label %76
76: ; preds = %52
%77 = load i32, i32* %16
%78 = add nsw i32 %77, 1
store i32 %78, i32* %16
br label %48
79: ; preds = %48
%80 = load i32*, i32** %19
%81 = load i32, i32* %18
%82 = load i32, i32* %18
%83 = mul nsw i32 9, %82
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i32 %81, i32 %83)
%85 = load i32, i32* %10
store i32 %85, i32* %16
br label %86
86: ; preds = %157, %79
%87 = load i32, i32* %16
%88 = load i32, i32* %11
%89 = icmp sle i32 %87, %88
br i1 %89, label %90, label %160
90: ; preds = %86
%91 = load i32*, i32** %19
%92 = load i32**, i32*** %14
%93 = getelementptr inbounds i32*, i32** %92, i64 0
%94 = load i32*, i32** %93
%95 = load i32, i32* %16
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %94, i64 %96
%98 = load i32, i32* %97
%99 = sub nsw i32 %98, 1
%100 = load i32**, i32*** %14
%101 = getelementptr inbounds i32*, i32** %100, i64 1
%102 = load i32*, i32** %101
%103 = load i32, i32* %16
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %102, i64 %104
%106 = load i32, i32* %105
%107 = sub nsw i32 %106, 1
%108 = load i32**, i32*** %14
%109 = getelementptr inbounds i32*, i32** %108, i64 3
%110 = load i32*, i32** %109
%111 = load i32, i32* %16
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i32, i32* %110, i64 %112
%114 = load i32, i32* %113
%115 = sub nsw i32 %114, 1
%116 = load i32**, i32*** %14
%117 = getelementptr inbounds i32*, i32** %116, i64 2
%118 = load i32*, i32** %117
%119 = load i32, i32* %16
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i32, i32* %118, i64 %120
%122 = load i32, i32* %121
%123 = sub nsw i32 %122, 1
%124 = load i32**, i32*** %14
%125 = getelementptr inbounds i32*, i32** %124, i64 4
%126 = load i32*, i32** %125
%127 = load i32, i32* %16
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i32, i32* %126, i64 %128
%130 = load i32, i32* %129
%131 = sub nsw i32 %130, 1
%132 = load i32**, i32*** %14
%133 = getelementptr inbounds i32*, i32** %132, i64 5
%134 = load i32*, i32** %133
%135 = load i32, i32* %16
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i32, i32* %134, i64 %136
%138 = load i32, i32* %137
%139 = sub nsw i32 %138, 1
%140 = load i32**, i32*** %14
%141 = getelementptr inbounds i32*, i32** %140, i64 7
%142 = load i32*, i32** %141
%143 = load i32, i32* %16
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i32, i32* %142, i64 %144
%146 = load i32, i32* %145
%147 = sub nsw i32 %146, 1
%148 = load i32**, i32*** %14
%149 = getelementptr inbounds i32*, i32** %148, i64 6
%150 = load i32*, i32** %149
%151 = load i32, i32* %16
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i32, i32* %150, i64 %152
%154 = load i32, i32* %153
%155 = sub nsw i32 %154, 1
%156 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %99, i32 %107, i32 %115, i32 %123, i32 %131, i32 %139, i32 %147, i32 %155)
br label %157
157: ; preds = %90
%158 = load i32, i32* %16
%159 = add nsw i32 %158, 1
store i32 %159, i32* %16
br label %86
160: ; preds = %86
%161 = load i32*, i32** %19
%162 = load i32, i32* %18
%163 = call i32 (i32*, i8*, ...) @fprintf(i32* %161, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 %162)
%164 = load i32, i32* %10
store i32 %164, i32* %16
br label %165
165: ; preds = %172, %160
%166 = load i32, i32* %16
%167 = load i32, i32* %11
%168 = icmp sle i32 %166, %167
br i1 %168, label %169, label %175
169: ; preds = %165
%170 = load i32*, i32** %19
%171 = call i32 (i32*, i8*, ...) @fprintf(i32* %170, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
br label %172
172: ; preds = %169
%173 = load i32, i32* %16
%174 = add nsw i32 %173, 1
store i32 %174, i32* %16
br label %165
175: ; preds = %165
%176 = load i32*, i32** %19
%177 = load i32, i32* %18
%178 = call i32 (i32*, i8*, ...) @fprintf(i32* %176, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i32 %177)
%179 = load i32*, i32** %19
%180 = call i32 (i32*, i8*, ...) @fprintf(i32* %179, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0))
%181 = load i32, i32* %10
store i32 %181, i32* %16
br label %182
182: ; preds = %194, %175
%183 = load i32, i32* %16
%184 = load i32, i32* %11
%185 = icmp sle i32 %183, %184
br i1 %185, label %186, label %197
186: ; preds = %182
%187 = load i32*, i32** %19
%188 = load double*, double** %15
%189 = load i32, i32* %16
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds double, double* %188, i64 %190
%192 = load double, double* %191
%193 = call i32 (i32*, i8*, ...) @fprintf(i32* %187, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), double %192)
br label %194
194: ; preds = %186
%195 = load i32, i32* %16
%196 = add nsw i32 %195, 1
store i32 %196, i32* %16
br label %182
197: ; preds = %182
%198 = load i32*, i32** %19
%199 = call i32 @fclose(i32* %198)
store i32 0, i32* %8
br label %200
200: ; preds = %197, %28
%201 = load i32, i32* %8
ret i32 %201
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.2 = [28 x i8] c"# vtk DataFile Version 3.0\0A\00"
@.str.3 = [12 x i8] c"vtk output\0A\00"
@.str.4 = [7 x i8] c"ASCII\0A\00"
@.str.5 = [27 x i8] c"DATASET UNSTRUCTURED_GRID\0A\00"
@.str.6 = [17 x i8] c"POINTS %d float\0A\00"
@.str.7 = [53 x i8] c"nodeCnt = %d, startInd= %d, endInd = %d, cellCnt=%d\0A\00"
@.str.8 = [10 x i8] c"%d %d %d\0A\00"
@.str.9 = [14 x i8] c"\0ACELLS %d %d\0A\00"
@.str.10 = [27 x i8] c"8 %d %d %d %d %d %d %d %d\0A\00"
@.str.11 = [16 x i8] c"\0ACELL_TYPES %d\0A\00"
@.str.12 = [4 x i8] c"11\0A\00"
@.str.13 = [15 x i8] c"\0ACELL_DATA %d\0A\00"
@.str.14 = [44 x i8] c"SCALARS scalars float\0ALOOKUP_TABLE default\0A\00"
@.str.15 = [4 x i8] c"%f \00"
define i32 @write_result_vtk(i8* %0, i32 %1, i32 %2, i32 %3, i32** nocapture %4, i32** nocapture %5, double* nocapture %6) {
%8 = sub nsw i32 %2, %1
%9 = add nsw i32 %8, 1
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %121
14: ; preds = %7
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %10)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 11, i64 1, i32* %10)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 6, i64 1, i32* %10)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i64 26, i64 1, i32* %10)
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %3)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %3, i32 %1, i32 %2, i32 %9)
%21 = icmp slt i32 %3, 1
br i1 %21, label %41, label %22
22: ; preds = %14
%23 = getelementptr inbounds i32*, i32** %4, i64 1
%24 = getelementptr inbounds i32*, i32** %4, i64 2
%25 = add nuw i32 %3, 1
%26 = zext i32 %25 to i64
br label %27
27: ; preds = %22, %27
%28 = phi i64 [ 1, %22 ], [ %39, %27 ]
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 %28
%31 = load i32, i32* %30
%32 = load i32*, i32** %23
%33 = getelementptr inbounds i32, i32* %32, i64 %28
%34 = load i32, i32* %33
%35 = load i32*, i32** %24
%36 = getelementptr inbounds i32, i32* %35, i64 %28
%37 = load i32, i32* %36
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %31, i32 %34, i32 %37)
%39 = add nuw nsw i64 %28, 1
%40 = icmp eq i64 %39, %26
br i1 %40, label %41, label %27
41: ; preds = %27, %14
%42 = mul nsw i32 %9, 9
%43 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i32 %9, i32 %42)
%44 = icmp slt i32 %2, %1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 %9)
br label %102
47: ; preds = %41
%48 = getelementptr inbounds i32*, i32** %5, i64 1
%49 = getelementptr inbounds i32*, i32** %5, i64 3
%50 = getelementptr inbounds i32*, i32** %5, i64 2
%51 = getelementptr inbounds i32*, i32** %5, i64 4
%52 = getelementptr inbounds i32*, i32** %5, i64 5
%53 = getelementptr inbounds i32*, i32** %5, i64 7
%54 = getelementptr inbounds i32*, i32** %5, i64 6
%55 = sext i32 %1 to i64
%56 = add i32 %2, 1
br label %57
57: ; preds = %47, %57
%58 = phi i64 [ %55, %47 ], [ %92, %57 ]
%59 = load i32*, i32** %5
%60 = getelementptr inbounds i32, i32* %59, i64 %58
%61 = load i32, i32* %60
%62 = add nsw i32 %61, -1
%63 = load i32*, i32** %48
%64 = getelementptr inbounds i32, i32* %63, i64 %58
%65 = load i32, i32* %64
%66 = add nsw i32 %65, -1
%67 = load i32*, i32** %49
%68 = getelementptr inbounds i32, i32* %67, i64 %58
%69 = load i32, i32* %68
%70 = add nsw i32 %69, -1
%71 = load i32*, i32** %50
%72 = getelementptr inbounds i32, i32* %71, i64 %58
%73 = load i32, i32* %72
%74 = add nsw i32 %73, -1
%75 = load i32*, i32** %51
%76 = getelementptr inbounds i32, i32* %75, i64 %58
%77 = load i32, i32* %76
%78 = add nsw i32 %77, -1
%79 = load i32*, i32** %52
%80 = getelementptr inbounds i32, i32* %79, i64 %58
%81 = load i32, i32* %80
%82 = add nsw i32 %81, -1
%83 = load i32*, i32** %53
%84 = getelementptr inbounds i32, i32* %83, i64 %58
%85 = load i32, i32* %84
%86 = add nsw i32 %85, -1
%87 = load i32*, i32** %54
%88 = getelementptr inbounds i32, i32* %87, i64 %58
%89 = load i32, i32* %88
%90 = add nsw i32 %89, -1
%91 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %62, i32 %66, i32 %70, i32 %74, i32 %78, i32 %82, i32 %86, i32 %90)
%92 = add nsw i64 %58, 1
%93 = trunc i64 %92 to i32
%94 = icmp eq i32 %56, %93
br i1 %94, label %95, label %57
95: ; preds = %57
%96 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 %9)
br i1 %44, label %116, label %97
97: ; preds = %95, %97
%98 = phi i32 [ %100, %97 ], [ %1, %95 ]
%99 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i64 3, i64 1, i32* %10)
%100 = add i32 %98, 1
%101 = icmp eq i32 %98, %2
br i1 %101, label %102, label %97
102: ; preds = %97, %45
%103 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i32 %9)
%104 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0), i64 43, i64 1, i32* %10)
br i1 %44, label %119, label %105
105: ; preds = %102
%106 = sext i32 %1 to i64
%107 = add i32 %2, 1
br label %108
108: ; preds = %105, %108
%109 = phi i64 [ %106, %105 ], [ %113, %108 ]
%110 = getelementptr inbounds double, double* %6, i64 %109
%111 = load double, double* %110
%112 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), double %111)
%113 = add nsw i64 %109, 1
%114 = trunc i64 %113 to i32
%115 = icmp eq i32 %107, %114
br i1 %115, label %119, label %108
116: ; preds = %95
%117 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i32 %9)
%118 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.14, i64 0, i64 0), i64 43, i64 1, i32* %10)
br label %119
119: ; preds = %108, %116, %102
%120 = tail call i32 @fclose(i32* %10)
br label %121
121: ; preds = %119, %12
%122 = phi i32 [ -1, %12 ], [ 0, %119 ]
ret i32 %122
}