#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*/ convertftd(float *, size_t, double **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ sprintf(char *, char *, int, char);
void printfarray(float *array, size_t s0, size_t s1, char *comment,
                 char *filename, int decimals, char fmttype) {
  FILE *fp;
  double *d;
  size_t i, j;
  char fmt[20];
  sprintf(fmt, "%%-15.%d%c", decimals, fmttype);
  convertftd(array, s0 * s1, &d);
  fp = fopen(filename, "w");
  fprintf(fp, "%s", comment);
  for (i = 0; i < s0; i++) {
    for (j = 0; j < s1; j++) {
      fprintf(fp, fmt, d[i * s1 + j]);
    }
    fprintf(fp, "\n");
  }
  free(d);
  fclose(fp);
}


x86 assembly (clang, -O0):
<printfarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe6f(%rip),%rsi
movsbl 0x10(%rbp),%ecx
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
imul   -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <convertftd@plt>
mov    -0x28(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    125f <printfarray+0xff>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    123c <printfarray+0xdc>
mov    -0x38(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11f8 <printfarray+0x98>
mov    -0x38(%rbp),%rdi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11e2 <printfarray+0x82>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printfarray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl 0x70(%rsp),%ecx
lea    0xe57(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %r9d,%edx
call   10a0 <sprintf@plt>
mov    %rbp,(%rsp)
imul   %r14,%rbp
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <convertftd@plt>
lea    0xe36(%rip),%rsi
mov    %r13,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %r14,0x18(%rsp)
test   %r14,%r14
je     1273 <printfarray+0xf3>
mov    (%rsp),%rax
lea    0x0(,%rax,8),%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
lea    0x20(%rsp),%r12
xor    %r14d,%r14d
jmp    123d <printfarray+0xbd>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0x1,%r14
add    0x10(%rsp),%r13
cmp    0x18(%rsp),%r14
je     1273 <printfarray+0xf3>
cmpq   $0x0,(%rsp)
je     1220 <printfarray+0xa0>
mov    %r13,%rbp
mov    (%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
movsd  (%rax,%rbp,1),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
add    $0x8,%rbp
add    $0xffffffffffffffff,%r15
jne    1250 <printfarray+0xd0>
jmp    1220 <printfarray+0xa0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%%-15.%d%c\00"
@.str.1 = [2 x i8] c"w\00"
define void @printfarray(float* %0, i64 %1, i64 %2, i8* nocapture %3, i8* nocapture %4, i32 %5, i8 signext %6) {
%8 = alloca double*
%9 = alloca [20 x i8]
%10 = bitcast double** %8 to i8*
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5, i8 signext %6)
%13 = mul i64 %2, %1
%14 = call i32 @convertftd(float* %0, i64 %13, double** %8)
%15 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @fputs(i8* %3, i32* %15)
%17 = icmp eq i64 %1, 0
br i1 %17, label %37, label %18
18: ; preds = %7
%19 = icmp eq i64 %2, 0
br label %20
20: ; preds = %18, %33
%21 = phi i64 [ 0, %18 ], [ %35, %33 ]
br i1 %19, label %33, label %22
22: ; preds = %20
%23 = mul i64 %21, %2
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ 0, %22 ], [ %31, %24 ]
%26 = load double*, double** %8
%27 = add i64 %25, %23
%28 = getelementptr inbounds double, double* %26, i64 %27
%29 = load double, double* %28
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* %11, double %29)
%31 = add nuw i64 %25, 1
%32 = icmp eq i64 %31, %2
br i1 %32, label %33, label %24
33: ; preds = %24, %20
%34 = call i32 @fputc(i32 10, i32* %15)
%35 = add nuw i64 %21, 1
%36 = icmp eq i64 %35, %1
br i1 %36, label %37, label %20
37: ; preds = %33, %7
%38 = load double*, double** %8
%39 = call i32 @free(double* %38)
%40 = call i32 @fclose(i32* %15)
ret void
}