#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*/ putchar(char);
void showmat(size_t nrows, size_t ncols, double *M) {
  int r, c;
  printf("M=[");
  for (r = 0; r < nrows; r++) {
    for (c = 0; c < ncols; c++) {
      printf("\t%+3.6f", M[c + r * ncols]);
      if (c == ncols - 1) {
        if (r == nrows - 1) {
          printf("];\n");
        } else {
          printf(";\n");
        }
      } else {
        putchar(',');
      }
    }
  }
}


x86 assembly (clang, -O0):
<showmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1213 <showmat+0xf3>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1200 <showmat+0xe0>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
imul   -0x10(%rbp),%rdx
add    %rdx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe78(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11e3 <showmat+0xc3>
movslq -0x1c(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11d0 <showmat+0xb0>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11de <showmat+0xbe>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ed <showmat+0xcd>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    11f2 <showmat+0xd2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115e <showmat+0x3e>
jmp    1205 <showmat+0xe5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <showmat+0x29>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,(%rsp)
test   %rbp,%rbp
je     11fe <showmat+0xce>
lea    -0x1(%r14),%r15
mov    (%rsp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x10(%rsp)
lea    0x0(,%r14,8),%rax
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
lea    0xe7b(%rip),%r12
jmp    119f <showmat+0x6f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
add    0x8(%rsp),%rbx
cmp    (%rsp),%rbp
je     11fe <showmat+0xce>
test   %r14,%r14
je     1190 <showmat+0x60>
xor    %r13d,%r13d
jmp    11c3 <showmat+0x93>
nopl   0x0(%rax)
mov    $0x2c,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     1190 <showmat+0x60>
movsd  (%rbx,%r13,8),%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cmp    %r13,%r15
jne    11b0 <showmat+0x80>
cmp    %rbp,0x10(%rsp)
jne    11f0 <showmat+0xc0>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
jmp    11ba <showmat+0x8a>
nopl   (%rax)
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
jmp    11ba <showmat+0x8a>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"M=[\00"
@.str.1 = [8 x i8] c"\09%+3.6f\00"
@str = [2 x i8] c";\00"
@str.4 = [3 x i8] c"];\00"
define void @showmat(i64 %0, i64 %1, double* nocapture %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %0, 0
br i1 %5, label %35, label %6
6: ; preds = %3
%7 = icmp eq i64 %1, 0
%8 = add i64 %1, -1
%9 = add i64 %0, -1
br label %10
10: ; preds = %6, %32
%11 = phi i64 [ 0, %6 ], [ %33, %32 ]
br i1 %7, label %32, label %12
12: ; preds = %10
%13 = mul i64 %11, %1
%14 = icmp eq i64 %9, %11
br label %15
15: ; preds = %12, %29
%16 = phi i64 [ 0, %12 ], [ %30, %29 ]
%17 = add 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 ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = icmp eq i64 %8, %16
br i1 %21, label %22, label %27
22: ; preds = %15
br i1 %14, label %23, label %25
23: ; preds = %22
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.4, i64 0, i64 0))
br label %29
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %29
27: ; preds = %15
%28 = tail call i32 @putchar(i8 signext 44)
br label %29
29: ; preds = %27, %25, %23
%30 = add nuw i64 %16, 1
%31 = icmp eq i64 %30, %1
br i1 %31, label %32, label %15
32: ; preds = %29, %10
%33 = add nuw i64 %11, 1
%34 = icmp eq i64 %33, %0
br i1 %34, label %35, label %10
35: ; preds = %32, %3
ret void
}