#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 */
int /*<<< orphan*/ free(void **);
void safe_deallocate_2d_array(void **pointer, size_t first_size) {
  if (pointer == NULL)
    return;
  for (size_t i = 0; i < first_size; i++) {
    free(pointer[i]);
    pointer[i] = NULL;
  }
  free(pointer);
}


x86 assembly (clang, -O0):
<safe_deallocate_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1130 <safe_deallocate_2d_array+0x20>
jmp    1181 <safe_deallocate_2d_array+0x71>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1178 <safe_deallocate_2d_array+0x68>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <safe_deallocate_2d_array+0x28>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_deallocate_2d_array>:
test   %rdi,%rdi
je     1157 <safe_deallocate_2d_array+0x47>
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rsi,%rsi
je     114a <safe_deallocate_2d_array+0x3a>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <safe_deallocate_2d_array+0x20>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
ret

LLVM IR (-O0):
define void @safe_deallocate_2d_array(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i64
store i8** %0, i8*** %3
store i64 %1, i64* %4
%6 = load i8**, i8*** %3
%7 = icmp eq i8** %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
br label %30
9: ; preds = %2
store i64 0, i64* %5
br label %10
10: ; preds = %24, %9
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8**, i8*** %3
%16 = load i64, i64* %5
%17 = getelementptr inbounds i8*, i8** %15, i64 %16
%18 = load i8*, i8** %17
%19 = bitcast i8* %18 to i8**
%20 = call i32 @free(i8** %19)
%21 = load i8**, i8*** %3
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
store i8* null, i8** %23
br label %24
24: ; preds = %14
%25 = load i64, i64* %5
%26 = add i64 %25, 1
store i64 %26, i64* %5
br label %10
27: ; preds = %10
%28 = load i8**, i8*** %3
%29 = call i32 @free(i8** %28)
br label %30
30: ; preds = %27, %8
ret void
}

LLVM IR (-O2):
define void @safe_deallocate_2d_array(i8** %0, i64 %1) {
%3 = icmp eq i8** %0, null
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %8, %4
%7 = tail call i32 @free(i8** %0)
br label %16
8: ; preds = %4, %8
%9 = phi i64 [ %14, %8 ], [ 0, %4 ]
%10 = getelementptr inbounds i8*, i8** %0, i64 %9
%11 = bitcast i8** %10 to i8***
%12 = load i8**, i8*** %11
%13 = tail call i32 @free(i8** %12)
store i8* null, i8** %10
%14 = add nuw i64 %9, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %6, label %8
16: ; preds = %2, %6
ret void
}