#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*/ printf(char *);
extern int *imat(int n, int m) {
  int *p;
  if (n <= 0 || m <= 0)
    return NULL;
  if (!(p = (int *)malloc(sizeof(int) * n * m))) {
    printf("allocate memory error!\n");
    return NULL;
  }
  return p;
}


x86 assembly (clang, -O0):
<imat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1142 <imat+0x22>
cmpl   $0x0,-0x10(%rbp)
jg     114f <imat+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1195 <imat+0x75>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0x10(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118d <imat+0x6d>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1195 <imat+0x75>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imat>:
push   %rax
xor    %eax,%eax
test   %edi,%edi
jle    113b <imat+0x1b>
test   %esi,%esi
jle    113b <imat+0x1b>
imul   %esi,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     113d <imat+0x1d>
pop    %rcx
ret
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"allocate memory error!\0A\00"
define i32* @imat(i32 %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32* null, i32** %3
br label %28
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = mul i64 %16, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %26, label %24
24: ; preds = %13
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %28
26: ; preds = %13
%27 = load i32*, i32** %6
store i32* %27, i32** %3
br label %28
28: ; preds = %26, %24, %12
%29 = load i32*, i32** %3
ret i32* %29
}

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