#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 *, double const, char *);
void print_matrix(const double *x, const int nrows, const int ncols) {
  int k = 0;
  for (int i = 0; i < nrows; i++) {
    for (int j = 0; j < ncols; j++) {
      printf("%f%s", x[k], j == ncols - 1 ? "\n" : "\t");
      k++;
    }
  }
}


x86 assembly (clang, -O0):
<print_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <print_matrix+0x9f>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119c <print_matrix+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
lea    0xe9b(%rip),%rsi
lea    0xe92(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <print_matrix+0x33>
jmp    11a1 <print_matrix+0x91>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <print_matrix+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0xc(%rsp)
mov    %rdi,0x18(%rsp)
mov    %esi,0x10(%rsp)
test   %esi,%esi
jle    11c6 <print_matrix+0xb6>
mov    0xc(%rsp),%eax
mov    %eax,%ebp
neg    %ebp
xor    %eax,%eax
lea    0xec1(%rip),%r14
lea    0xebc(%rip),%r15
lea    0xeae(%rip),%rbx
xor    %ecx,%ecx
jmp    1169 <print_matrix+0x59>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%eax
cmp    0x10(%rsp),%eax
je     11c6 <print_matrix+0xb6>
cmpl   $0x0,0xc(%rsp)
jle    1160 <print_matrix+0x50>
mov    %rax,0x20(%rsp)
mov    %ecx,0x14(%rsp)
movslq %ecx,%rax
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%r13
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%eax
movsd  0x0(%r13,%r12,8),%xmm0
cmp    $0xffffffff,%eax
mov    %r15,%rsi
cmove  %r14,%rsi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%r12
mov    %r12d,%eax
add    %ebp,%eax
jne    1190 <print_matrix+0x80>
mov    0x14(%rsp),%ecx
add    %r12d,%ecx
mov    0x20(%rsp),%rax
jmp    1160 <print_matrix+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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