char **cmatrix(nsam, len)
int nsam, len;
{
  int i;
  char **m;
  if (!(m = (char **)malloc((unsigned)(nsam * sizeof(char *)))))
    perror("alloc error in cmatrix");
  for (i = 0; i < nsam; i++) {
    if (!(m[i] = (char *)malloc((unsigned)(len * sizeof(char)))))
      perror("alloc error in cmatric. 2");
  }
  return (m);
}


x86 assembly (clang, -O0):
<cmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%eax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115b <cmatrix+0x3b>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <perror@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b6 <cmatrix+0x96>
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%eax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    -0x18(%rbp),%rcx
movslq -0xc(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11a3 <cmatrix+0x83>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <perror@plt>
jmp    11a8 <cmatrix+0x88>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <cmatrix+0x42>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmatrix>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     114a <cmatrix+0x2a>
test   %r15d,%r15d
jg     115d <cmatrix+0x3d>
jmp    1196 <cmatrix+0x76>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <perror@plt>
test   %r15d,%r15d
jle    1196 <cmatrix+0x76>
mov    %ebx,%r12d
mov    %r15d,%r13d
lea    0xead(%rip),%r15
xor    %ebx,%ebx
jmp    1179 <cmatrix+0x59>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r13
je     1196 <cmatrix+0x76>
mov    %r12,%rdi
call   1030 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
jne    1170 <cmatrix+0x50>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <perror@plt>
jmp    1170 <cmatrix+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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 i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = zext i32 %10 to i64
%12 = call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to i8**
store i8** %13, i8*** %6
%14 = icmp ne i8** %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
store i32 0, i32* %5
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = zext i32 %26 to i64
%28 = call i8* @malloc(i64 %27)
%29 = load i8**, i8*** %6
%30 = load i32, i32* %5
%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 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %18
40: ; preds = %18
%41 = load i8**, i8*** %6
ret i8** %41
}

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 = zext i32 %3 to i64
%5 = tail call i8* @malloc(i64 %4)
%6 = bitcast i8* %5 to i8**
%7 = icmp eq i8* %5, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %25
12: ; preds = %10
%13 = zext i32 %1 to i64
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %12, %22
%16 = phi i64 [ 0, %12 ], [ %23, %22 ]
%17 = tail call i8* @malloc(i64 %13)
%18 = getelementptr inbounds i8*, i8** %6, i64 %16
store i8* %17, i8** %18
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %15, %20
%23 = add nuw nsw i64 %16, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %25, label %15
25: ; preds = %22, %10
ret i8** %6
}