#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 *, ...);
scalar_t__ strlen(char *);
void print_matrix(double *mat, int row, int col, char *premsg) {
  if (row < 0 || col < 0) {
    printf("***print_matrix wrong input arguments for the row and col ***");
    return;
  }
  int i, j;
  if (strlen(premsg) != 0) {
    printf("%s\n", premsg);
  }
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      printf("%12.5lf ", mat[i + j * col]);
    }
    printf("\n");
  }
}


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)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     114a <print_matrix+0x2a>
cmpl   $0x0,-0x10(%rbp)
jge    115d <print_matrix+0x3d>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <print_matrix+0xd8>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1182 <print_matrix+0x62>
mov    -0x18(%rbp),%rsi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f8 <print_matrix+0xd8>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11dc <print_matrix+0xbc>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x10(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe7b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119c <print_matrix+0x7c>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <print_matrix+0x69>
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    $0x18,%rsp
mov    %edx,0x4(%rsp)
mov    %edx,%eax
or     %esi,%eax
js     11e9 <print_matrix+0xb9>
mov    %esi,%ebp
mov    %rdi,%r12
cmpb   $0x0,(%rcx)
je     115e <print_matrix+0x2e>
mov    %rcx,%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    11da <print_matrix+0xaa>
movslq 0x4(%rsp),%rbx
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
mov    %ebx,%eax
mov    %rax,0x8(%rsp)
shl    $0x3,%rbx
xor    %r13d,%r13d
lea    0xebb(%rip),%rbp
jmp    11a9 <print_matrix+0x79>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
add    $0x8,%r12
cmp    0x10(%rsp),%r13
je     11da <print_matrix+0xaa>
cmpl   $0x0,0x4(%rsp)
jle    1190 <print_matrix+0x60>
mov    0x8(%rsp),%r14
mov    %r12,%r15
nopl   0x0(%rax,%rax,1)
movsd  (%r15),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    %rbx,%r15
add    $0xffffffffffffffff,%r14
jne    11c0 <print_matrix+0x90>
jmp    1190 <print_matrix+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe10(%rip),%rdi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [62 x i8] c"***print_matrix wrong input arguments for the row and col ***\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [9 x i8] c"%12.5lf \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_matrix(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %4
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13, %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %54
18: ; preds = %13
%19 = load i8*, i8** %8
%20 = call i64 @strlen(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %18
store i32 0, i32* %9
br label %26
26: ; preds = %51, %25
%27 = load i32, i32* %9
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %54
30: ; preds = %26
store i32 0, i32* %10
br label %31
31: ; preds = %46, %30
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = load double*, double** %5
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = load i32, i32* %7
%40 = mul nsw i32 %38, %39
%41 = add nsw i32 %37, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %36, i64 %42
%44 = load double, double* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %44)
br label %46
46: ; preds = %35
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %31
49: ; preds = %31
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %26
54: ; preds = %16, %26
ret void
}

LLVM IR (-O2):
@.str = [62 x i8] c"***print_matrix wrong input arguments for the row and col ***\00"
@.str.2 = [9 x i8] c"%12.5lf \00"
define void @print_matrix(double* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = or i32 %2, %1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %36
9: ; preds = %4
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @puts(i8* %3)
br label %14
14: ; preds = %12, %9
%15 = icmp sgt i32 %1, 0
br i1 %15, label %16, label %36
16: ; preds = %14
%17 = icmp sgt i32 %2, 0
%18 = sext i32 %2 to i64
%19 = zext i32 %1 to i64
%20 = zext i32 %2 to i64
br label %21
21: ; preds = %16, %32
%22 = phi i64 [ 0, %16 ], [ %34, %32 ]
br i1 %17, label %23, label %32
23: ; preds = %21, %23
%24 = phi i64 [ %30, %23 ], [ 0, %21 ]
%25 = mul nsw i64 %24, %18
%26 = add nsw i64 %25, %22
%27 = getelementptr inbounds double, double* %0, i64 %26
%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)
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %20
br i1 %31, label %32, label %23
32: ; preds = %23, %21
%33 = tail call i32 @putchar(i32 10)
%34 = add nuw nsw i64 %22, 1
%35 = icmp eq i64 %34, %19
br i1 %35, label %36, label %21
36: ; preds = %32, %14, %7
ret void
}