#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 */
struct nodod {
  int dummy;
};

/* Variables and functions */
int count(struct nodod **);
int excluiNodo(struct nodod **, int);
int /*<<< orphan*/ imprime(struct nodod **);
int insereAntesValor(struct nodod **, int, int);
int /*<<< orphan*/ insereUltimo(struct nodod **, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int i = 0;
  struct nodod *p = NULL;
  srand(time(NULL));
  for (i = 0; i < 25; i++) {
    int rnd = rand() % 100;
    insereUltimo(&p, rnd);
  }
  imprime(&p);
  int valPsq;
  printf("Digite um valor a ser pesquisado na LDE circular: ");
  scanf("%i", &valPsq);
  int valIns;
  printf(
      "Digite o valor a ser inserido antes do valor anterior, se encontrado: ");
  scanf("%i", &valIns);
  int statusInsereAntesValor = insereAntesValor(&p, valPsq, valIns);
  if (statusInsereAntesValor == 0) {
    printf("Valor de pesquisa não encontrado.\n");
  } else if (statusInsereAntesValor == -1) {
    printf("Não foi possível alocar a estrutura.\n");
  }
  imprime(&p);
  int valDel;
  printf("Digite um valor a ser deletado da LDE circular: ");
  scanf("%i", &valDel);
  int statusExcluiNodo = excluiNodo(&p, valDel);
  if (statusExcluiNodo == 0) {
    printf("O valor selecionado não foi encontrado.\n");
  }
  imprime(&p);
  printf("A LDE circular possui %i nodos.\n", count(&p));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x19,-0x8(%rbp)
jge    120b <main+0x6b>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   10a0 <insereUltimo@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d5 <main+0x35>
lea    -0x10(%rbp),%rdi
call   1060 <imprime@plt>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <scanf@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdec(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    -0x10(%rbp),%rdi
call   1050 <insereAntesValor@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    127f <main+0xdf>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129c <main+0xfc>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1297 <main+0xf7>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129c <main+0xfc>
lea    -0x10(%rbp),%rdi
call   1060 <imprime@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd79(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x24(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   10b0 <excluiNodo@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    12ea <main+0x14a>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1060 <imprime@plt>
lea    -0x10(%rbp),%rdi
call   1030 <count@plt>
mov    %eax,%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    $0x19,%ebp
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rsi
imul   $0x51eb851f,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%esi
mov    %rbx,%rdi
call   10b0 <insereUltimo@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x30>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1070 <imprime@plt>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe01(%rip),%rbx
lea    0x1c(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <scanf@plt>
lea    0xdf0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <scanf@plt>
mov    0x1c(%rsp),%esi
mov    0x18(%rsp),%edx
mov    %r14,%rdi
call   1060 <insereAntesValor@plt>
test   %eax,%eax
je     127c <main+0xcc>
cmp    $0xffffffff,%eax
jne    1288 <main+0xd8>
lea    0xe7e(%rip),%rdi
jmp    1283 <main+0xd3>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <imprime@plt>
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd89(%rip),%rdi
lea    0x14(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   10c0 <excluiNodo@plt>
test   %eax,%eax
jne    12d0 <main+0x120>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <imprime@plt>
mov    %rbx,%rdi
call   1030 <count@plt>
lea    0xdc2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.nodod = type { i32 }
@.str = [51 x i8] c"Digite um valor a ser pesquisado na LDE circular: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [71 x i8] c"Digite o valor a ser inserido antes do valor anterior, se encontrado: \00"
@.str.3 = [36 x i8] c"Valor de pesquisa n\C3\A3o encontrado.\0A\00"
@.str.4 = [40 x i8] c"N\C3\A3o foi poss\C3\ADvel alocar a estrutura.\0A\00"
@.str.5 = [49 x i8] c"Digite um valor a ser deletado da LDE circular: \00"
@.str.6 = [42 x i8] c"O valor selecionado n\C3\A3o foi encontrado.\0A\00"
@.str.7 = [33 x i8] c"A LDE circular possui %i nodos.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.nodod*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store %struct.nodod* null, %struct.nodod** %3
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %2
br label %12
12: ; preds = %20, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 25
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 100
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = call i32 @insereUltimo(%struct.nodod** %3, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %12
23: ; preds = %12
%24 = call i32 @imprime(%struct.nodod** %3)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @insereAntesValor(%struct.nodod** %3, i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %23
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %42
36: ; preds = %23
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
br label %42
42: ; preds = %41, %34
%43 = call i32 @imprime(%struct.nodod** %3)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%46 = load i32, i32* %8
%47 = call i32 @excluiNodo(%struct.nodod** %3, i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %42
%53 = call i32 @imprime(%struct.nodod** %3)
%54 = call i32 @count(%struct.nodod** %3)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %54)
ret i32 0
}

LLVM IR (-O2):
%struct.nodod = type { i32 }
@.str = [51 x i8] c"Digite um valor a ser pesquisado na LDE circular: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [71 x i8] c"Digite o valor a ser inserido antes do valor anterior, se encontrado: \00"
@.str.5 = [49 x i8] c"Digite um valor a ser deletado da LDE circular: \00"
@.str.7 = [33 x i8] c"A LDE circular possui %i nodos.\0A\00"
@str = [41 x i8] c"O valor selecionado n\C3\A3o foi encontrado.\00"
@str.8 = [39 x i8] c"N\C3\A3o foi poss\C3\ADvel alocar a estrutura.\00"
@str.9 = [35 x i8] c"Valor de pesquisa n\C3\A3o encontrado.\00"
define i32 @main() {
%1 = alloca %struct.nodod*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast %struct.nodod** %1 to i8*
store %struct.nodod* null, %struct.nodod** %1
%6 = tail call i32 @time(i32* null)
%7 = tail call i32 @srand(i32 %6)
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %13, %8 ]
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = call i32 @insereUltimo(%struct.nodod** %1, i32 %11)
%13 = add nuw nsw i32 %9, 1
%14 = icmp eq i32 %13, 25
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = call i32 @imprime(%struct.nodod** %1)
%17 = bitcast i32* %2 to i8*
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%20 = bitcast i32* %3 to i8*
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = call i32 @insereAntesValor(%struct.nodod** %1, i32 %23, i32 %24)
switch i32 %25, label %30 [
i32 0, label %27
i32 -1, label %26
]
26: ; preds = %15
br label %27
27: ; preds = %15, %26
%28 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0), %26 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.9, i64 0, i64 0), %15 ]
%29 = call i32 @puts(i8* dereferenceable(1) %28)
br label %30
30: ; preds = %27, %15
%31 = call i32 @imprime(%struct.nodod** %1)
%32 = bitcast i32* %4 to i8*
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%35 = load i32, i32* %4
%36 = call i32 @excluiNodo(%struct.nodod** %1, i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
%41 = call i32 @imprime(%struct.nodod** %1)
%42 = call i32 @count(%struct.nodod** %1)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %42)
ret i32 0
}