#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void prtdata(int nx, int ny, int ts, double *u1, char *fname) {
  int ix, iy;
  FILE *fp;
  char ffname[100];
  sprintf(ffname, "output/%s%d.csv", fname, ts);
  fp = fopen(ffname, "w");
  if (fp != NULL) {
    for (iy = ny - 1; iy >= 0; iy--) {
      for (ix = 0; ix <= nx - 1; ix++) {
        fprintf(fp, "%8.3f,", *(u1 + ix * ny + iy));
        if (ix != nx - 1) {
          fprintf(fp, " ");
        } else {
          fprintf(fp, "\n");
        }
      }
    }
  }
  fflush(fp);
  fclose(fp);
  printf(" %s\n", ffname);
}


x86 assembly (clang, -O0):
<prtdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe6f(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1278 <prtdata+0x118>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1273 <prtdata+0x113>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1260 <prtdata+0x100>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x8(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe06(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     123b <prtdata+0xdb>
mov    -0x30(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    124d <prtdata+0xed>
mov    -0x30(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1252 <prtdata+0xf2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d2 <prtdata+0x72>
jmp    1265 <prtdata+0x105>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11c1 <prtdata+0x61>
jmp    1278 <prtdata+0x118>
mov    -0x30(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prtdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rcx,%r15
mov    %edx,%ecx
mov    %esi,%r12d
mov    %rdi,(%rsp)
lea    0xe6c(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r8,%rdx
call   1090 <sprintf@plt>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126a <prtdata+0xfa>
test   %r12d,%r12d
jle    126a <prtdata+0xfa>
mov    (%rsp),%rax
lea    -0x1(%rax),%ecx
mov    %rcx,0x18(%rsp)
mov    %r12d,%ecx
mov    %eax,%r12d
lea    -0x8(%r15,%rcx,8),%rax
mov    %rax,0x8(%rsp)
lea    0x0(,%rcx,8),%rbp
lea    0xe1f(%rip),%r13
jmp    1218 <prtdata+0xa8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%rcx
lea    -0x1(%rcx),%rax
addq   $0xfffffffffffffff8,0x8(%rsp)
cmp    $0x2,%rcx
mov    %rax,%rcx
jl     126a <prtdata+0xfa>
mov    %rcx,0x10(%rsp)
cmpl   $0x0,(%rsp)
jle    1200 <prtdata+0x90>
mov    0x8(%rsp),%r15
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movsd  (%r15),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
cmp    %r14,0x18(%rsp)
mov    $0x20,%edi
mov    $0xa,%eax
cmove  %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r14
add    %rbp,%r15
cmp    %r14,%r12
jne    1230 <prtdata+0xc0>
jmp    1200 <prtdata+0x90>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd98(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1040 <printf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"output/%s%d.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%8.3f,\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [5 x i8] c" %s\0A\00"
define void @prtdata(i32 %0, i32 %1, i32 %2, double* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [100 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double* %3, double** %9
store i8* %4, i8** %10
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%16 = load i8*, i8** %10
%17 = load i32, i32* %8
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %13
%21 = load i32*, i32** %13
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %67
23: ; preds = %5
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %12
br label %26
26: ; preds = %63, %23
%27 = load i32, i32* %12
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %66
29: ; preds = %26
store i32 0, i32* %11
br label %30
30: ; preds = %59, %29
%31 = load i32, i32* %11
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
%34 = icmp sle i32 %31, %33
br i1 %34, label %35, label %62
35: ; preds = %30
%36 = load i32*, i32** %13
%37 = load double*, double** %9
%38 = load i32, i32* %11
%39 = load i32, i32* %7
%40 = mul nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %46)
%48 = load i32, i32* %11
%49 = load i32, i32* %6
%50 = sub nsw i32 %49, 1
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %55
52: ; preds = %35
%53 = load i32*, i32** %13
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %58
55: ; preds = %35
%56 = load i32*, i32** %13
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
br label %59
59: ; preds = %58
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %30
62: ; preds = %30
br label %63
63: ; preds = %62
%64 = load i32, i32* %12
%65 = add nsw i32 %64, -1
store i32 %65, i32* %12
br label %26
66: ; preds = %26
br label %67
67: ; preds = %66, %5
%68 = load i32*, i32** %13
%69 = call i32 @fflush(i32* %68)
%70 = load i32*, i32** %13
%71 = call i32 @fclose(i32* %70)
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %72)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"output/%s%d.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%8.3f,\00"
@.str.5 = [5 x i8] c" %s\0A\00"
define void @prtdata(i32 %0, i32 %1, i32 %2, double* nocapture %3, i8* %4) {
%6 = alloca [100 x i8]
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %2)
%9 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i32* %9, null
%11 = icmp sgt i32 %1, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %5
%14 = icmp sgt i32 %0, 0
%15 = add nsw i32 %0, -1
%16 = zext i32 %1 to i64
%17 = zext i32 %15 to i64
%18 = zext i32 %0 to i64
br label %21
19: ; preds = %26, %21
%20 = icmp sgt i64 %22, 1
br i1 %20, label %21, label %37
21: ; preds = %13, %19
%22 = phi i64 [ %16, %13 ], [ %23, %19 ]
%23 = add nsw i64 %22, -1
br i1 %14, label %24, label %19
24: ; preds = %21
%25 = getelementptr inbounds double, double* %3, i64 %23
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %35, %26 ]
%28 = mul nsw i64 %27, %16
%29 = getelementptr inbounds double, double* %25, i64 %28
%30 = load double, double* %29
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %30)
%32 = icmp eq i64 %27, %17
%33 = select i1 %32, i32 10, i32 32
%34 = tail call i32 @fputc(i32 %33, i32* %9)
%35 = add nuw nsw i64 %27, 1
%36 = icmp eq i64 %35, %18
br i1 %36, label %19, label %26
37: ; preds = %19, %5
%38 = tail call i32 @fflush(i32* %9)
%39 = tail call i32 @fclose(i32* %9)
%40 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %7)
ret void
}