#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; i++) {
    for (int j = 0; j < gridSize; 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
cmp    -0xc(%rbp),%eax
jge    11d1 <gridprint+0xa1>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <gridprint+0x81>
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    0xe74(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <gridprint+0x40>
mov    -0x18(%rbp),%rdi
lea    0xe59(%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,%ebp
mov    %rdi,%r14
lea    0xea9(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    11c5 <gridprint+0x85>
mov    %ebp,%r13d
xor    %ebx,%ebx
lea    0xe9a(%rip),%r15
cs nopw 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    1190 <gridprint+0x50>
mov    $0xa,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jne    1180 <gridprint+0x40>
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 = %36, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
store i32 0, i32* %7
br label %14
14: ; preds = %30, %13
%15 = load i32, i32* %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = load double**, double*** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
%24 = load double*, double** %23
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %28)
br label %30
30: ; preds = %18
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %14
33: ; preds = %14
%34 = load i32*, i32** %5
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %9
39: ; preds = %9
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
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, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %12, %5
%8 = phi i64 [ 0, %5 ], [ %14, %12 ]
%9 = getelementptr inbounds double*, double** %0, i64 %8
br label %16
10: ; preds = %12, %2
%11 = tail call i32 @fclose(i32* %3)
ret void
12: ; preds = %16
%13 = tail call i32 @fputc(i32 10, i32* %3)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %10, label %7
16: ; preds = %7, %16
%17 = phi i64 [ 0, %7 ], [ %22, %16 ]
%18 = load double*, double** %9
%19 = getelementptr inbounds double, double* %18, i64 %17
%20 = load double, double* %19
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %20)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %6
br i1 %23, label %12, label %16
}