#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*/ fatalerr(char *, int, int);
scalar_t__ malloc(int);
extern int *imat(int n, int m) {
  int *p;
  if (n <= 0 || m <= 0)
    return NULL;
  if (!(p = (int *)malloc(sizeof(int) * n * m))) {
    fatalerr("integer matrix memory allocation error: n=%d,m=%d\n", n, m);
  }
  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    118e <imat+0x6e>
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    1186 <imat+0x66>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <fatalerr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imat>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %edi,%edi
jle    1158 <imat+0x38>
mov    %esi,%r14d
test   %esi,%esi
jle    1158 <imat+0x38>
mov    %edi,%ebp
imul   %r14d,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1158 <imat+0x38>
lea    0xeb2(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <fatalerr@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"integer matrix memory allocation error: n=%d,m=%d\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 %30
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 %28, label %24
24: ; preds = %13
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @fatalerr(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %13
%29 = load i32*, i32** %6
store i32* %29, i32** %3
br label %30
30: ; preds = %28, %12
%31 = load i32*, i32** %3
ret i32* %31
}

LLVM IR (-O2):
@.str = [51 x i8] c"integer matrix memory allocation error: n=%d,m=%d\0A\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 %14, label %6
6: ; preds = %2
%7 = shl i32 %0, 2
%8 = mul i32 %7, %1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @fatalerr(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %14
14: ; preds = %6, %12, %2
%15 = phi i32* [ null, %2 ], [ %10, %12 ], [ %10, %6 ]
ret i32* %15
}