#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 *, ...);
void printmat(int N, int M, double *A, char *title) {
  int i, j;
  printf("%s\n", title);
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++)
      printf("%8.2f ", A[i + j * N]);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<printmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ae <printmat+0x9e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1192 <printmat+0x82>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x4(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe87(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1152 <printmat+0x42>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <printmat+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %esi,0x4(%rsp)
mov    %edi,%ebp
mov    %rcx,%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    11cb <printmat+0x9b>
mov    %ebp,%eax
mov    0x4(%rsp),%ecx
mov    %rcx,0x8(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%rbx
xor    %r12d,%r12d
lea    0xe8b(%rip),%rbp
jmp    1199 <printmat+0x69>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    $0x8,%r15
cmp    0x10(%rsp),%r12
je     11cb <printmat+0x9b>
cmpl   $0x0,0x4(%rsp)
jle    1180 <printmat+0x50>
mov    0x8(%rsp),%r14
mov    %r15,%r13
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    %rbx,%r13
add    $0xffffffffffffffff,%r14
jne    11b0 <printmat+0x80>
jmp    1180 <printmat+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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