#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 printmatrix(char *name, double *A, int m, int n, int sparse) {
  int i, j;
  printf("%s = [...\n", name);
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++)
      if ((sparse == 1) && (A[i + j * m] == 0))
        printf("         0");
      else
        printf("  % 9.4f", A[i + j * m]);
    printf(",\n");
  }
  printf("];\n");
}


x86 assembly (clang, -O0):
<printmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ff <printmatrix+0xef>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e3 <printmatrix+0xd3>
cmpl   $0x1,-0x1c(%rbp)
jne    11aa <printmatrix+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11aa <printmatrix+0x9a>
jp     11aa <printmatrix+0x9a>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <printmatrix+0xc0>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11d5 <printmatrix+0xc5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1156 <printmatrix+0x46>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <printmatrix+0x33>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %ecx,0xc(%rsp)
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rsi
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11f0 <printmatrix+0xd0>
mov    %ebp,%eax
mov    0xc(%rsp),%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%r14
lea    0xeaa(%rip),%rbp
xor    %r13d,%r13d
jmp    119d <printmatrix+0x7d>
nopl   0x0(%rax)
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r13
addq   $0x8,0x10(%rsp)
cmp    0x20(%rsp),%r13
je     11f0 <printmatrix+0xd0>
cmpl   $0x0,0xc(%rsp)
jle    1180 <printmatrix+0x60>
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r12
jmp    11c9 <printmatrix+0xa9>
movsd  (%r12),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    %r14,%r12
add    $0xffffffffffffffff,%r15
je     1180 <printmatrix+0x60>
cmp    $0x1,%ebx
jne    11b0 <printmatrix+0x90>
movsd  (%r12),%xmm0
ucomisd 0xe24(%rip),%xmm0
jne    11b0 <printmatrix+0x90>
jp     11b0 <printmatrix+0x90>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <printmatrix+0xa0>
lea    0xe30(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

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