#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, int, double,
                           double);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
void write2file_fluid(int t, double *u, double *v, int M) {
  int i, j, z;
  FILE *fp1, *fp2, *fp3, *fp4;
  char fname1[1000], fname2[1000], fname3[1000], fname4[1000];
  sprintf(fname4, "./datafiles_1.0.%d/velocity_%d.dat", 3, t);
  fp4 = fopen(fname4, "w");
  for (i = 0; i < M; i++) {
    for (j = 0; j < M; j++) {
      z = i * M + j;
      fprintf(fp4, "%d %d %le %le\n", j, i, u[z], v[z]);
    }
  }
  fclose(fp4);
}


x86 assembly (clang, -O0):
<write2file_fluid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1000,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x1000(%rbp),%rdi
mov    -0x4(%rbp),%ecx
lea    0xe96(%rip),%rsi
mov    $0x3,%edx
call   1060 <sprintf@plt>
lea    -0x1000(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <write2file_fluid+0xcf>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11fc <write2file_fluid+0xbc>
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rsi
movsd  (%rax,%rsi,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rsi
movsd  (%rax,%rsi,8),%xmm1
lea    0xe3c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a5 <write2file_fluid+0x65>
jmp    1201 <write2file_fluid+0xc1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1192 <write2file_fluid+0x52>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1000,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write2file_fluid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ecx
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%edx
call   1060 <sprintf@plt>
lea    0xea8(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%r13
test   %ebp,%ebp
jle    1202 <write2file_fluid+0xc2>
mov    %ebp,%edx
lea    0x0(,%rdx,8),%rax
mov    %rax,(%rsp)
xor    %r12d,%r12d
lea    0xe83(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %rbx,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,8),%xmm0
movsd  (%r15,%rbp,8),%xmm1
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rdx,%rbx
mov    %ebp,%edx
mov    %r12d,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdx
mov    0x8(%rsp),%rbx
add    $0x1,%rbp
cmp    %rbp,%rdx
jne    11c0 <write2file_fluid+0x80>
add    $0x1,%r12
mov    (%rsp),%rax
add    %rax,%rbx
add    %rax,%r15
cmp    %rdx,%r12
jne    11b0 <write2file_fluid+0x70>
mov    %r13,%rdi
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [35 x i8] c"./datafiles_1.0.%d/velocity_%d.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"%d %d %le %le\0A\00"
define void @write2file_fluid(i32 %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = alloca [1000 x i8]
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 3, i32 %0)
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %31
10: ; preds = %4
%11 = zext i32 %3 to i64
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %28, %10
%14 = phi i64 [ 0, %10 ], [ %29, %28 ]
%15 = mul nsw i64 %14, %11
%16 = trunc i64 %14 to i32
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %26, %17 ]
%19 = add nuw nsw i64 %18, %15
%20 = getelementptr inbounds double, double* %1, i64 %19
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %2, i64 %19
%23 = load double, double* %22
%24 = trunc i64 %18 to i32
%25 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %16, double %21, double %23)
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %17
28: ; preds = %17
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %13
31: ; preds = %28, %4
%32 = tail call i32 @fclose(i32* %8)
ret void
}