void testCelebrities() {
  int count = 4, celeb = 2;
  int **relations = (int **)calloc(sizeof(int *), count);
  for (int i = 0; i < count; i++) {
    relations[i] = (int *)calloc(sizeof(int), count);
    for (int j = 0; j < count; j++)
      relations[i][j] = (j == celeb && i != celeb) ? 1 : 0;
  }
  for (int i = 0; i < count; i++)
    outArrInt(relations[i], count);
  celeb = findCelebrity(relations, count);
  printf("celebrity: %d\n", celeb);
  for (int i = 0; i < count; i++)
    free(relations[i]);
  free(relations);
}


x86 assembly (clang, -O0):
<testCelebrities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x4,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movslq -0x4(%rbp),%rsi
mov    $0x8,%edi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121c <testCelebrities+0xcc>
movslq -0x4(%rbp),%rsi
mov    $0x4,%edi
call   1060 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1209 <testCelebrities+0xb9>
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x21(%rbp)
jne    11d8 <testCelebrities+0x88>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%cl
xor    %edx,%edx
mov    $0x1,%eax
test   $0x1,%cl
cmovne %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11af <testCelebrities+0x5f>
jmp    120e <testCelebrities+0xbe>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <testCelebrities+0x2f>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1253 <testCelebrities+0x103>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1070 <outArrInt@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <testCelebrities+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1040 <findCelebrity@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12a7 <testCelebrities+0x157>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127c <testCelebrities+0x12c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testCelebrities>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x8,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    %rax,(%rbx)
movl   $0x1,0x8(%rax)
mov    $0x4,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    %rax,0x8(%rbx)
movl   $0x1,0x8(%rax)
mov    $0x4,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %rax,0x10(%rbx)
mov    $0x4,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
mov    %rax,0x18(%rbx)
movl   $0x1,0x8(%rax)
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <outArrInt@plt>
mov    %r15,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <outArrInt@plt>
mov    %r12,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <outArrInt@plt>
mov    %r13,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <outArrInt@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <findCelebrity@plt>
lea    0xdd7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"celebrity: %d\0A\00"
define void @testCelebrities() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 4, i32* %1
store i32 2, i32* %2
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = call i8* @calloc(i64 8, i64 %9)
%11 = bitcast i8* %10 to i32**
store i32** %11, i32*** %3
store i32 0, i32* %4
br label %12
12: ; preds = %53, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %1
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %56
16: ; preds = %12
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = call i8* @calloc(i64 4, i64 %18)
%20 = bitcast i8* %19 to i32*
%21 = load i32**, i32*** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
store i32* %20, i32** %24
store i32 0, i32* %5
br label %25
25: ; preds = %49, %16
%26 = load i32, i32* %5
%27 = load i32, i32* %1
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %52
29: ; preds = %25
%30 = load i32, i32* %5
%31 = load i32, i32* %2
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = icmp ne i32 %34, %35
br label %37
37: ; preds = %33, %29
%38 = phi i1 [ false, %29 ], [ %36, %33 ]
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 1, i32 0
%41 = load i32**, i32*** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32*, i32** %41, i64 %43
%45 = load i32*, i32** %44
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %40, i32* %48
br label %49
49: ; preds = %37
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %25
52: ; preds = %25
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %12
56: ; preds = %12
store i32 0, i32* %6
br label %57
57: ; preds = %69, %56
%58 = load i32, i32* %6
%59 = load i32, i32* %1
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %72
61: ; preds = %57
%62 = load i32**, i32*** %3
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32*, i32** %62, i64 %64
%66 = load i32*, i32** %65
%67 = load i32, i32* %1
%68 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @outArrInt to i32 (i32*, i32, ...)*)(i32* %66, i32 %67)
br label %69
69: ; preds = %61
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %57
72: ; preds = %57
%73 = load i32**, i32*** %3
%74 = load i32, i32* %1
%75 = call i32 (i32**, i32, ...) bitcast (i32 (...)* @findCelebrity to i32 (i32**, i32, ...)*)(i32** %73, i32 %74)
store i32 %75, i32* %2
%76 = load i32, i32* %2
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %76)
store i32 0, i32* %7
br label %78
78: ; preds = %89, %72
%79 = load i32, i32* %7
%80 = load i32, i32* %1
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %92
82: ; preds = %78
%83 = load i32**, i32*** %3
%84 = load i32, i32* %7
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32*, i32** %83, i64 %85
%87 = load i32*, i32** %86
%88 = bitcast i32* %87 to i8*
br label %89
89: ; preds = %82
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %78
92: ; preds = %78
%93 = load i32**, i32*** %3
%94 = bitcast i32** %93 to i8*
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"celebrity: %d\0A\00"
define void @testCelebrities() {
%1 = tail call dereferenceable_or_null(32) i8* @calloc(i64 8, i64 4)
%2 = bitcast i8* %1 to i32**
%3 = tail call dereferenceable_or_null(16) i8* @calloc(i64 4, i64 4)
%4 = bitcast i8* %1 to i8**
store i8* %3, i8** %4
%5 = bitcast i8* %3 to i32*
%6 = getelementptr inbounds i32, i32* %5, i64 2
store i32 1, i32* %6
%7 = tail call dereferenceable_or_null(16) i8* @calloc(i64 4, i64 4)
%8 = getelementptr inbounds i32*, i32** %2, i64 1
%9 = bitcast i32** %8 to i8**
store i8* %7, i8** %9
%10 = bitcast i8* %7 to i32*
%11 = getelementptr inbounds i32, i32* %10, i64 2
store i32 1, i32* %11
%12 = tail call dereferenceable_or_null(16) i8* @calloc(i64 4, i64 4)
%13 = getelementptr inbounds i32*, i32** %2, i64 2
%14 = bitcast i32** %13 to i8**
store i8* %12, i8** %14
%15 = bitcast i8* %12 to i32*
%16 = tail call dereferenceable_or_null(16) i8* @calloc(i64 4, i64 4)
%17 = getelementptr inbounds i32*, i32** %2, i64 3
%18 = bitcast i32** %17 to i8**
store i8* %16, i8** %18
%19 = bitcast i8* %16 to i32*
%20 = getelementptr inbounds i32, i32* %19, i64 2
store i32 1, i32* %20
%21 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @outArrInt to i32 (i32*, i32, ...)*)(i32* %5, i32 4)
%22 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @outArrInt to i32 (i32*, i32, ...)*)(i32* %10, i32 4)
%23 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @outArrInt to i32 (i32*, i32, ...)*)(i32* %15, i32 4)
%24 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @outArrInt to i32 (i32*, i32, ...)*)(i32* %19, i32 4)
%25 = tail call i32 (i32**, i32, ...) bitcast (i32 (...)* @findCelebrity to i32 (i32**, i32, ...)*)(i32** %2, i32 4)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %4
tail call void @free(i8* %27)
%28 = load i8*, i8** %9
tail call void @free(i8* %28)
%29 = load i8*, i8** %14
tail call void @free(i8* %29)
%30 = load i8*, i8** %18
tail call void @free(i8* %30)
tail call void @free(i8* %1)
ret void
}