#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 /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int a[] = {3, 3, 4, 2, 4, 4, 2, 4, 4};
  int size = sizeof(a) / sizeof(a[0]);
  int count = 0, k = -1;
  for (int i = 0; i < size; i++) {
    count = -1;
    for (int j = 0; j < size; j++) {
      if (a[i] == a[j]) {
        count++;
      }
    }
    if (count >= (size / 3) + 1)
      k = i;
  }
  if (k != -1)
    printf("Majority element exits, it is %d\n", a[k]);
  else
    printf("Does not exists!!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x9,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11f9 <main+0xd9>
movl   $0xffffffff,-0x48(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11bf <main+0x9f>
movslq -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
movslq -0x54(%rbp),%rcx
cmp    -0x40(%rbp,%rcx,4),%eax
jne    11ac <main+0x8c>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11b1 <main+0x91>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1181 <main+0x61>
mov    -0x48(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x44(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jl     11e6 <main+0xc6>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    11eb <main+0xcb>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1167 <main+0x47>
cmpl   $0xffffffff,-0x4c(%rbp)
je     121e <main+0xfe>
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122c <main+0x10c>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
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 = [34 x i8] c"Majority element exits, it is %d\0A\00"
@.str.1 = [19 x i8] c"Does not exists!!\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [9 x i32]* %6 to i8*
store i32 9, i32* %7
store i32 0, i32* %8
store i32 -1, i32* %9
store i32 0, i32* %10
br label %13
13: ; preds = %48, %2
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %51
17: ; preds = %13
store i32 -1, i32* %8
store i32 0, i32* %11
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %26, %30
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %35
35: ; preds = %32, %22
br label %36
36: ; preds = %35
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %18
39: ; preds = %18
%40 = load i32, i32* %8
%41 = load i32, i32* %7
%42 = sdiv i32 %41, 3
%43 = add nsw i32 %42, 1
%44 = icmp sge i32 %40, %43
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = load i32, i32* %10
store i32 %46, i32* %9
br label %47
47: ; preds = %45, %39
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %13
51: ; preds = %13
%52 = load i32, i32* %9
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load i32, i32* %9
%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
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %62
60: ; preds = %51
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Majority element exits, it is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 4)
ret i32 0
}