#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ inicializar(int *, int);
scalar_t__ malloc(int);
int mayoritario0(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, pos;
  int *vector;
  printf("De Que tamaño desea el vector : ");
  scanf("%d", &n);
  vector = (int *)malloc(n * sizeof(int));
  if (vector == NULL) {
    printf("Error");
    exit(1);
  } else {
    inicializar(vector, n);
    pos = mayoritario0(vector, n);
    if (pos != -1) {
      printf(
          "\nEl mayoritario es %i que ocupa la posicion %i por la derecha \n",
          vector[pos], pos + 1);
    } else
      printf("No se ha encontrado ningun mayoritario en el vector");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <main+0x63>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <inicializar@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <mayoritario0@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     120c <main+0xac>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121a <main+0xba>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121f <main+0xbf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e6 <main+0x86>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1050 <inicializar@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <mayoritario0@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x70>
movslq %eax,%rcx
mov    (%rbx,%rcx,4),%esi
add    $0x1,%eax
lea    0xe66(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11de <main+0x7e>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"De Que tama\C3\B1o desea el vector : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [64 x i8] c"\0AEl mayoritario es %i que ocupa la posicion %i por la derecha \0A\00"
@.str.4 = [52 x i8] c"No se ha encontrado ningun mayoritario en el vector\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = load i32*, i32** %4
%20 = load i32, i32* %2
%21 = call i32 @inicializar(i32* %19, i32 %20)
%22 = load i32*, i32** %4
%23 = load i32, i32* %2
%24 = call i32 @mayoritario0(i32* %22, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %36
27: ; preds = %18
%28 = load i32*, i32** %4
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %34)
br label %38
36: ; preds = %18
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %27
br label %39
39: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"De Que tama\C3\B1o desea el vector : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [64 x i8] c"\0AEl mayoritario es %i que ocupa la posicion %i por la derecha \0A\00"
@.str.4 = [52 x i8] c"No se ha encontrado ningun mayoritario en el vector\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
%15 = call i32 @inicializar(i32* %8, i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @mayoritario0(i32* %8, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i32, i32* %8, i64 %20
%22 = load i32, i32* %21
%23 = add nuw nsw i32 %17, 1
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %23)
br label %27
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %19, %25
ret i32 0
}