#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 */
size_t get_pointer_array_length(void **);
bool compare_arrays(void **arr1, void **arr2,
                    int (*comparator)(const void *, const void *)) {
  size_t numberOfElements = get_pointer_array_length(arr1);
  if (numberOfElements != get_pointer_array_length(arr2)) {
    return false;
  }
  for (size_t i = 0; i < numberOfElements; i++) {
    if (comparator(arr1[i], arr2[i]) != 0) {
      return false;
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<compare_arrays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <get_pointer_array_length@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <get_pointer_array_length@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     115e <compare_arrays+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <compare_arrays+0xb4>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11bd <compare_arrays+0xad>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rsi
call   *%rax
cmp    $0x0,%eax
je     11a7 <compare_arrays+0x97>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <compare_arrays+0xb4>
jmp    11ac <compare_arrays+0x9c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1166 <compare_arrays+0x56>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_arrays>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <get_pointer_array_length@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <get_pointer_array_length@plt>
xor    %r13d,%r13d
cmp    %rax,%rbx
jne    118d <compare_arrays+0x7d>
test   %rbx,%rbx
je     1187 <compare_arrays+0x77>
mov    (%r12),%rdi
mov    (%r15),%rsi
call   *%r14
test   %eax,%eax
jne    118d <compare_arrays+0x7d>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbp
cmp    %rcx,%rbx
je     117b <compare_arrays+0x6b>
mov    (%r12,%rbp,8),%rdi
mov    (%r15,%rbp,8),%rsi
call   *%r14
lea    0x1(%rbp),%rcx
test   %eax,%eax
je     1160 <compare_arrays+0x50>
xor    %r13d,%r13d
cmp    %rbx,%rbp
setae  %r13b
jmp    118d <compare_arrays+0x7d>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compare_arrays(i8** %0, i8** %1, i32 (i8*, i8*)* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32 (i8*, i8*)*
%8 = alloca i64
%9 = alloca i64
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i32 (i8*, i8*)* %2, i32 (i8*, i8*)** %7
%10 = load i8**, i8*** %5
%11 = call i64 @get_pointer_array_length(i8** %10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = load i8**, i8*** %6
%14 = call i64 @get_pointer_array_length(i8** %13)
%15 = icmp ne i64 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %40
17: ; preds = %3
store i64 0, i64* %9
br label %18
18: ; preds = %36, %17
%19 = load i64, i64* %9
%20 = load i64, i64* %8
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %7
%24 = load i8**, i8*** %5
%25 = load i64, i64* %9
%26 = getelementptr inbounds i8*, i8** %24, i64 %25
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %6
%29 = load i64, i64* %9
%30 = getelementptr inbounds i8*, i8** %28, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 %23(i8* %27, i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %22
store i32 0, i32* %4
br label %40
35: ; preds = %22
br label %36
36: ; preds = %35
%37 = load i64, i64* %9
%38 = add i64 %37, 1
store i64 %38, i64* %9
br label %18
39: ; preds = %18
store i32 1, i32* %4
br label %40
40: ; preds = %39, %34, %16
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
define i32 @compare_arrays(i8** %0, i8** %1, i32 (i8*, i8*)* nocapture %2) {
%4 = tail call i64 @get_pointer_array_length(i8** %0)
%5 = tail call i64 @get_pointer_array_length(i8** %1)
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %28
7: ; preds = %3
%8 = icmp eq i64 %4, 0
br i1 %8, label %28, label %9
9: ; preds = %7
%10 = load i8*, i8** %0
%11 = load i8*, i8** %1
%12 = tail call i32 %2(i8* %10, i8* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %9, %17
%15 = phi i64 [ %24, %17 ], [ 1, %9 ]
%16 = icmp eq i64 %15, %4
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8*, i8** %0, i64 %15
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 %15
%21 = load i8*, i8** %20
%22 = tail call i32 %2(i8* %19, i8* %21)
%23 = icmp eq i32 %22, 0
%24 = add nuw i64 %15, 1
br i1 %23, label %14, label %25
25: ; preds = %14, %17
%26 = icmp uge i64 %15, %4
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %7, %9, %25, %3
%29 = phi i32 [ 0, %3 ], [ 1, %7 ], [ 0, %9 ], [ %27, %25 ]
ret i32 %29
}