#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 dlange_(char *, int *, int *, double const *, int *, double *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double call_dlange(char norm, int m, int n, const double *a, int lda) {
  double res = 0.0;
  double *work = NULL;
  if (norm == 'I' || norm == 'i') {
    work = (double *)malloc(sizeof(double) * m);
    if (work == NULL) {
      fputs("ERROR: memory allocation (malloc) failed in call_dlange\n",
            stderr);
      return res;
    }
  }
  res = dlange_(&norm, &m, &n, a, &lda, work);
  if (work)
    free(work);
  return res;
}


x86 assembly (clang, -O0):
<call_dlange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x49,%eax
je     1186 <call_dlange+0x46>
movsbl -0x9(%rbp),%eax
cmp    $0x69,%eax
jne    11cd <call_dlange+0x8d>
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c8 <call_dlange+0x88>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1040 <fputs@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120d <call_dlange+0xcd>
jmp    11cd <call_dlange+0x8d>
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r9
lea    -0x9(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x24(%rbp),%r8
call   1060 <dlange_@plt>
movsd  %xmm0,-0x30(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1203 <call_dlange+0xc3>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dlange>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %dil,0x3(%rsp)
mov    %esi,0xc(%rsp)
mov    %edx,0x8(%rsp)
mov    %r8d,0x4(%rsp)
and    $0xdf,%dil
cmp    $0x49,%dil
jne    11ad <call_dlange+0x6d>
shl    $0x3,%esi
mov    %esi,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ce <call_dlange+0x8e>
mov    %rax,%rbx
lea    0x3(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%r8
mov    %r14,%rcx
mov    %rax,%r9
call   1060 <dlange_@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x10(%rsp),%xmm0
jmp    11e6 <call_dlange+0xa6>
lea    0x3(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%r8
mov    %r14,%rcx
xor    %r9d,%r9d
call   1060 <dlange_@plt>
jmp    11e6 <call_dlange+0xa6>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
call   1040 <fputs@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [57 x i8] c"ERROR: memory allocation (malloc) failed in call_dlange\0A\00"
@stderr = global i32 0
define double @call_dlange(i8 signext %0, i32 %1, i32 %2, double* %3, i32 %4) {
%6 = alloca double
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double*
store i8 %0, i8* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store i32 %4, i32* %11
store double 0.000000e+00, double* %12
store double* null, double** %13
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 73
br i1 %16, label %21, label %17
17: ; preds = %5
%18 = load i8, i8* %7
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 105
br i1 %20, label %21, label %35
21: ; preds = %17, %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = mul i64 8, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to double*
store double* %27, double** %13
%28 = load double*, double** %13
%29 = icmp eq double* %28, null
br i1 %29, label %30, label %34
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load double, double* %12
store double %33, double* %6
br label %46
34: ; preds = %21
br label %35
35: ; preds = %34, %17
%36 = load double*, double** %10
%37 = load double*, double** %13
%38 = call double @dlange_(i8* %7, i32* %8, i32* %9, double* %36, i32* %11, double* %37)
store double %38, double* %12
%39 = load double*, double** %13
%40 = icmp ne double* %39, null
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load double*, double** %13
%43 = call i32 @free(double* %42)
br label %44
44: ; preds = %41, %35
%45 = load double, double* %12
store double %45, double* %6
br label %46
46: ; preds = %44, %30
%47 = load double, double* %6
ret double %47
}

LLVM IR (-O2):
@.str = [57 x i8] c"ERROR: memory allocation (malloc) failed in call_dlange\0A\00"
@stderr = global i32 0
define double @call_dlange(i8 signext %0, i32 %1, i32 %2, double* %3, i32 %4) {
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8 %0, i8* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %4, i32* %9
%10 = and i8 %0, -33
%11 = icmp eq i8 %10, 73
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = call double @dlange_(i8* %6, i32* %7, i32* %8, double* %3, i32* %9, double* null)
br label %25
14: ; preds = %5
%15 = shl i32 %1, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %25
22: ; preds = %14
%23 = call double @dlange_(i8* %6, i32* %7, i32* %8, double* %3, i32* %9, double* %17)
%24 = call i32 @free(double* %17)
br label %25
25: ; preds = %12, %22, %19
%26 = phi double [ 0.000000e+00, %19 ], [ %23, %22 ], [ %13, %12 ]
ret double %26
}