#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 */
double **allocMem(int, int);
int /*<<< orphan*/ scanf(char *, ...);
double **readMatrix(int *m, int *n) {
  scanf("%d %d", m, n);
  double **A = allocMem(*m, *n);
  for (int i = 0; i < *m; i++)
    for (int j = 0; j < *n; j++) {
      scanf("%lf", (A[i] + j));
    }
  return A;
}


x86 assembly (clang, -O0):
<readMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <scanf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <allocMem@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    11cd <readMatrix+0xad>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11ba <readMatrix+0x9a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <readMatrix+0x58>
jmp    11bf <readMatrix+0x9f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <readMatrix+0x42>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xec8(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <scanf@plt>
mov    (%rbx),%edi
mov    (%r15),%esi
call   1040 <allocMem@plt>
mov    %rax,%r13
mov    %rbx,(%rsp)
mov    (%rbx),%ecx
test   %ecx,%ecx
jle    11ba <readMatrix+0x9a>
mov    (%r15),%eax
lea    0xea0(%rip),%r12
xor    %ebx,%ebx
jmp    117c <readMatrix+0x5c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movslq %ecx,%rdx
cmp    %rdx,%rbx
jge    11ba <readMatrix+0x9a>
test   %eax,%eax
jle    1170 <readMatrix+0x50>
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,8),%rsi
add    %rbp,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <scanf@plt>
add    $0x1,%r14
movslq (%r15),%rax
add    $0x8,%rbp
cmp    %rax,%r14
jl     1190 <readMatrix+0x70>
mov    (%rsp),%rcx
mov    (%rcx),%ecx
jmp    1170 <readMatrix+0x50>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [4 x i8] c"%lf\00"
define double** @readMatrix(i32* %0, i32* %1) {
%3 = tail call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %0, i32* %1)
%4 = load i32, i32* %0
%5 = load i32, i32* %1
%6 = tail call double** @allocMem(i32 %4, i32 %5)
%7 = load i32, i32* %0
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i32, i32* %1
br label %11
11: ; preds = %9, %21
%12 = phi i32 [ %7, %9 ], [ %22, %21 ]
%13 = phi i32 [ %10, %9 ], [ %23, %21 ]
%14 = phi i64 [ 0, %9 ], [ %24, %21 ]
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = getelementptr inbounds double*, double** %6, i64 %14
br label %27
18: ; preds = %21, %2
ret double** %6
19: ; preds = %27
%20 = load i32, i32* %0
br label %21
21: ; preds = %19, %11
%22 = phi i32 [ %20, %19 ], [ %12, %11 ]
%23 = phi i32 [ %33, %19 ], [ %13, %11 ]
%24 = add nuw nsw i64 %14, 1
%25 = sext i32 %22 to i64
%26 = icmp slt i64 %24, %25
br i1 %26, label %11, label %18
27: ; preds = %16, %27
%28 = phi i64 [ 0, %16 ], [ %32, %27 ]
%29 = load double*, double** %17
%30 = getelementptr inbounds double, double* %29, i64 %28
%31 = tail call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %30)
%32 = add nuw nsw i64 %28, 1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %27, label %19
}