#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 const j;
typedef int const i;
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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void write(float *u, int timestep, int size) {
  int i, j;
  char szFilename[255];
  sprintf(szFilename, "%04d.txt", timestep);
  printf("Writing file %s...\n", szFilename);
  FILE *file = fopen(szFilename, "w");
  const int k = size / 3;
  for (j = 0; j < size; j++) {
    for (i = 0; i < size; i++)
      fprintf(file, "%f ", u[((i) + size * ((j) + size * (k)))]);
    fprintf(file, "\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x12c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1252 <write+0x102>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    122f <write+0xdf>
mov    -0x128(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%r8d
imul   -0x12c(%rbp),%r8d
ff
add    %r8d,%esi
imul   %esi,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe05(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d3 <write+0x83>
mov    -0x128(%rbp),%rdi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c0 <write+0x70>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edx,%r15d
mov    %esi,%edx
mov    %rdi,%r14
lea    0xe80(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    123b <write+0xdb>
mov    %r15d,%ebp
mov    $0xaaaaaaab,%eax
imul   %rbp,%rax
shr    $0x21,%rax
imul   %r15d,%eax
cltq
imul   %rbp,%rax
lea    (%r14,%rax,4),%rbx
lea    0x0(,%rbp,4),%rax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
lea    0xe33(%rip),%r14
nopl   0x0(%rax)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  (%rbx,%r15,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1200 <write+0xa0>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0x1,%r13
add    0x8(%rsp),%rbx
cmp    %rbp,%r13
jne    11f0 <write+0x90>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%04d.txt\00"
@.str.1 = [20 x i8] c"Writing file %s...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%f \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @write(float* %0, i32 %1, i32 %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [255 x i8]
%10 = alloca i32*
%11 = alloca i32
store float* %0, float** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%13 = load i32, i32* %5
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %10
%19 = load i32, i32* %6
%20 = sdiv i32 %19, 3
store i32 %20, i32* %11
store i32 0, i32* %8
br label %21
21: ; preds = %53, %3
%22 = load i32, i32* %8
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %21
store i32 0, i32* %7
br label %26
26: ; preds = %47, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %50
30: ; preds = %26
%31 = load i32*, i32** %10
%32 = load float*, float** %4
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = load i32, i32* %8
%36 = load i32, i32* %6
%37 = load i32, i32* %11
%38 = mul nsw i32 %36, %37
%39 = add nsw i32 %35, %38
%40 = mul nsw i32 %34, %39
%41 = add nsw i32 %33, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %32, i64 %42
%44 = load float, float* %43
%45 = fpext float %44 to double
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %45)
br label %47
47: ; preds = %30
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %26
50: ; preds = %26
%51 = load i32*, i32** %10
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %50
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %21
56: ; preds = %21
%57 = load i32*, i32** %10
%58 = call i32 @fclose(i32* %57)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%04d.txt\00"
@.str.1 = [20 x i8] c"Writing file %s...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%f \00"
define void @write(float* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %33
10: ; preds = %3
%11 = udiv i32 %2, 3
%12 = mul nsw i32 %11, %2
%13 = sext i32 %12 to i64
%14 = zext i32 %2 to i64
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %29, %10
%17 = phi i64 [ 0, %10 ], [ %31, %29 ]
%18 = add nsw i64 %17, %13
%19 = mul nsw i64 %18, %14
br label %20
20: ; preds = %16, %20
%21 = phi i64 [ 0, %16 ], [ %27, %20 ]
%22 = add nsw i64 %21, %19
%23 = getelementptr inbounds float, float* %0, i64 %22
%24 = load float, float* %23
%25 = fpext float %24 to double
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %25)
%27 = add nuw nsw i64 %21, 1
%28 = icmp eq i64 %27, %15
br i1 %28, label %29, label %20
29: ; preds = %20
%30 = call i32 @fputc(i32 10, i32* %8)
%31 = add nuw nsw i64 %17, 1
%32 = icmp eq i64 %31, %15
br i1 %32, label %33, label %16
33: ; preds = %29, %3
%34 = call i32 @fclose(i32* %8)
ret void
}