#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*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int **my_malloc(int n, int m) {
  int i = 0;
  int **temp = NULL;
  temp = (int **)malloc(n * sizeof(int *));
  if (temp == NULL) {
    printf("分配错误1!\n");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    temp[i] = (int *)malloc(m * sizeof(int));
    if (temp[i] == NULL) {
      printf("分配错误2!\n");
      exit(1);
    }
  }
  return temp;
}


x86 assembly (clang, -O0):
<my_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <my_malloc+0x51>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ee <my_malloc+0xbe>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11db <my_malloc+0xab>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11e0 <my_malloc+0xb0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1188 <my_malloc+0x58>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_malloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11ac <my_malloc+0x7c>
mov    %rax,%r12
test   %r14d,%r14d
jle    118a <my_malloc+0x5a>
shl    $0x2,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     1196 <my_malloc+0x66>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <my_malloc+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe5c(%rip),%rdi
jmp    119d <my_malloc+0x6d>

LLVM IR (-O0):
@.str = [16 x i8] c"\E5\88\86\E9\85\8D\E9\94\99\E8\AF\AF1!\0A\00"
@.str.1 = [16 x i8] c"\E5\88\86\E9\85\8D\E9\94\99\E8\AF\AF2!\0A\00"
define i32** @my_malloc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32** null, i32*** %6
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %6
%13 = load i32**, i32*** %6
%14 = icmp eq i32** %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 0, i32* %5
br label %19
19: ; preds = %44, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = load i32, i32* %4
%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*** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
store i32* %29, i32** %33
%34 = load i32**, i32*** %6
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
%38 = load i32*, i32** %37
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %23
%41 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %23
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %19
47: ; preds = %19
%48 = load i32**, i32*** %6
ret i32** %48
}

LLVM IR (-O2):
@str = [15 x i8] c"\E5\88\86\E9\85\8D\E9\94\99\E8\AF\AF2!\00"
@str.2 = [15 x i8] c"\E5\88\86\E9\85\8D\E9\94\99\E8\AF\AF1!\00"
define i32** @my_malloc(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32**
%6 = icmp eq i64 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %27
9: ; preds = %7
%10 = shl i32 %1, 2
%11 = zext i32 %0 to i64
br label %17
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %23, %11
br i1 %16, label %27, label %17
17: ; preds = %9, %15
%18 = phi i64 [ 0, %9 ], [ %23, %15 ]
%19 = tail call i64 @malloc(i32 %10)
%20 = inttoptr i64 %19 to i32*
%21 = getelementptr inbounds i32*, i32** %5, i64 %18
store i32* %20, i32** %21
%22 = icmp eq i64 %19, 0
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %24, label %15
24: ; preds = %17
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %15, %7
ret i32** %5
}