#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*/ deallocate_target_usage_marks(int **, int);
scalar_t__ malloc(int);
int **safely_allocate_target_usage_marks(int num_cams) {
  int cam, error = 0;
  int **tusage;
  tusage = (int **)malloc(num_cams * sizeof(int *));
  if (tusage == NULL)
    return NULL;
  for (cam = 0; cam < num_cams; cam++) {
    if (error == 0) {
      tusage[cam] = (int *)calloc(202400, sizeof(int));
      if (tusage[cam] == NULL)
        error = 1;
    } else {
      tusage[cam] = NULL;
    }
  }
  if (error == 0)
    return tusage;
  deallocate_target_usage_marks(tusage, num_cams);
  return NULL;
}


x86 assembly (clang, -O0):
<safely_allocate_target_usage_marks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116d <safely_allocate_target_usage_marks+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1215 <safely_allocate_target_usage_marks+0xe5>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ea <safely_allocate_target_usage_marks+0xba>
cmpl   $0x0,-0x14(%rbp)
jne    11c7 <safely_allocate_target_usage_marks+0x97>
mov    $0x316a0,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11c2 <safely_allocate_target_usage_marks+0x92>
movl   $0x1,-0x14(%rbp)
jmp    11d7 <safely_allocate_target_usage_marks+0xa7>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    11dc <safely_allocate_target_usage_marks+0xac>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <safely_allocate_target_usage_marks+0x44>
cmpl   $0x0,-0x14(%rbp)
jne    1201 <safely_allocate_target_usage_marks+0xd1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1215 <safely_allocate_target_usage_marks+0xe5>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <deallocate_target_usage_marks@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safely_allocate_target_usage_marks>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a0 <safely_allocate_target_usage_marks+0x70>
mov    %rax,%r15
test   %r14d,%r14d
jle    11a3 <safely_allocate_target_usage_marks+0x73>
mov    %r14d,%r12d
xor    %ebx,%ebx
xor    %ecx,%ecx
jmp    1184 <safely_allocate_target_usage_marks+0x54>
xchg   %ax,%ax
mov    $0x316a0,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1191 <safely_allocate_target_usage_marks+0x61>
test   %ecx,%ecx
je     1160 <safely_allocate_target_usage_marks+0x30>
mov    $0x1,%ecx
xor    %eax,%eax
jmp    1177 <safely_allocate_target_usage_marks+0x47>
test   %ecx,%ecx
je     11a3 <safely_allocate_target_usage_marks+0x73>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <deallocate_target_usage_marks@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32** @safely_allocate_target_usage_marks(i32 %0) {
%2 = alloca i32**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 %0, i32* %3
store i32 0, i32* %5
%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 %16
15: ; preds = %1
store i32** null, i32*** %2
br label %57
16: ; preds = %1
store i32 0, i32* %4
br label %17
17: ; preds = %45, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = call i64 @calloc(i32 202400, i32 4)
%26 = inttoptr i64 %25 to i32*
%27 = load i32**, i32*** %6
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
store i32* %26, i32** %30
%31 = load i32**, i32*** %6
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %38
37: ; preds = %24
store i32 1, i32* %5
br label %38
38: ; preds = %37, %24
br label %44
39: ; preds = %21
%40 = load i32**, i32*** %6
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32*, i32** %40, i64 %42
store i32* null, i32** %43
br label %44
44: ; preds = %39, %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %17
48: ; preds = %17
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i32**, i32*** %6
store i32** %52, i32*** %2
br label %57
53: ; preds = %48
%54 = load i32**, i32*** %6
%55 = load i32, i32* %3
%56 = call i32 @deallocate_target_usage_marks(i32** %54, i32 %55)
store i32** null, i32*** %2
br label %57
57: ; preds = %53, %51, %15
%58 = load i32**, i32*** %2
ret i32** %58
}

LLVM IR (-O2):
define i32** @safely_allocate_target_usage_marks(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32**
%5 = icmp eq i64 %3, 0
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %29
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %19
%11 = phi i64 [ 0, %8 ], [ %23, %19 ]
%12 = phi i32 [ 0, %8 ], [ %21, %19 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = tail call i64 @calloc(i32 202400, i32 4)
%16 = inttoptr i64 %15 to i32*
%17 = icmp eq i64 %15, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %10, %14
%20 = phi i32* [ %16, %14 ], [ null, %10 ]
%21 = phi i32 [ %18, %14 ], [ 1, %10 ]
%22 = getelementptr inbounds i32*, i32** %4, i64 %11
store i32* %20, i32** %22
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %25, label %10
25: ; preds = %19
%26 = icmp eq i32 %21, 0
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = tail call i32 @deallocate_target_usage_marks(i32** %4, i32 %0)
br label %29
29: ; preds = %6, %25, %1, %27
%30 = phi i32** [ null, %27 ], [ null, %1 ], [ %4, %25 ], [ %4, %6 ]
ret i32** %30
}