#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*/ IOHBTerminate(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ readHB_info(char const *, int *, int *, int *, char **,
                               int *);
int readHB_mat_double(char const *, int *, int *, double *);
int readHB_newmat_double(const char *filename, int *M, int *N, int *nonzeros,
                         int **colptr, int **rowind, double **val) {
  int Nrhs;
  char *Type;
  readHB_info(filename, M, N, nonzeros, &Type, &Nrhs);
  *colptr = (int *)malloc((*N + 1) * sizeof(int));
  if (*colptr == NULL)
    IOHBTerminate("Insufficient memory for colptr.\n");
  *rowind = (int *)malloc(*nonzeros * sizeof(int));
  if (*rowind == NULL)
    IOHBTerminate("Insufficient memory for rowind.\n");
  if (Type[0] == 'C') {
    *val = (double *)malloc(*nonzeros * sizeof(double) * 2);
    if (*val == NULL)
      IOHBTerminate("Insufficient memory for val.\n");
  } else {
    if (Type[0] != 'P') {
      *val = (double *)malloc(*nonzeros * sizeof(double));
      if (*val == NULL)
        IOHBTerminate("Insufficient memory for val.\n");
    }
  }
  return readHB_mat_double(filename, *colptr, *rowind, *val);
}


x86 assembly (clang, -O0):
<readHB_newmat_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1030 <readHB_info@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11bb <readHB_newmat_double+0x7b>
lea    0xe4a(%rip),%rdi
call   1040 <IOHBTerminate@plt>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11f1 <readHB_newmat_double+0xb1>
lea    0xe35(%rip),%rdi
call   1040 <IOHBTerminate@plt>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x43,%eax
jne    1240 <readHB_newmat_double+0x100>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    123b <readHB_newmat_double+0xfb>
lea    0xe0c(%rip),%rdi
call   1040 <IOHBTerminate@plt>
jmp    1290 <readHB_newmat_double+0x150>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
je     128b <readHB_newmat_double+0x14b>
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1286 <readHB_newmat_double+0x146>
lea    0xdc1(%rip),%rdi
call   1040 <IOHBTerminate@plt>
jmp    128b <readHB_newmat_double+0x14b>
jmp    1290 <readHB_newmat_double+0x150>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
mov    0x10(%rbp),%rax
mov    (%rax),%rcx
call   1050 <readHB_mat_double@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readHB_newmat_double>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rdi,%r12
mov    %rsp,%r8
lea    0xc(%rsp),%r9
call   1030 <readHB_info@plt>
mov    (%rbx),%eax
lea    0x4(,%rax,4),%edi
call   1060 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
jne    118b <readHB_newmat_double+0x4b>
lea    0xe7a(%rip),%rdi
call   1040 <IOHBTerminate@plt>
mov    0x0(%r13),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    11ab <readHB_newmat_double+0x6b>
lea    0xe7b(%rip),%rdi
call   1040 <IOHBTerminate@plt>
mov    0x40(%rsp),%rbx
mov    (%rsp),%rax
mov    (%rax),%al
cmp    $0x50,%al
je     11e7 <readHB_newmat_double+0xa7>
cmp    $0x43,%al
jne    11c7 <readHB_newmat_double+0x87>
mov    0x0(%r13),%edi
shl    $0x4,%edi
jmp    11ce <readHB_newmat_double+0x8e>
mov    0x0(%r13),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    11e7 <readHB_newmat_double+0xa7>
lea    0xe60(%rip),%rdi
call   1040 <IOHBTerminate@plt>
mov    (%r15),%rsi
mov    (%r14),%rdx
mov    (%rbx),%rcx
mov    %r12,%rdi
call   1050 <readHB_mat_double@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Insufficient memory for colptr.\0A\00"
@.str.1 = [33 x i8] c"Insufficient memory for rowind.\0A\00"
@.str.2 = [30 x i8] c"Insufficient memory for val.\0A\00"
define i32 @readHB_newmat_double(i8* %0, i32* %1, i32* %2, i32* %3, i32** %4, i32** %5, double** %6) {
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32**
%13 = alloca i32**
%14 = alloca double**
%15 = alloca i32
%16 = alloca i8*
store i8* %0, i8** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32** %4, i32*** %12
store i32** %5, i32*** %13
store double** %6, double*** %14
%17 = load i8*, i8** %8
%18 = load i32*, i32** %9
%19 = load i32*, i32** %10
%20 = load i32*, i32** %11
%21 = call i32 @readHB_info(i8* %17, i32* %18, i32* %19, i32* %20, i8** %16, i32* %15)
%22 = load i32*, i32** %10
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = load i32**, i32*** %12
store i32* %29, i32** %30
%31 = load i32**, i32*** %12
%32 = load i32*, i32** %31
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %7
%35 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %7
%37 = load i32*, i32** %11
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i32*
%44 = load i32**, i32*** %13
store i32* %43, i32** %44
%45 = load i32**, i32*** %13
%46 = load i32*, i32** %45
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %36
%49 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %36
%51 = load i8*, i8** %16
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 67
br i1 %55, label %56, label %72
56: ; preds = %50
%57 = load i32*, i32** %11
%58 = load i32, i32* %57
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 8
%61 = mul i64 %60, 2
%62 = trunc i64 %61 to i32
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to double*
%65 = load double**, double*** %14
store double* %64, double** %65
%66 = load double**, double*** %14
%67 = load double*, double** %66
%68 = icmp eq double* %67, null
br i1 %68, label %69, label %71
69: ; preds = %56
%70 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %71
71: ; preds = %69, %56
br label %94
72: ; preds = %50
%73 = load i8*, i8** %16
%74 = getelementptr inbounds i8, i8* %73, i64 0
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 80
br i1 %77, label %78, label %93
78: ; preds = %72
%79 = load i32*, i32** %11
%80 = load i32, i32* %79
%81 = sext i32 %80 to i64
%82 = mul i64 %81, 8
%83 = trunc i64 %82 to i32
%84 = call i64 @malloc(i32 %83)
%85 = inttoptr i64 %84 to double*
%86 = load double**, double*** %14
store double* %85, double** %86
%87 = load double**, double*** %14
%88 = load double*, double** %87
%89 = icmp eq double* %88, null
br i1 %89, label %90, label %92
90: ; preds = %78
%91 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %92
92: ; preds = %90, %78
br label %93
93: ; preds = %92, %72
br label %94
94: ; preds = %93, %71
%95 = load i8*, i8** %8
%96 = load i32**, i32*** %12
%97 = load i32*, i32** %96
%98 = load i32**, i32*** %13
%99 = load i32*, i32** %98
%100 = load double**, double*** %14
%101 = load double*, double** %100
%102 = call i32 @readHB_mat_double(i8* %95, i32* %97, i32* %99, double* %101)
ret i32 %102
}

LLVM IR (-O2):
@.str = [33 x i8] c"Insufficient memory for colptr.\0A\00"
@.str.1 = [33 x i8] c"Insufficient memory for rowind.\0A\00"
@.str.2 = [30 x i8] c"Insufficient memory for val.\0A\00"
define i32 @readHB_newmat_double(i8* %0, i32* %1, i32* %2, i32* %3, i32** nocapture %4, i32** nocapture %5, double** nocapture %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = bitcast i32* %8 to i8*
%11 = bitcast i8** %9 to i8*
%12 = call i32 @readHB_info(i8* %0, i32* %1, i32* %2, i32* %3, i8** %9, i32* %8)
%13 = load i32, i32* %2
%14 = shl i32 %13, 2
%15 = add i32 %14, 4
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %4
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %7
%20 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %7
%22 = load i32, i32* %3
%23 = shl i32 %22, 2
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %5
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
switch i8 %31, label %38 [
i8 67, label %32
i8 80, label %46
]
32: ; preds = %29
%33 = load i32, i32* %3
%34 = shl i32 %33, 4
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to double*
store double* %36, double** %6
%37 = icmp eq i64 %35, 0
br i1 %37, label %44, label %46
38: ; preds = %29
%39 = load i32, i32* %3
%40 = shl i32 %39, 3
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to double*
store double* %42, double** %6
%43 = icmp eq i64 %41, 0
br i1 %43, label %44, label %46
44: ; preds = %38, %32
%45 = call i32 @IOHBTerminate(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %29, %38, %32
%47 = load i32*, i32** %4
%48 = load i32*, i32** %5
%49 = load double*, double** %6
%50 = call i32 @readHB_mat_double(i8* %0, i32* %47, i32* %48, double* %49)
ret i32 %50
}