#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 scalar_t__ *w;
typedef size_t i;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void dumpGrid(float g[], int w) {
  int i, j;
  FILE *fp;
  fp = fopen("./dump.out", "w");
  for (i = 0; i < w; i++) {
    for (j = 0; j < w; j++) {
      fprintf(fp, "%f ", g[(i) * (w) + j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<dumpGrid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d6 <dumpGrid+0xa6>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b6 <dumpGrid+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <dumpGrid+0x40>
mov    -0x20(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <dumpGrid+0x2d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpGrid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea9(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11da <dumpGrid+0x9a>
mov    %ebp,%ebp
lea    0x0(,%rbp,4),%rax
mov    %rax,(%rsp)
xor    %r13d,%r13d
lea    0xe8b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  (%rbx,%r12,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    11a0 <dumpGrid+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
add    (%rsp),%rbx
cmp    %rbp,%r13
jne    1190 <dumpGrid+0x50>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

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