#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printmatw(double *, int, int, int);
void printmatwf(double *a, int m, int n, int w, char *format) {
  int i, j, jmod;
  if (format == NULL) {
    printmatw(a, m, n, w);
    return;
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      printf(format, a[i * n + j]);
      jmod = (j + 1) % w;
      if ((jmod == 0) && (j < (n - 1))) {
        printf("  ...\n");
      }
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<printmatwf>:
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)
cmpq   $0x0,-0x20(%rbp)
jne    115b <printmatwf+0x3b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <printmatw@plt>
jmp    1207 <printmatwf+0xe7>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1207 <printmatwf+0xe7>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11eb <printmatwf+0xcb>
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
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11d8 <printmatwf+0xb8>
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d8 <printmatwf+0xb8>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dd <printmatwf+0xbd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1175 <printmatwf+0x55>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <printmatwf+0x42>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmatwf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r15d
mov    %rdi,%rbp
test   %r8,%r8
je     121c <printmatwf+0xdc>
test   %esi,%esi
jle    120d <printmatwf+0xcd>
mov    %r8,%r13
lea    -0x1(%rdx),%eax
cltq
mov    %rax,0x20(%rsp)
movslq %edx,%rax
mov    %esi,%ecx
mov    %rcx,(%rsp)
mov    %eax,%r12d
shl    $0x3,%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rdx,0x10(%rsp)
jmp    11b3 <printmatwf+0x73>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%rax
add    $0x1,%rax
add    0x8(%rsp),%rbp
cmp    (%rsp),%rax
mov    0x10(%rsp),%rdx
je     120d <printmatwf+0xcd>
mov    %rax,0x18(%rsp)
test   %edx,%edx
jle    1190 <printmatwf+0x50>
xor    %r14d,%r14d
jmp    11d5 <printmatwf+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %r14,%r12
je     1190 <printmatwf+0x50>
mov    %r14,%rbx
movsd  0x0(%rbp,%r14,8),%xmm0
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%r14
mov    %r14d,%eax
cltd
idiv   %r15d
test   %edx,%edx
jne    11d0 <printmatwf+0x90>
cmp    0x20(%rsp),%rbx
jge    11d0 <printmatwf+0x90>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
jmp    11d0 <printmatwf+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r15d,%ecx
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printmatw@plt>

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

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