#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 */
void *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettext(char *);
char *msg_error(char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
long **allocate_2d_array(int rows, int columns) {
  int i;
  long **array = NULL;
  array = calloc(rows, sizeof(long *));
  if (array == NULL)
    goto error;
  for (i = 0; i < rows; i++) {
    array[i] = calloc(columns, sizeof(long));
    if (array[i] == NULL)
      goto error;
  }
  return array;
error:
  fprintf(stderr,
          msg_error(
              "\x1b[1;31m",
              (strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/ShyPixie/"
                       "CPU-X/refs/heads/master/src/core.c",
                       '/')
                   ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                             "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                             "ShyPixie/CPU-X/refs/heads/master/src/core.c",
                             '/') +
                         1
                   : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/ShyPixie/CPU-X/refs/"
                     "heads/master/src/core.c"),
              610,
              gettext("failed to allocate memory for CPU usage calculation")));
  return NULL;
}


x86 assembly (clang, -O0):
<allocate_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <allocate_2d_array+0x37>
jmp    11ee <allocate_2d_array+0x9e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e1 <allocate_2d_array+0x91>
mov    -0x10(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11ce <allocate_2d_array+0x7e>
jmp    11ee <allocate_2d_array+0x9e>
jmp    11d3 <allocate_2d_array+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <allocate_2d_array+0x3e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1281 <allocate_2d_array+0x131>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe07(%rip),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
cmp    $0x0,%rax
je     1233 <allocate_2d_array+0xe3>
lea    0xdec(%rip),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1243 <allocate_2d_array+0xf3>
lea    0xdce(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1243 <allocate_2d_array+0xf3>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe3c(%rip),%rdi
call   1030 <gettext@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%ecx
lea    0xd9c(%rip),%rdi
mov    $0x262,%edx
call   1070 <msg_error@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_2d_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1191 <allocate_2d_array+0x51>
mov    %rax,%rbx
test   %r14d,%r14d
jle    11cc <allocate_2d_array+0x8c>
mov    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
test   %rax,%rax
je     1191 <allocate_2d_array+0x51>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1170 <allocate_2d_array+0x30>
jmp    11cc <allocate_2d_array+0x8c>
mov    0x2e48(%rip),%rax
mov    (%rax),%ebx
lea    0xeed(%rip),%rdi
call   1030 <gettext@plt>
lea    0xe53(%rip),%rdi
lea    0xed3(%rip),%rsi
mov    $0x262,%edx
mov    %eax,%ecx
call   1060 <msg_error@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [8 x i8] c"\1B[1;31m\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ShyPixie/CPU-X/refs/heads/master/src/core.c\00"
@.str.2 = [52 x i8] c"failed to allocate memory for CPU usage calculation\00"
define i64** @allocate_2d_array(i32 %0, i32 %1) {
%3 = alloca i64**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64**
store i32 %0, i32* %4
store i32 %1, i32* %5
store i64** null, i64*** %7
%8 = load i32, i32* %4
%9 = call i8* @calloc(i32 %8, i32 8)
%10 = bitcast i8* %9 to i64**
store i64** %10, i64*** %7
%11 = load i64**, i64*** %7
%12 = icmp eq i64** %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %40
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %35, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i32, i32* %5
%21 = call i8* @calloc(i32 %20, i32 8)
%22 = bitcast i8* %21 to i64*
%23 = load i64**, i64*** %7
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i64*, i64** %23, i64 %25
store i64* %22, i64** %26
%27 = load i64**, i64*** %7
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64*, i64** %27, i64 %29
%31 = load i64*, i64** %30
%32 = icmp eq i64* %31, null
br i1 %32, label %33, label %34
33: ; preds = %19
br label %40
34: ; preds = %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %15
38: ; preds = %15
%39 = load i64**, i64*** %7
store i64** %39, i64*** %3
br label %53
40: ; preds = %33, %13
%41 = load i32, i32* @stderr
%42 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%46 = getelementptr inbounds i8, i8* %45, i64 1
br label %48
47: ; preds = %40
br label %48
48: ; preds = %47, %44
%49 = phi i8* [ %46, %44 ], [ getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), %47 ]
%50 = call i32 @gettext(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%51 = call i8* @msg_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %49, i32 610, i32 %50)
%52 = call i32 @fprintf(i32 %41, i8* %51)
store i64** null, i64*** %3
br label %53
53: ; preds = %48, %38
%54 = load i64**, i64*** %3
ret i64** %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [8 x i8] c"\1B[1;31m\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ShyPixie/CPU-X/refs/heads/master/src/core.c\00"
@.str.2 = [52 x i8] c"failed to allocate memory for CPU usage calculation\00"
define noalias i64** @allocate_2d_array(i32 %0, i32 %1) {
%3 = tail call i8* @calloc(i32 %0, i32 8)
%4 = bitcast i8* %3 to i64**
%5 = icmp eq i8* %3, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %24
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %12
10: ; preds = %12
%11 = icmp eq i64 %18, %9
br i1 %11, label %24, label %12
12: ; preds = %8, %10
%13 = phi i64 [ 0, %8 ], [ %18, %10 ]
%14 = tail call i8* @calloc(i32 %1, i32 8)
%15 = getelementptr inbounds i64*, i64** %4, i64 %13
%16 = bitcast i64** %15 to i8**
store i8* %14, i8** %16
%17 = icmp eq i8* %14, null
%18 = add nuw nsw i64 %13, 1
br i1 %17, label %19, label %10
19: ; preds = %12, %2
%20 = load i32, i32* @stderr
%21 = tail call i32 @gettext(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i8* @msg_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 127), i32 610, i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* %22)
br label %24
24: ; preds = %10, %6, %19
%25 = phi i64** [ null, %19 ], [ %4, %6 ], [ %4, %10 ]
ret i64** %25
}