#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 count(int, int, int *);
int solve(int n, int num[]) {
  int l = 0, r = 0, ln = 0, rn = 0, cnt = 0;
  if (n == 1) {
    return num[0];
  }
  ln = n / 2;
  rn = (n + 1) / 2;
  l = solve(ln, &num[0]);
  r = solve(rn, &num[ln]);
  if (r != 0) {
    cnt = count(r, n, num);
    if (cnt > n / 2) {
      return r;
    }
  }
  if (l != 0) {
    cnt = count(l, n, num);
    if (cnt > n / 2) {
      return l;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    116a <solve+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <solve+0x12d>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <solve@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <solve@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11fc <solve+0xdc>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <count@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    11f7 <solve+0xd7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <solve+0x12d>
jmp    11fc <solve+0xdc>
cmpl   $0x0,-0x14(%rbp)
je     1246 <solve+0x126>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <count@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    1241 <solve+0x121>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <solve+0x12d>
jmp    1246 <solve+0x126>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1135 <solve+0x15>
mov    (%r14),%ebx
jmp    11a0 <solve+0x80>
mov    %edi,%r12d
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
lea    0x1(%r12),%eax
shr    $0x1f,%eax
lea    (%r12,%rax,1),%ebx
add    $0x1,%ebx
sar    %ebx
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <solve@plt>
mov    %eax,%r15d
movslq %ebp,%rax
lea    (%r14,%rax,4),%rsi
mov    %ebx,%edi
call   1030 <solve@plt>
test   %eax,%eax
je     1184 <solve+0x64>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1040 <count@plt>
cmp    %ebp,%eax
jg     11a0 <solve+0x80>
test   %r15d,%r15d
je     119e <solve+0x7e>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1040 <count@plt>
mov    %r15d,%ebx
cmp    %ebp,%eax
jg     11a0 <solve+0x80>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @solve(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
store i32 %16, i32* %3
br label %63
17: ; preds = %2
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 2
store i32 %19, i32* %8
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
%22 = sdiv i32 %21, 2
store i32 %22, i32* %9
%23 = load i32, i32* %8
%24 = load i32*, i32** %5
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = call i32 @solve(i32 %23, i32* %25)
store i32 %26, i32* %6
%27 = load i32, i32* %9
%28 = load i32*, i32** %5
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = call i32 @solve(i32 %27, i32* %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %47
35: ; preds = %17
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = load i32*, i32** %5
%39 = call i32 @count(i32 %36, i32 %37, i32* %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = load i32, i32* %4
%42 = sdiv i32 %41, 2
%43 = icmp sgt i32 %40, %42
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = load i32, i32* %7
store i32 %45, i32* %3
br label %63
46: ; preds = %35
br label %47
47: ; preds = %46, %17
%48 = load i32, i32* %6
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %47
%51 = load i32, i32* %6
%52 = load i32, i32* %4
%53 = load i32*, i32** %5
%54 = call i32 @count(i32 %51, i32 %52, i32* %53)
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = load i32, i32* %4
%57 = sdiv i32 %56, 2
%58 = icmp sgt i32 %55, %57
br i1 %58, label %59, label %61
59: ; preds = %50
%60 = load i32, i32* %6
store i32 %60, i32* %3
br label %63
61: ; preds = %50
br label %62
62: ; preds = %61, %47
store i32 0, i32* %3
br label %63
63: ; preds = %62, %59, %44, %13
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
define i32 @solve(i32 %0, i32* %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* %1
br label %24
6: ; preds = %2
%7 = sdiv i32 %0, 2
%8 = add nsw i32 %0, 1
%9 = sdiv i32 %8, 2
%10 = tail call i32 @solve(i32 %7, i32* %1)
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = tail call i32 @solve(i32 %9, i32* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %6
%16 = tail call i32 @count(i32 %13, i32 %0, i32* %1)
%17 = icmp sgt i32 %16, %7
br i1 %17, label %24, label %18
18: ; preds = %15, %6
%19 = icmp eq i32 %10, 0
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = tail call i32 @count(i32 %10, i32 %0, i32* %1)
%22 = icmp sgt i32 %21, %7
br i1 %22, label %24, label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %20, %15, %23, %4
%25 = phi i32 [ %5, %4 ], [ 0, %23 ], [ %13, %15 ], [ %10, %20 ]
ret i32 %25
}