#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 end {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ imprimir(struct end *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int *);
struct end *seekndestroy(struct end *, char *, int);
int /*<<< orphan*/ stdin;
int teste(int, int /*<<< orphan*/, int, int);
void buscar(struct end *p) {
  int entrada;
  if (p != NULL) {
    int i;
    char procurado[51], *p_nom = &procurado[0];
    struct end *p_aux;
    for (entrada = 0; entrada < 80; entrada++)
      putchar('\n');
    printf("\nDeseja buscar um contato? (1. Sim | 0. Nao)\n");
    scanf("%i", &entrada);
    entrada = teste(entrada, 0, 1, 1);
    while (entrada != 0) {
      entrada = 0;
      while (entrada != 1) {
        printf(
            "Qual eh o nome do contato que voce busca? (Max.: %i caracteres)\n",
            51 - 1);
        procurado[0] = getchar();
        fgets(procurado, 51, stdin);
        for (i = 0; (procurado[i] != '\n') && (procurado[i] != '\0'); i++)
          ;
        procurado[i] = '\0';
        printf("O nome '%s' esta correto? (1. Sim | 0. Nao)\n", procurado);
        scanf("%i", &entrada);
        entrada = teste(entrada, 0, 1, 1);
      }
      p_aux = seekndestroy(p, p_nom, 1);
      if (p_aux != NULL)
        imprimir(p_aux, 2);
      else
        printf("O contato buscado nao esta na agenda.\n");
      printf("Deseja buscar outro contato? (1. Sim | 0. Nao)\n");
      scanf("%i", &entrada);
      entrada = teste(entrada, 0, 1, 1);
    }
  } else
    printf("Voce nao possui contatos na sua agenda.\n");
  printf("Aperte 'Enter' para voltar ao menu principal.\n");
  entrada = getchar();
  entrada = getchar();
}


x86 assembly (clang, -O0):
<buscar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     135e <buscar+0x1de>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x50,-0xc(%rbp)
jge    11c8 <buscar+0x48>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a6 <buscar+0x26>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <teste@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1359 <buscar+0x1d9>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     12e0 <buscar+0x160>
lea    0xe15(%rip),%rdi
mov    $0x32,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x50(%rbp)
lea    -0x50(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    $0x33,%esi
call   1070 <fgets@plt>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x61(%rbp)
je     1279 <buscar+0xf9>
movslq -0x10(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    1289 <buscar+0x109>
jmp    129c <buscar+0x11c>
jmp    128e <buscar+0x10e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1250 <buscar+0xd0>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd70(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <teste@plt>
mov    %eax,-0xc(%rbp)
jmp    120b <buscar+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <seekndestroy@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1314 <buscar+0x194>
mov    -0x60(%rbp),%rdi
mov    $0x2,%esi
call   1060 <imprimir@plt>
jmp    1322 <buscar+0x1a2>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcf7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <teste@plt>
mov    %eax,-0xc(%rbp)
jmp    11fa <buscar+0x7a>
jmp    136c <buscar+0x1ec>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0xc(%rbp)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
je     134d <buscar+0x1bd>
mov    $0x50,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11c0 <buscar+0x30>
movl   $0x50,0x4(%rsp)
lea    0xee9(%rip),%rdi
call   1040 <puts@plt>
lea    0xe16(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1060 <teste@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
je     1359 <buscar+0x1c9>
lea    0xde7(%rip),%r15
mov    0x2dc5(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe15(%rip),%r12
lea    0xdca(%rip),%r13
lea    0x4(%rsp),%rbp
jmp    1284 <buscar+0xf4>
nopl   (%rax)
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1060 <teste@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
je     1359 <buscar+0x1c9>
movl   $0x0,0x4(%rsp)
jmp    12cd <buscar+0x13d>
xchg   %ax,%ax
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1060 <teste@plt>
mov    %eax,0x4(%rsp)
cmp    $0x1,%eax
je     1320 <buscar+0x190>
mov    %r15,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %al,0x10(%rsp)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x33,%esi
call   1080 <fgets@plt>
xor    %eax,%eax
nopl   0x0(%rax)
movzbl 0x10(%rsp,%rax,1),%ecx
test   %cl,%cl
je     1290 <buscar+0x100>
cmp    $0xa,%cl
je     1290 <buscar+0x100>
add    $0x1,%rax
jmp    1300 <buscar+0x170>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10b0 <seekndestroy@plt>
test   %rax,%rax
je     1240 <buscar+0xb0>
mov    %rax,%rdi
mov    $0x2,%esi
call   1070 <imprimir@plt>
jmp    124c <buscar+0xbc>
lea    0xd1d(%rip),%rdi
call   1040 <puts@plt>
lea    0xd39(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1090 <getchar@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.end = type { i32 }
@.str = [46 x i8] c"\0ADeseja buscar um contato? (1. Sim | 0. Nao)\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [65 x i8] c"Qual eh o nome do contato que voce busca? (Max.: %i caracteres)\0A\00"
@stdin = global i32 0
@.str.3 = [45 x i8] c"O nome '%s' esta correto? (1. Sim | 0. Nao)\0A\00"
@.str.4 = [39 x i8] c"O contato buscado nao esta na agenda.\0A\00"
@.str.5 = [48 x i8] c"Deseja buscar outro contato? (1. Sim | 0. Nao)\0A\00"
@.str.6 = [41 x i8] c"Voce nao possui contatos na sua agenda.\0A\00"
@.str.7 = [47 x i8] c"Aperte 'Enter' para voltar ao menu principal.\0A\00"
define void @buscar(%struct.end* %0) {
%2 = alloca %struct.end*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [51 x i8]
%6 = alloca i8*
%7 = alloca %struct.end*
store %struct.end* %0, %struct.end** %2
%8 = load %struct.end*, %struct.end** %2
%9 = icmp ne %struct.end* %8, null
br i1 %9, label %10, label %86
10: ; preds = %1
%11 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
store i8* %11, i8** %6
store i32 0, i32* %3
br label %12
12: ; preds = %17, %10
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 80
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 @putchar(i8 signext 10)
br label %17
17: ; preds = %15
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %12
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, 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* %3
%24 = call i32 @teste(i32 %23, i32 0, i32 1, i32 1)
store i32 %24, i32* %3
br label %25
25: ; preds = %80, %20
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %85
28: ; preds = %25
store i32 0, i32* %3
br label %29
29: ; preds = %60, %28
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %69
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 50)
%34 = call i32 (...) @getchar()
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
store i8 %35, i8* %36
%37 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %37, i32 51, i32 %38)
store i32 0, i32* %4
br label %40
40: ; preds = %57, %32
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %54
47: ; preds = %40
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br label %54
54: ; preds = %47, %40
%55 = phi i1 [ false, %40 ], [ %53, %47 ]
br i1 %55, label %56, label %60
56: ; preds = %54
br label %57
57: ; preds = %56
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %40
60: ; preds = %54
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 %62
store i8 0, i8* %63
%64 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %64)
%66 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%67 = load i32, i32* %3
%68 = call i32 @teste(i32 %67, i32 0, i32 1, i32 1)
store i32 %68, i32* %3
br label %29
69: ; preds = %29
%70 = load %struct.end*, %struct.end** %2
%71 = load i8*, i8** %6
%72 = call %struct.end* @seekndestroy(%struct.end* %70, i8* %71, i32 1)
store %struct.end* %72, %struct.end** %7
%73 = load %struct.end*, %struct.end** %7
%74 = icmp ne %struct.end* %73, null
br i1 %74, label %75, label %78
75: ; preds = %69
%76 = load %struct.end*, %struct.end** %7
%77 = call i32 @imprimir(%struct.end* %76, i32 2)
br label %80
78: ; preds = %69
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %80
80: ; preds = %78, %75
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%82 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%83 = load i32, i32* %3
%84 = call i32 @teste(i32 %83, i32 0, i32 1, i32 1)
store i32 %84, i32* %3
br label %25
85: ; preds = %25
br label %88
86: ; preds = %1
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %86, %85
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%90 = call i32 (...) @getchar()
store i32 %90, i32* %3
%91 = call i32 (...) @getchar()
store i32 %91, i32* %3
ret void
}

LLVM IR (-O2):
%struct.end = type { i32 }
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [65 x i8] c"Qual eh o nome do contato que voce busca? (Max.: %i caracteres)\0A\00"
@stdin = global i32 0
@.str.3 = [45 x i8] c"O nome '%s' esta correto? (1. Sim | 0. Nao)\0A\00"
@str = [40 x i8] c"Voce nao possui contatos na sua agenda.\00"
@str.8 = [46 x i8] c"Aperte 'Enter' para voltar ao menu principal.\00"
@str.9 = [45 x i8] c"\0ADeseja buscar um contato? (1. Sim | 0. Nao)\00"
@str.10 = [38 x i8] c"O contato buscado nao esta na agenda.\00"
@str.11 = [47 x i8] c"Deseja buscar outro contato? (1. Sim | 0. Nao)\00"
define void @buscar(%struct.end* %0) {
%2 = alloca i32
%3 = alloca [51 x i8]
%4 = bitcast i32* %2 to i8*
%5 = icmp eq %struct.end* %0, null
br i1 %5, label %54, label %6
6: ; preds = %1
%7 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 0, %6 ], [ %11, %8 ]
%10 = tail call i32 @putchar(i8 signext 10)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, 80
br i1 %12, label %13, label %8
13: ; preds = %8
store i32 80, i32* %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.9, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = call i32 @teste(i32 %16, i32 0, i32 1, i32 1)
store i32 %17, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %53, label %19
19: ; preds = %13, %47
store i32 0, i32* %2
br label %20
20: ; preds = %19, %32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 50)
%22 = call i32 (...) @getchar()
%23 = trunc i32 %22 to i8
store i8 %23, i8* %7
%24 = load i32, i32* @stdin
%25 = call i32 @fgets(i8* %7, i32 51, i32 %24)
br label %26
26: ; preds = %30, %20
%27 = phi i64 [ %31, %30 ], [ 0, %20 ]
%28 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
switch i8 %29, label %30 [
i8 10, label %32
i8 0, label %32
]
30: ; preds = %26
%31 = add nuw i64 %27, 1
br label %26
32: ; preds = %26, %26
%33 = and i64 %27, 4294967295
%34 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%37 = load i32, i32* %2
%38 = call i32 @teste(i32 %37, i32 0, i32 1, i32 1)
store i32 %38, i32* %2
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %20
40: ; preds = %32
%41 = call %struct.end* @seekndestroy(%struct.end* %0, i8* %7, i32 1)
%42 = icmp eq %struct.end* %41, null
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @imprimir(%struct.end* %41, i32 2)
br label %47
45: ; preds = %40
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.11, i64 0, i64 0))
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%50 = load i32, i32* %2
%51 = call i32 @teste(i32 %50, i32 0, i32 1, i32 1)
store i32 %51, i32* %2
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %19
53: ; preds = %47, %13
br label %56
54: ; preds = %1
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %54, %53
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.8, i64 0, i64 0))
%58 = call i32 (...) @getchar()
store i32 %58, i32* %2
%59 = call i32 (...) @getchar()
ret void
}