#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, char);
char findMajority(char m[], unsigned size, char *majority) {
  unsigned i, size2 = size / 2;
  for (i = 0; i < size; i++)
    if (count(m, size, m[i]) > size2) {
      *majority = m[i];
      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    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    118b <findMajority+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
call   1030 <count@plt>
cmp    -0x28(%rbp),%eax
jbe    1178 <findMajority+0x68>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movb   $0x1,-0x1(%rbp)
jmp    118f <findMajority+0x7f>
jmp    117d <findMajority+0x6d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1133 <findMajority+0x23>
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
test   %esi,%esi
je     115d <findMajority+0x4d>
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%rbx
mov    %esi,%r15d
shr    %r15d
mov    %esi,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <count@plt>
cmp    %r15d,%eax
ja     1161 <findMajority+0x51>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1140 <findMajority+0x30>
xor    %eax,%eax
jmp    1169 <findMajority+0x59>
mov    (%rbx,%rbp,1),%al
mov    %al,(%r14)
mov    $0x1,%al
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, i8* %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %6
%11 = udiv i32 %10, 2
store i32 %11, i32* %9
store i32 0, i32* %8
br label %12
12: ; preds = %35, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @count(i8* %17, i32 %18, i8 signext %23)
%25 = load i32, i32* %9
%26 = icmp ugt i32 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %7
store i8 %32, i8* %33
store i8 1, i8* %4
br label %39
34: ; preds = %16
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add i32 %36, 1
store i32 %37, i32* %8
br label %12
38: ; preds = %12
store i8 0, i8* %4
br label %39
39: ; preds = %38, %27
%40 = load i8, i8* %4
ret i8 %40
}

LLVM IR (-O2):
define signext i8 @findMajority(i8* %0, i32 %1, i8* nocapture writeonly %2) {
%4 = lshr i32 %1, 1
%5 = icmp eq i32 %1, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %18
%9 = phi i64 [ 0, %6 ], [ %19, %18 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @count(i8* %0, i32 %1, i8 signext %11)
%13 = icmp ugt i32 %12, %4
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = and i64 %9, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %2
br label %21
18: ; preds = %8
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %18, %3, %14
%22 = phi i8 [ 1, %14 ], [ 0, %3 ], [ 0, %18 ]
ret i8 %22
}