#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(unsigned int);
int /*<<< orphan*/ perror(char *);
char **cmatrix(int nsam, int len) {
  int i;
  char **m;
  if (!(m = (char **)malloc((unsigned)(nsam * sizeof(char *))))) {
    perror("alloc error in cmatrix");
    return NULL;
  }
  for (i = 0; i < nsam; i++) {
    if (!(m[i] = (char *)malloc((unsigned)(len * sizeof(char))))) {
      perror("alloc error in cmatric. 2");
      return NULL;
    }
  }
  return (m);
}


x86 assembly (clang, -O0):
<cmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1164 <cmatrix+0x44>
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d0 <cmatrix+0xb0>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c8 <cmatrix+0xa8>
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    -0x20(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11b5 <cmatrix+0x95>
lea    0xe74(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d0 <cmatrix+0xb0>
jmp    11ba <cmatrix+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <cmatrix+0x4b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1186 <cmatrix+0x66>
mov    %rax,%r12
test   %r14d,%r14d
jle    117a <cmatrix+0x5a>
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xec3(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     118d <cmatrix+0x6d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <cmatrix+0x40>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe73(%rip),%r14
mov    %r14,%rdi
call   1040 <perror@plt>
xor    %r12d,%r12d
jmp    117a <cmatrix+0x5a>

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

LLVM IR (-O2):
@.str = [23 x i8] c"alloc error in cmatrix\00"
@.str.1 = [26 x i8] c"alloc error in cmatric. 2\00"
define i8** @cmatrix(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8**
%6 = icmp eq i64 %4, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %23
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %13
11: ; preds = %13
%12 = icmp eq i64 %19, %10
br i1 %12, label %23, label %13
13: ; preds = %9, %11
%14 = phi i64 [ 0, %9 ], [ %19, %11 ]
%15 = tail call i64 @malloc(i32 %1)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds i8*, i8** %5, i64 %14
store i8* %16, i8** %17
%18 = icmp eq i64 %15, 0
%19 = add nuw nsw i64 %14, 1
br i1 %18, label %20, label %11
20: ; preds = %13, %2
%21 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %13 ]
%22 = tail call i32 @perror(i8* %21)
br label %23
23: ; preds = %11, %20, %7
%24 = phi i8** [ %5, %7 ], [ null, %20 ], [ %5, %11 ]
ret i8** %24
}