#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__ calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int alloc_matrix(int num_rows, int num_cols, double ***ptr_x) {
  printf("allocating matrix\n");
  int status = 0;
  double **x = NULL;
  if (num_rows < 1) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 35,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/OPERATORS/MM/src/mm_helpers.c");
      };
      status = -1;
      goto BYE;
    };
  }
  if (num_cols < 1) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 36,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/OPERATORS/MM/src/mm_helpers.c");
      };
      status = -1;
      goto BYE;
    };
  }
  if ((num_rows == 1) && (num_cols == 1)) {
    {
      {
        fprintf(stderr, "Line %3d of File %s \n", 37,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/"
                "master/OPERATORS/MM/src/mm_helpers.c");
      };
      status = -1;
      goto BYE;
    };
  }
  x = (double **)calloc(num_cols, sizeof(double *));
  {
    if (x == NULL) {
      fprintf(stderr, "Unable to allocate memory\n");
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 39,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/OPERATORS/MM/src/mm_helpers.c");
        };
        status = -1;
        goto BYE;
      };
    }
  };
  for (int i = 0; i < num_cols; i++) {
    x[i] = (double *)calloc(num_rows, sizeof(double));
    {
      if (x[i] == NULL) {
        fprintf(stderr, "Unable to allocate memory\n");
        {
          {
            fprintf(stderr, "Line %3d of File %s \n", 42,
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                    "heads/master/OPERATORS/MM/src/mm_helpers.c");
          };
          status = -1;
          goto BYE;
        };
      }
    };
  }
  *ptr_x = x;
BYE:
  return status;
}


x86 assembly (clang, -O0):
<alloc_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    1196 <alloc_matrix+0x66>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    $0x23,%edx
lea    0xea6(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    131a <alloc_matrix+0x1ea>
cmpl   $0x1,-0x8(%rbp)
jge    11cf <alloc_matrix+0x9f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x24,%edx
lea    0xe6d(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    131a <alloc_matrix+0x1ea>
cmpl   $0x1,-0x4(%rbp)
jne    1212 <alloc_matrix+0xe2>
cmpl   $0x1,-0x8(%rbp)
jne    1212 <alloc_matrix+0xe2>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x25,%edx
lea    0xe2a(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    131a <alloc_matrix+0x1ea>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1274 <alloc_matrix+0x144>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0x27,%edx
lea    0xdc8(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    131a <alloc_matrix+0x1ea>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130f <alloc_matrix+0x1df>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    12fc <alloc_matrix+0x1cc>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
mov    $0x2a,%edx
lea    0xd40(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    131a <alloc_matrix+0x1ea>
jmp    1301 <alloc_matrix+0x1d1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127b <alloc_matrix+0x14b>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xf84(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jle    1181 <alloc_matrix+0x51>
test   %r15d,%r15d
jle    11a2 <alloc_matrix+0x72>
cmp    $0x1,%ebp
jne    11c3 <alloc_matrix+0x93>
cmp    $0x1,%r15d
jne    11c3 <alloc_matrix+0x93>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
lea    0xe9f(%rip),%rcx
mov    $0x25,%edx
jmp    125f <alloc_matrix+0x12f>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
lea    0xe7e(%rip),%rcx
mov    $0x23,%edx
jmp    125f <alloc_matrix+0x12f>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
lea    0xe5d(%rip),%rcx
mov    $0x24,%edx
jmp    125f <alloc_matrix+0x12f>
mov    %r15d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1205 <alloc_matrix+0xd5>
mov    %rax,%r12
mov    %r15d,%r15d
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebp,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%r12,%rbx,8)
test   %rax,%rax
je     1233 <alloc_matrix+0x103>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <alloc_matrix+0xb0>
mov    %r12,(%r14)
xor    %eax,%eax
jmp    126b <alloc_matrix+0x13b>
mov    0x2dd4(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xddb(%rip),%rsi
lea    0xdea(%rip),%rcx
mov    $0x27,%edx
jmp    125f <alloc_matrix+0x12f>
mov    0x2da6(%rip),%rbx
mov    (%rbx),%edi
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdad(%rip),%rsi
lea    0xdbc(%rip),%rcx
mov    $0x2a,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"allocating matrix\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.2 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/OPERATORS/MM/src/mm_helpers.c\00"
@.str.3 = [27 x i8] c"Unable to allocate memory\0A\00"
define i32 @alloc_matrix(i32 %0, i32 %1, double*** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double***
%7 = alloca i32
%8 = alloca double**
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double*** %2, double**** %6
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
store double** null, double*** %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %73
16: ; preds = %3
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %73
22: ; preds = %16
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %73
31: ; preds = %25, %22
%32 = load i32, i32* %5
%33 = call i64 @calloc(i32 %32, i32 8)
%34 = inttoptr i64 %33 to double**
store double** %34, double*** %8
%35 = load double**, double*** %8
%36 = icmp eq double** %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %73
42: ; preds = %31
store i32 0, i32* %9
br label %43
43: ; preds = %67, %42
%44 = load i32, i32* %9
%45 = load i32, i32* %5
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %70
47: ; preds = %43
%48 = load i32, i32* %4
%49 = call i64 @calloc(i32 %48, i32 8)
%50 = inttoptr i64 %49 to double*
%51 = load double**, double*** %8
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double*, double** %51, i64 %53
store double* %50, double** %54
%55 = load double**, double*** %8
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = icmp eq double* %59, null
br i1 %60, label %61, label %66
61: ; preds = %47
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %73
66: ; preds = %47
br label %67
67: ; preds = %66
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %43
70: ; preds = %43
%71 = load double**, double*** %8
%72 = load double***, double**** %6
store double** %71, double*** %72
br label %73
73: ; preds = %70, %61, %37, %28, %19, %13
%74 = load i32, i32* %7
ret i32 %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.2 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/OPERATORS/MM/src/mm_helpers.c\00"
@.str.3 = [27 x i8] c"Unable to allocate memory\0A\00"
@str = [18 x i8] c"allocating matrix\00"
define i32 @alloc_matrix(i32 %0, i32 %1, double*** nocapture writeonly %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%5 = icmp slt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
br label %47
9: ; preds = %3
%10 = icmp slt i32 %1, 1
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 36, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
br label %47
14: ; preds = %9
%15 = icmp eq i32 %0, 1
%16 = icmp eq i32 %1, 1
%17 = and i1 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
br label %47
21: ; preds = %14
%22 = tail call i64 @calloc(i32 %1, i32 8)
%23 = inttoptr i64 %22 to double**
%24 = icmp eq i64 %22, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = zext i32 %1 to i64
br label %34
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
br label %47
32: ; preds = %34
%33 = icmp eq i64 %40, %26
br i1 %33, label %46, label %34
34: ; preds = %25, %32
%35 = phi i64 [ 0, %25 ], [ %40, %32 ]
%36 = tail call i64 @calloc(i32 %0, i32 8)
%37 = inttoptr i64 %36 to double*
%38 = getelementptr inbounds double*, double** %23, i64 %35
store double* %37, double** %38
%39 = icmp eq i64 %36, 0
%40 = add nuw nsw i64 %35, 1
br i1 %39, label %41, label %32
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0))
br label %47
46: ; preds = %32
store double** %23, double*** %2
br label %47
47: ; preds = %41, %6, %11, %18, %27, %46
%48 = phi i32 [ -1, %6 ], [ -1, %11 ], [ -1, %18 ], [ -1, %27 ], [ -1, %41 ], [ 0, %46 ]
ret i32 %48
}