#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 */
unsigned int count(char *, unsigned int, unsigned int, char);
char findMajority(char m[], unsigned left, unsigned right, char *majority) {
  unsigned mid;
  if (left == right) {
    *majority = m[left];
    return 1;
  }
  mid = (left + right) / 2;
  if (findMajority(m, left, mid, majority))
    if (count(m, left, right, *majority) > (right - left + 1) / 2)
      return 1;
  if (findMajority(m, mid + 1, right, majority))
    if (count(m, left, right, *majority) > (right - left + 1) / 2)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<findMajority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    115b <findMajority+0x3b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movb   $0x1,-0x1(%rbp)
jmp    1214 <findMajority+0xf4>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <findMajority@plt>
cmp    $0x0,%al
je     11ba <findMajority+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
call   1030 <count@plt>
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jbe    11b5 <findMajority+0x95>
movb   $0x1,-0x1(%rbp)
jmp    1214 <findMajority+0xf4>
jmp    11ba <findMajority+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <findMajority@plt>
cmp    $0x0,%al
je     1210 <findMajority+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
call   1030 <count@plt>
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jbe    120b <findMajority+0xeb>
movb   $0x1,-0x1(%rbp)
jmp    1214 <findMajority+0xf4>
jmp    1210 <findMajority+0xf0>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMajority>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r13d
mov    %rdi,%r15
mov    %edx,%ebx
sub    %esi,%ebx
jne    1148 <findMajority+0x28>
mov    %r13d,%eax
mov    (%r15,%rax,1),%al
mov    %al,(%r14)
mov    $0x1,%al
jmp    11b9 <findMajority+0x99>
mov    %esi,%r12d
lea    (%r12,%r13,1),%ebp
shr    %ebp
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <findMajority@plt>
test   %al,%al
je     1181 <findMajority+0x61>
movsbl (%r14),%ecx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1030 <count@plt>
mov    %eax,%ecx
lea    0x1(%rbx),%edx
shr    %edx
mov    $0x1,%al
cmp    %edx,%ecx
ja     11b9 <findMajority+0x99>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r14,%rcx
call   1040 <findMajority@plt>
test   %al,%al
je     11b7 <findMajority+0x97>
movsbl (%r14),%ecx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1030 <count@plt>
mov    %eax,%ecx
add    $0x1,%ebx
shr    %ebx
mov    $0x1,%al
cmp    %ebx,%ecx
ja     11b9 <findMajority+0x99>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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