#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*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
double *mat(int m, int n) {
  double *p = NULL;
  if (m < 0 || n < 0) {
    printf("cant be zero!\n");
    return NULL;
  }
  p = (double *)malloc(m * n * sizeof(double));
  if (!p) {
    printf("allocate error!\n");
    return NULL;
  }
  memset(p, 0, sizeof(double) * m * n);
  return p;
}


x86 assembly (clang, -O0):
<mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     115a <mat+0x2a>
cmpl   $0x0,-0x10(%rbp)
jge    1173 <mat+0x43>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <mat+0xa4>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11af <mat+0x7f>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <mat+0xa4>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
movslq -0x10(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
or     %edi,%eax
js     115f <mat+0x2f>
mov    %edi,%ebx
imul   %esi,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1168 <mat+0x38>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
jmp    1177 <mat+0x47>
lea    0xeaa(%rip),%rdi
jmp    116f <mat+0x3f>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"cant be zero!\0A\00"
@.str.1 = [17 x i8] c"allocate error!\0A\00"
define double* @mat(i32 %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
store i32 %0, i32* %4
store i32 %1, i32* %5
store double* null, double** %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store double* null, double** %3
br label %38
14: ; preds = %9
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = mul nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to double*
store double* %22, double** %6
%23 = load double*, double** %6
%24 = icmp ne double* %23, null
br i1 %24, label %27, label %25
25: ; preds = %14
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store double* null, double** %3
br label %38
27: ; preds = %14
%28 = load double*, double** %6
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = mul i64 %31, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @memset(double* %28, i32 0, i32 %35)
%37 = load double*, double** %6
store double* %37, double** %3
br label %38
38: ; preds = %27, %25, %12
%39 = load double*, double** %3
ret double* %39
}

LLVM IR (-O2):
@str = [16 x i8] c"allocate error!\00"
@str.2 = [14 x i8] c"cant be zero!\00"
define double* @mat(i32 %0, i32 %1) {
%3 = or i32 %1, %0
%4 = icmp sgt i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.2, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = shl i32 %0, 3
%9 = mul i32 %8, %1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %7
%16 = tail call i32 @memset(double* %11, i32 0, i32 %9)
br label %17
17: ; preds = %15, %13, %5
%18 = phi double* [ null, %5 ], [ %11, %15 ], [ null, %13 ]
ret double* %18
}