#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free_mem3Dshort(short ***, int);
int /*<<< orphan*/ h264_free(short ****);
int /*<<< orphan*/ printf(char *);
void free_mem4Dshort(short ****array4D, int idx, int frames) {
  int j;
  if (array4D) {
    for (j = 0; j < idx; j++) {
      free_mem3Dshort(array4D[j], frames);
    }
    h264_free(array4D);
  } else {
    printf("free_mem4Dshort: trying to free unused memory");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<free_mem4Dshort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a0 <free_mem4Dshort+0x60>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <free_mem4Dshort+0x52>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%esi
call   1050 <free_mem3Dshort@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <free_mem4Dshort+0x24>
mov    -0x8(%rbp),%rdi
call   1040 <h264_free@plt>
jmp    11b3 <free_mem4Dshort+0x73>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<free_mem4Dshort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1187 <free_mem4Dshort+0x47>
mov    %rdi,%r15
test   %esi,%esi
jle    1175 <free_mem4Dshort+0x35>
mov    %edx,%r14d
mov    %esi,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %r14d,%esi
call   1050 <free_mem3Dshort@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <free_mem4Dshort+0x20>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <h264_free@plt>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"free_mem4Dshort: trying to free unused memory\00"
define void @free_mem4Dshort(i16**** %0, i32 %1, i32 %2) {
%4 = alloca i16****
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i16**** %0, i16***** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i16****, i16***** %4
%9 = icmp ne i16**** %8, null
br i1 %9, label %10, label %29
10: ; preds = %3
store i32 0, i32* %7
br label %11
11: ; preds = %23, %10
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i16****, i16***** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i16***, i16**** %16, i64 %18
%20 = load i16***, i16**** %19
%21 = load i32, i32* %6
%22 = call i32 @free_mem3Dshort(i16*** %20, i32 %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %11
26: ; preds = %11
%27 = load i16****, i16***** %4
%28 = call i32 @h264_free(i16**** %27)
br label %32
29: ; preds = %3
%30 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %26
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"free_mem4Dshort: trying to free unused memory\00"
define void @free_mem4Dshort(i16**** %0, i32 %1, i32 %2) {
%4 = icmp eq i16**** %0, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %16
7: ; preds = %5
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i16***, i16**** %0, i64 %10
%12 = load i16***, i16**** %11
%13 = tail call i32 @free_mem3Dshort(i16*** %12, i32 %2)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %5
%17 = tail call i32 @h264_free(i16**** %0)
ret void
18: ; preds = %3
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
}