#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void printmatwfile(double *a, int m, int n, int w, FILE *fff) {
  int i, j, jmod;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      fprintf(fff, "%9.3f ", a[i * n + j]);
      jmod = (j + 1) % w;
      if ((jmod == 0) && (j < (n - 1))) {
        fprintf(fff, "  ...\n");
      }
    }
    fprintf(fff, "\n");
  }
}


x86 assembly (clang, -O0):
<printmatwfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e4 <printmatwfile+0xd4>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c4 <printmatwfile+0xb4>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe90(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11b1 <printmatwfile+0xa1>
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b1 <printmatwfile+0xa1>
mov    -0x20(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b6 <printmatwfile+0xa6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1143 <printmatwfile+0x33>
mov    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1130 <printmatwfile+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmatwfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,(%rsp)
test   %esi,%esi
jle    1211 <printmatwfile+0xe1>
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %rdi,%rbp
mov    (%rsp),%rcx
lea    -0x1(%rcx),%eax
cltq
mov    %rax,0x20(%rsp)
movslq %ecx,%rax
mov    %esi,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r12d
shl    $0x3,%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
jmp    11a2 <printmatwfile+0x72>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    0x18(%rsp),%rax
add    $0x1,%rax
add    0x10(%rsp),%rbp
cmp    0x8(%rsp),%rax
je     1211 <printmatwfile+0xe1>
mov    %rax,0x18(%rsp)
cmpl   $0x0,(%rsp)
jle    1180 <printmatwfile+0x50>
xor    %r13d,%r13d
jmp    11c5 <printmatwfile+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %r13,%r12
je     1180 <printmatwfile+0x50>
mov    %r13,%r14
movsd  0x0(%rbp,%r13,8),%xmm0
mov    %rbx,%rdi
lea    0xe27(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x1,%r13
mov    %r13d,%eax
cltd
idiv   %r15d
test   %edx,%edx
jne    11c0 <printmatwfile+0x90>
cmp    0x20(%rsp),%r14
jge    11c0 <printmatwfile+0x90>
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xe00(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
jmp    11c0 <printmatwfile+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%9.3f \00"
@.str.1 = [7 x i8] c" ...\0A\00"
define void @printmatwfile(double* nocapture %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %38
7: ; preds = %5
%8 = icmp sgt i32 %2, 0
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
%11 = sext i32 %2 to i64
%12 = zext i32 %1 to i64
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %7, %34
%15 = phi i64 [ 0, %7 ], [ %36, %34 ]
br i1 %8, label %16, label %34
16: ; preds = %14
%17 = mul nsw i64 %15, %11
br label %18
18: ; preds = %16, %32
%19 = phi i64 [ 0, %16 ], [ %24, %32 ]
%20 = add nsw i64 %19, %17
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %22)
%24 = add nuw nsw i64 %19, 1
%25 = trunc i64 %24 to i32
%26 = srem i32 %25, %3
%27 = icmp eq i32 %26, 0
%28 = icmp slt i64 %19, %10
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 6, i64 1, i32* %4)
br label %32
32: ; preds = %18, %30
%33 = icmp eq i64 %24, %13
br i1 %33, label %34, label %18
34: ; preds = %32, %14
%35 = tail call i32 @fputc(i32 10, i32* %4)
%36 = add nuw nsw i64 %15, 1
%37 = icmp eq i64 %36, %12
br i1 %37, label %38, label %14
38: ; preds = %34, %5
ret void
}