#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 print_mat(float *mat, int width, int height) {
  printf("np.array([");
  for (int i = 0; i < width; i++) {
    printf("[");
    for (int j = 0; j < height; j++) {
      if (j == height - 1) {
        printf(" %.4f", mat[i * height + j]);
      } else {
        printf(" %.4f,", mat[i * height + j]);
      }
    }
    if (i == width - 1) {
      printf("]");
    } else {
      printf("],\n");
    }
  }
  printf("])\n");
}


x86 assembly (clang, -O0):
<print_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1222 <print_mat+0x112>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11dd <print_mat+0xcd>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11a2 <print_mat+0x92>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe75(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11ca <print_mat+0xba>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe4e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11cf <print_mat+0xbf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1158 <print_mat+0x48>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1201 <print_mat+0xf1>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <print_mat+0xff>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <print_mat+0x104>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <print_mat+0x27>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,(%rsp)
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    121f <print_mat+0xef>
mov    (%rsp),%rax
lea    -0x1(%rax),%ebp
lea    -0x1(%r15),%ecx
mov    %rcx,0x18(%rsp)
cltq
mov    %r15d,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r14d
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
lea    0xe7c(%rip),%r15
lea    0xe7b(%rip),%rax
jmp    11bf <print_mat+0x8f>
nopl   0x0(%rax,%rax,1)
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rax
add    $0x1,%r12
add    0x10(%rsp),%rbx
cmp    0x8(%rsp),%r12
je     121f <print_mat+0xef>
mov    %r12,0x20(%rsp)
mov    %rax,%r12
mov    $0x5b,%edi
call   1030 <putchar@plt>
cmpl   $0x0,(%rsp)
jle    1204 <print_mat+0xd4>
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
cmp    %r13,%rbp
mov    %r12,%rdi
cmove  %r15,%rdi
movss  (%rbx,%r13,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11e0 <print_mat+0xb0>
mov    %r12,%r13
mov    0x20(%rsp),%r12
cmp    0x18(%rsp),%r12
jne    11a0 <print_mat+0x70>
mov    $0x5d,%edi
call   1030 <putchar@plt>
jmp    11ac <print_mat+0x7c>
lea    0xdf2(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

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

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