#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 *, ...);
void gridprint(double **grid, int gridSize) {
  FILE *fp;
  fp = fopen("filedata.out", "w+");
  for (int i = 0; i < gridSize + 2; i++) {
    for (int j = 0; j < gridSize + 2; j++) {
      fprintf(fp, "%f  ", grid[i][j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<gridprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11db <gridprint+0xab>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11bb <gridprint+0x8b>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe6a(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1175 <gridprint+0x45>
mov    -0x18(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <gridprint+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gridprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xea8(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
cmp    $0xffffffff,%r15d
jl     11d5 <gridprint+0x95>
add    $0x2,%r15d
cmp    $0x2,%r15d
mov    $0x1,%r13d
cmovge %r15d,%r13d
xor    %ebx,%ebx
lea    0xe88(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11a0 <gridprint+0x60>
mov    $0xa,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jne    1190 <gridprint+0x50>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"filedata.out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @gridprint(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store double** %0, double*** %3
store i32 %1, i32* %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %5
store i32 0, i32* %6
br label %9
9: ; preds = %38, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 2
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %41
14: ; preds = %9
store i32 0, i32* %7
br label %15
15: ; preds = %32, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 2
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = load double**, double*** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
%26 = load double*, double** %25
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %32
32: ; preds = %20
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %15
35: ; preds = %15
%36 = load i32*, i32** %5
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %35
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %9
41: ; preds = %9
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"filedata.out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%f \00"
define void @gridprint(double** nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp sgt i32 %1, -2
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = add i32 %1, 2
%7 = call i32 @llvm.smax.i32(i32 %6, i32 1)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %14, %5
%10 = phi i64 [ 0, %5 ], [ %16, %14 ]
%11 = getelementptr inbounds double*, double** %0, i64 %10
br label %18
12: ; preds = %14, %2
%13 = tail call i32 @fclose(i32* %3)
ret void
14: ; preds = %18
%15 = tail call i32 @fputc(i32 10, i32* %3)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %12, label %9
18: ; preds = %9, %18
%19 = phi i64 [ 0, %9 ], [ %24, %18 ]
%20 = load double*, double** %11
%21 = getelementptr inbounds double, double* %20, i64 %19
%22 = load double, double* %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %14, label %18
}