#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*/ insere_lista_auto(int *, int);
int /*<<< orphan*/ mostra_lista(int *, int);
scalar_t__ primo(int);
int primoAnterior(int *, int);
int primoPosterior(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void question_four() {
  int n, tam_vetor = 100, vetor[tam_vetor], aux;
  printf("\n------------- Questao 4 -------------\n");
  insere_lista_auto(vetor, tam_vetor);
  mostra_lista(vetor, tam_vetor);
  do {
    printf("Valor a procurar(indice): ");
    scanf("%d", &n);
    if (primo(vetor[n])) {
      printf("%d e primo\n", vetor[n]);
      aux = primoAnterior(vetor, n);
      aux >= 0 ? printf("O proximo primo anterior esta na posicao: %d\n", aux)
               : printf("Nao existe um primo anterior\n");
      aux = primoPosterior(vetor, n, tam_vetor);
      aux >= 0 ? printf("O proximo primo posterior esta na posicao: %d\n", aux)
               : printf("Nao existe um primo posterior\n");
    } else
      printf("O numero nao e primo\n");
  } while (!primo(vetor[n]));
}


x86 assembly (clang, -O0):
<question_four>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x64,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <insere_lista_auto@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <mostra_lista@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1080 <primo@plt>
cmp    $0x0,%rax
je     129f <question_four+0x12f>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <primoAnterior@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     124c <question_four+0xdc>
mov    -0x1c(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <question_four+0xea>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1060 <primoPosterior@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     128c <question_four+0x11c>
mov    -0x1c(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129a <question_four+0x12a>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ad <question_four+0x13d>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b2 <question_four+0x142>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1080 <primo@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cc <question_four+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<question_four>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %rsp,0x8(%rsp)
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10a0 <insere_lista_auto@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <mostra_lista@plt>
lea    0xe38(%rip),%r14
lea    0xe4c(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe43(%rip),%rbp
lea    0xe76(%rip),%r13
jmp    1213 <question_four+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
movslq 0x4(%rsp),%rax
mov    0x10(%rsp,%rax,4),%edi
call   1090 <primo@plt>
test   %rax,%rax
jne    12bc <question_four+0x13c>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
movslq 0x4(%rsp),%rax
mov    0x10(%rsp,%rax,4),%edi
call   1090 <primo@plt>
test   %rax,%rax
je     11f0 <question_four+0x70>
movslq 0x4(%rsp),%rax
mov    0x10(%rsp,%rax,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <primoAnterior@plt>
test   %eax,%eax
js     1270 <question_four+0xf0>
lea    0xdc5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    127c <question_four+0xfc>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
mov    $0x64,%edx
call   1070 <primoPosterior@plt>
test   %eax,%eax
js     12b0 <question_four+0x130>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fc <question_four+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe29(%rip),%rdi
jmp    11f7 <question_four+0x77>
mov    0x8(%rsp),%rsp
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0A------------- Questao 4 -------------\0A\00"
@.str.1 = [27 x i8] c"Valor a procurar(indice): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"%d e primo\0A\00"
@.str.4 = [46 x i8] c"O proximo primo anterior esta na posicao: %d\0A\00"
@.str.5 = [30 x i8] c"Nao existe um primo anterior\0A\00"
@.str.6 = [47 x i8] c"O proximo primo posterior esta na posicao: %d\0A\00"
@.str.7 = [31 x i8] c"Nao existe um primo posterior\0A\00"
@.str.8 = [22 x i8] c"O numero nao e primo\0A\00"
define void @question_four() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 100, i32* %2
%6 = load i32, i32* %2
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca i32, i64 %7
store i64 %7, i64* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 @insere_lista_auto(i32* %9, i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @mostra_lista(i32* %9, i32 %13)
br label %15
15: ; preds = %56, %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %9, i64 %19
%21 = load i32, i32* %20
%22 = call i64 @primo(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %53
24: ; preds = %15
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %9, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
%31 = call i32 @primoAnterior(i32* %9, i32 %30)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = load i32, i32* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %39
37: ; preds = %24
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = phi i32 [ %36, %34 ], [ %38, %37 ]
%41 = load i32, i32* %1
%42 = load i32, i32* %2
%43 = call i32 @primoPosterior(i32* %9, i32 %41, i32 %42)
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 %47)
br label %51
49: ; preds = %39
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = phi i32 [ %48, %46 ], [ %50, %49 ]
br label %55
53: ; preds = %15
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
br label %56
56: ; preds = %55
%57 = load i32, i32* %1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %9, i64 %58
%60 = load i32, i32* %59
%61 = call i64 @primo(i32 %60)
%62 = icmp ne i64 %61, 0
%63 = xor i1 %62, true
br i1 %63, label %15, label %64
64: ; preds = %56
%65 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"Valor a procurar(indice): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"%d e primo\0A\00"
@.str.4 = [46 x i8] c"O proximo primo anterior esta na posicao: %d\0A\00"
@.str.6 = [47 x i8] c"O proximo primo posterior esta na posicao: %d\0A\00"
@str = [39 x i8] c"\0A------------- Questao 4 -------------\00"
@str.9 = [21 x i8] c"O numero nao e primo\00"
@str.10 = [29 x i8] c"Nao existe um primo anterior\00"
@str.11 = [30 x i8] c"Nao existe um primo posterior\00"
define void @question_four() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [100 x i32]
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%7 = call i32 @insere_lista_auto(i32* %5, i32 100)
%8 = call i32 @mostra_lista(i32* %5, i32 100)
br label %9
9: ; preds = %41, %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i64 @primo(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %39, label %18
18: ; preds = %9
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %1
%25 = call i32 @primoAnterior(i32* %5, i32 %24)
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %31
29: ; preds = %18
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
%32 = load i32, i32* %1
%33 = call i32 @primoPosterior(i32* %5, i32 %32, i32 100)
%34 = icmp sgt i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 %33)
br label %41
37: ; preds = %31
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.11, i64 0, i64 0))
br label %41
39: ; preds = %9
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
br label %41
41: ; preds = %39, %37, %35
%42 = load i32, i32* %1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i64 @primo(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %9, label %48
48: ; preds = %41
ret void
}