#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 */
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int findRank(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char const *argv[]) {
  int a[] = {3, 3, 4, 2, 4, 4, 2, 4, 4};
  int size = sizeof(a) / sizeof(a[0]);
  int oneThird = size / 3, twoThrid = (2 * size) / 3;
  int chanceOne, chanceTwo;
  chanceOne = findRank(a, 0, size - 1, oneThird);
  chanceTwo = findRank(a, 0, size - 1, twoThrid);
  printf("Possibilities for Majority element are  : %d %d\n",
         a[(size - 1) - chanceOne + 1], a[(size - 1) - chanceTwo + 1]);
  int ele1 = a[(size - 1) - chanceOne + 1];
  int ele2 = a[(size - 1) - chanceTwo + 1];
  int count1 = 0, count2 = 0;
  for (int i = 1; i < size; i++) {
    if (a[i] == ele1) {
      count1++;
    }
  }
  if (count1 >= ((size / 3) + 1))
    printf("Majority element can be  %d\n", ele1);
  for (int i = 1; i < size; i++) {
    if (a[i] == ele2) {
      count2++;
    }
  }
  if (count2 >= ((size / 3) + 1))
    printf("Majority element can be  %d\n", ele2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x9,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x48(%rbp),%ecx
xor    %esi,%esi
call   1030 <findRank@plt>
mov    %eax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
mov    -0x4c(%rbp),%ecx
xor    %esi,%esi
call   1030 <findRank@plt>
mov    %eax,-0x54(%rbp)
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
sub    -0x50(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%esi
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
sub    -0x54(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
sub    -0x50(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x58(%rbp)
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
sub    -0x54(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    125c <main+0x12c>
movslq -0x68(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
cmp    -0x58(%rbp),%eax
jne    1249 <main+0x119>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    124e <main+0x11e>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1223 <main+0xf3>
mov    -0x60(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jl     128e <main+0x15e>
mov    -0x58(%rbp),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    12ce <main+0x19e>
movslq -0x6c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
cmp    -0x5c(%rbp),%eax
jne    12bb <main+0x18b>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12c0 <main+0x190>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1295 <main+0x165>
mov    -0x64(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jl     1300 <main+0x1d0>
mov    -0x5c(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    0xef4(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
mov    $0x3,%ecx
call   1030 <findRank@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
mov    $0x6,%ecx
call   1030 <findRank@plt>
mov    $0x9,%ecx
mov    $0x9,%edx
sub    %ebp,%edx
movslq %edx,%rbx
mov    (%rsp,%rbx,4),%esi
sub    %eax,%ecx
movslq %ecx,%rbp
mov    (%rsp,%rbp,4),%edx
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp,%rbx,4),%esi
mov    (%rsp,%rbp,4),%ebx
movdqu 0x4(%rsp),%xmm0
movdqu 0x14(%rsp),%xmm1
movd   %esi,%xmm2
pshufd $0x0,%xmm2,%xmm2
movdqa %xmm1,%xmm3
pcmpeqd %xmm2,%xmm3
pcmpeqd %xmm0,%xmm2
packssdw %xmm3,%xmm2
packsswb %xmm2,%xmm2
pmovmskb %xmm2,%eax
mov    %eax,%ecx
shr    %cl
and    $0x55,%cl
sub    %cl,%al
mov    %eax,%ecx
and    $0x33,%cl
shr    $0x2,%al
and    $0x33,%al
add    %cl,%al
mov    %eax,%ecx
shr    $0x4,%cl
add    %al,%cl
and    $0xf,%cl
cmp    $0x4,%cl
jb     120d <main+0xed>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movdqu 0x4(%rsp),%xmm0
movdqu 0x14(%rsp),%xmm1
movd   %ebx,%xmm2
pshufd $0x0,%xmm2,%xmm2
pcmpeqd %xmm2,%xmm1
pcmpeqd %xmm2,%xmm0
packssdw %xmm1,%xmm0
packsswb %xmm0,%xmm0
pmovmskb %xmm0,%eax
mov    %eax,%ecx
shr    %cl
and    $0x55,%cl
sub    %cl,%al
mov    %eax,%ecx
and    $0x33,%cl
shr    $0x2,%al
and    $0x33,%al
add    %cl,%al
mov    %eax,%ecx
shr    $0x4,%cl
add    %al,%cl
and    $0xf,%cl
cmp    $0x4,%cl
jb     125e <main+0x13e>
lea    0xe00(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.a = [9 x i32] [i32 3, i32 3, i32 4, i32 2, i32 4, i32 4, i32 2, i32 4, i32 4]
@.str = [49 x i8] c"Possibilities for Majority element are : %d %d\0A\00"
@.str.1 = [29 x i8] c"Majority element can be %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [9 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = bitcast [9 x i32]* %6 to i8*
store i32 9, i32* %7
%19 = load i32, i32* %7
%20 = sdiv i32 %19, 3
store i32 %20, i32* %8
%21 = load i32, i32* %7
%22 = mul nsw i32 2, %21
%23 = sdiv i32 %22, 3
store i32 %23, i32* %9
%24 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = load i32, i32* %8
%28 = call i32 @findRank(i32* %24, i32 0, i32 %26, i32 %27)
store i32 %28, i32* %10
%29 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%30 = load i32, i32* %7
%31 = sub nsw i32 %30, 1
%32 = load i32, i32* %9
%33 = call i32 @findRank(i32* %29, i32 0, i32 %31, i32 %32)
store i32 %33, i32* %11
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %10
%37 = sub nsw i32 %35, %36
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, 1
%44 = load i32, i32* %11
%45 = sub nsw i32 %43, %44
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %49)
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
%53 = load i32, i32* %10
%54 = sub nsw i32 %52, %53
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %56
%58 = load i32, i32* %57
store i32 %58, i32* %12
%59 = load i32, i32* %7
%60 = sub nsw i32 %59, 1
%61 = load i32, i32* %11
%62 = sub nsw i32 %60, %61
%63 = add nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %64
%66 = load i32, i32* %65
store i32 %66, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 1, i32* %16
br label %67
67: ; preds = %82, %2
%68 = load i32, i32* %16
%69 = load i32, i32* %7
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %85
71: ; preds = %67
%72 = load i32, i32* %16
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = load i32, i32* %12
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %71
%79 = load i32, i32* %14
%80 = add nsw i32 %79, 1
store i32 %80, i32* %14
br label %81
81: ; preds = %78, %71
br label %82
82: ; preds = %81
%83 = load i32, i32* %16
%84 = add nsw i32 %83, 1
store i32 %84, i32* %16
br label %67
85: ; preds = %67
%86 = load i32, i32* %14
%87 = load i32, i32* %7
%88 = sdiv i32 %87, 3
%89 = add nsw i32 %88, 1
%90 = icmp sge i32 %86, %89
br i1 %90, label %91, label %94
91: ; preds = %85
%92 = load i32, i32* %12
%93 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %91, %85
store i32 1, i32* %17
br label %95
95: ; preds = %110, %94
%96 = load i32, i32* %17
%97 = load i32, i32* %7
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %113
99: ; preds = %95
%100 = load i32, i32* %17
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = load i32, i32* %13
%105 = icmp eq i32 %103, %104
br i1 %105, label %106, label %109
106: ; preds = %99
%107 = load i32, i32* %15
%108 = add nsw i32 %107, 1
store i32 %108, i32* %15
br label %109
109: ; preds = %106, %99
br label %110
110: ; preds = %109
%111 = load i32, i32* %17
%112 = add nsw i32 %111, 1
store i32 %112, i32* %17
br label %95
113: ; preds = %95
%114 = load i32, i32* %15
%115 = load i32, i32* %7
%116 = sdiv i32 %115, 3
%117 = add nsw i32 %116, 1
%118 = icmp sge i32 %114, %117
br i1 %118, label %119, label %122
119: ; preds = %113
%120 = load i32, i32* %13
%121 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %120)
br label %122
122: ; preds = %119, %113
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [9 x i32] [i32 3, i32 3, i32 4, i32 2, i32 4, i32 4, i32 2, i32 4, i32 4]
@.str = [49 x i8] c"Possibilities for Majority element are : %d %d\0A\00"
@.str.1 = [29 x i8] c"Majority element can be %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i32]
%4 = bitcast [9 x i32]* %3 to i8*
%5 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 0
%6 = call i32 @findRank(i32* %5, i32 0, i32 8, i32 3)
%7 = call i32 @findRank(i32* %5, i32 0, i32 8, i32 6)
%8 = sub i32 9, %6
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = sub i32 9, %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %15)
%17 = load i32, i32* %10
%18 = load i32, i32* %14
%19 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 1
%20 = bitcast i32* %19 to <8 x i32>*
%21 = load <8 x i32>, <8 x i32>* %20
%22 = insertelement <8 x i32> poison, i32 %17, i64 0
%23 = shufflevector <8 x i32> %22, <8 x i32> poison, <8 x i32> zeroinitializer
%24 = icmp eq <8 x i32> %21, %23
%25 = bitcast <8 x i1> %24 to i8
%26 = call i8 @llvm.ctpop.i8(i8 %25)
%27 = icmp ugt i8 %26, 3
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%30 = bitcast i32* %19 to <8 x i32>*
%31 = load <8 x i32>, <8 x i32>* %30
br label %32
32: ; preds = %28, %2
%33 = phi <8 x i32> [ %31, %28 ], [ %21, %2 ]
%34 = insertelement <8 x i32> poison, i32 %18, i64 0
%35 = shufflevector <8 x i32> %34, <8 x i32> poison, <8 x i32> zeroinitializer
%36 = icmp eq <8 x i32> %33, %35
%37 = bitcast <8 x i1> %36 to i8
%38 = call i8 @llvm.ctpop.i8(i8 %37)
%39 = icmp ugt i8 %38, 3
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %42
42: ; preds = %40, %32
ret i32 0
}