#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ scanf(char *, float *);
float **read_matrix(int m, int n) {
  int i, j;
  float **v;
  v = (float **)malloc(m * sizeof(float *));
  for (i = 0; i < m; i++) {
    v[i] = (float *)malloc(n * sizeof(float));
    for (j = 0; j < n; j++) {
      scanf("%f", &v[i][j]);
    }
  }
  return v;
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <read_matrix+0xa9>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b6 <read_matrix+0x96>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <read_matrix+0x59>
jmp    11bb <read_matrix+0x9b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <read_matrix+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x0(,%rbp,8),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11db <read_matrix+0xbb>
lea    0x0(,%r14,4),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%eax
mov    %rax,0x10(%rsp)
mov    %r14d,%eax
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
lea    0xe8d(%rip),%rbp
jmp    118b <read_matrix+0x6b>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r13
cmp    0x10(%rsp),%r13
je     11db <read_matrix+0xbb>
mov    0x4(%rsp),%edi
call   1030 <malloc@plt>
mov    %rax,(%rbx,%r13,8)
test   %r14d,%r14d
jle    1180 <read_matrix+0x60>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%r14d
je     1180 <read_matrix+0x60>
mov    $0x4,%r15d
mov    0x8(%rsp),%r12
nopl   0x0(%rax)
mov    (%rbx,%r13,8),%rsi
add    %r15,%rsi
mov    %rbp,%rdi
call   1040 <scanf@plt>
add    $0x4,%r15
add    $0xffffffffffffffff,%r12
jne    11c0 <read_matrix+0xa0>
jmp    1180 <read_matrix+0x60>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
define float** @read_matrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float**
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to float**
store float** %13, float*** %7
store i32 0, i32* %5
br label %14
14: ; preds = %47, %2
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to float*
%25 = load float**, float*** %7
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float*, float** %25, i64 %27
store float* %24, float** %28
store i32 0, i32* %6
br label %29
29: ; preds = %43, %18
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %46
33: ; preds = %29
%34 = load float**, float*** %7
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float*, float** %34, i64 %36
%38 = load float*, float** %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %29
46: ; preds = %29
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %14
50: ; preds = %14
%51 = load float**, float*** %7
ret float** %51
}

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