#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 const *, ...);
void doubles_print_mat(const double *a, int nrows, int ncols, const char *fmt) {
  for (int i = 0; i < nrows * ncols; i++) {
    printf(fmt, a[i]);
    if ((i % ncols) == (ncols - 1))
      printf("\n");
  }
}


x86 assembly (clang, -O0):
<doubles_print_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    118d <doubles_print_mat+0x7d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    %eax,%edx
jne    117a <doubles_print_mat+0x6a>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117f <doubles_print_mat+0x6f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <doubles_print_mat+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_print_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
imul   %edx,%esi
test   %esi,%esi
jle    1180 <doubles_print_mat+0x60>
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rdi,%r15
lea    -0x1(%r12),%r13d
mov    %esi,%ebp
xor    %ebx,%ebx
jmp    1159 <doubles_print_mat+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1180 <doubles_print_mat+0x60>
movsd  (%r15,%rbx,8),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %ebx,%eax
cltd
idiv   %r12d
cmp    %r13d,%edx
jne    1150 <doubles_print_mat+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <doubles_print_mat+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @doubles_print_mat(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %33, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = mul nsw i32 %12, %13
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = load i8*, i8** %8
%18 = load double*, double** %5
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = call i32 (i8*, ...) @printf(i8* %17, double %22)
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = srem i32 %24, %25
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 1
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %32
30: ; preds = %16
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %10
36: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @doubles_print_mat(double* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = mul i32 %2, %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = add nsw i32 %2, -1
%9 = zext i32 %5 to i64
br label %11
10: ; preds = %21, %4
ret void
11: ; preds = %7, %21
%12 = phi i64 [ 0, %7 ], [ %22, %21 ]
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %3, double %14)
%16 = trunc i64 %12 to i32
%17 = srem i32 %16, %2
%18 = icmp eq i32 %17, %8
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = tail call i32 @putchar(i32 10)
br label %21
21: ; preds = %11, %19
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, %9
br i1 %23, label %10, label %11
}