#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(unsigned int);
int /*<<< orphan*/ read_ascii_data(char const *, unsigned int, unsigned int,
                                   double *);
int scan_ascii_matrix(char const *, unsigned int *, unsigned int *);
int read_ascii_matrix(const char *fname, unsigned *pnrows, unsigned *pncols,
                      double **matdata) {
  int res;
  res = scan_ascii_matrix(fname, pnrows, pncols);
  if (res)
    return res;
  *matdata = (double *)malloc((*pnrows) * (*pncols) * sizeof(double));
  read_ascii_data(fname, *pnrows, *pncols, *matdata);
  return res;
}


x86 assembly (clang, -O0):
<read_ascii_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <scan_ascii_matrix@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1171 <read_ascii_matrix+0x41>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <read_ascii_matrix+0x87>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
call   1050 <read_ascii_data@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ascii_matrix>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
call   1040 <scan_ascii_matrix@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1176 <read_ascii_matrix+0x46>
mov    0x0(%r13),%edi
imul   (%r15),%edi
shl    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12)
mov    0x0(%r13),%esi
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rax,%rcx
call   1050 <read_ascii_data@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @read_ascii_matrix(i8* %0, i32* %1, i32* %2, double** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca double**
%10 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store double** %3, double*** %9
%11 = load i8*, i8** %6
%12 = load i32*, i32** %7
%13 = load i32*, i32** %8
%14 = call i32 @scan_ascii_matrix(i8* %11, i32* %12, i32* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %10
store i32 %18, i32* %5
br label %40
19: ; preds = %4
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = mul i32 %21, %23
%25 = zext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to double*
%30 = load double**, double*** %9
store double* %29, double** %30
%31 = load i8*, i8** %6
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = load i32*, i32** %8
%35 = load i32, i32* %34
%36 = load double**, double*** %9
%37 = load double*, double** %36
%38 = call i32 @read_ascii_data(i8* %31, i32 %33, i32 %35, double* %37)
%39 = load i32, i32* %10
store i32 %39, i32* %5
br label %40
40: ; preds = %19, %17
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @read_ascii_matrix(i8* %0, i32* %1, i32* %2, double** nocapture writeonly %3) {
%5 = tail call i32 @scan_ascii_matrix(i8* %0, i32* %1, i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = shl i32 %8, 3
%11 = mul i32 %10, %9
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %3
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = tail call i32 @read_ascii_data(i8* %0, i32 %14, i32 %15, double* %13)
br label %17
17: ; preds = %4, %7
ret i32 %5
}