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

/* Variables and functions */
char getch();
int lookup(struct contacts *, char *, struct contacts **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printlist(struct contacts **, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ slowprint(char *, int);
void findcon(struct contacts *head) {
  char a[20], b;
  int i = 0, j, k;
  struct contacts *l[20];
  slowprint("Enter Key Word: ", 30);
  while (((b = getch()) != 13) && (i < 20)) {
    if (b != 127) {
      putchar(b);
      a[i] = b;
      a[i + 1] = '\0';
      i++;
      k = lookup(head, a, l);
    } else {
      if (i > 0) {
        a[i] = '\0';
        i--;
        putchar('\b');
        putchar(' ');
        putchar('\b');
        k = lookup(head, a, l);
      }
    }
    printf("\e7");
    printf("\e["
           "3"
           ";"
           "1"
           "H");
    printlist(l, k);
    printf("\e8");
  }
}


x86 assembly (clang, -O0):
<findcon>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x1e,%esi
call   1070 <slowprint@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0xd1(%rbp)
je     11b2 <findcon+0x52>
cmpl   $0x14,-0x28(%rbp)
setl   %al
mov    %al,-0xd1(%rbp)
mov    -0xd1(%rbp),%al
test   $0x1,%al
jne    11c5 <findcon+0x65>
jmp    12a6 <findcon+0x146>
movsbl -0x21(%rbp),%eax
cmp    $0x7f,%eax
je     1218 <findcon+0xb8>
movsbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x21(%rbp),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1050 <lookup@plt>
mov    %eax,-0x30(%rbp)
jmp    126e <findcon+0x10e>
cmpl   $0x0,-0x28(%rbp)
jle    1269 <findcon+0x109>
movslq -0x28(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1050 <lookup@plt>
mov    %eax,-0x30(%rbp)
jmp    126e <findcon+0x10e>
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
lea    0xd93(%rip),%rdi
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1080 <printlist@plt>
lea    0xd7f(%rip),%rdi
call   1040 <printf@plt>
jmp    1187 <findcon+0x27>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findcon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rdi,%r15
lea    0xe85(%rip),%rdi
mov    $0x1e,%esi
call   1070 <slowprint@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0xd,%al
je     125e <findcon+0xfe>
mov    %eax,%r12d
lea    0x20(%rsp),%rbx
lea    0xe78(%rip),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
cmp    $0x7f,%r12b
jne    11f0 <findcon+0x90>
test   %r13d,%r13d
jle    121b <findcon+0xbb>
mov    %r13d,%eax
movb   $0x0,(%rsp,%rax,1)
add    $0xffffffff,%r13d
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    120a <findcon+0xaa>
cs nopw 0x0(%rax,%rax,1)
movsbl %r12b,%edi
call   1030 <putchar@plt>
movslq %r13d,%r13
mov    %r12b,(%rsp,%r13,1)
movb   $0x0,0x1(%rsp,%r13,1)
add    $0x1,%r13
mov    %r15,%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1050 <lookup@plt>
mov    %eax,%r14d
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <printlist@plt>
mov    %rbp,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0xd,%al
je     125e <findcon+0xfe>
mov    %eax,%r12d
cmp    $0x14,%r13d
jl     11b0 <findcon+0x50>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.contacts = type { i32 }
@.str = [17 x i8] c"Enter Key Word: \00"
@.str.1 = [3 x i8] c"\1B7\00"
@.str.2 = [7 x i8] c"\1B[3;1H\00"
@.str.3 = [3 x i8] c"\1B8\00"
define void @findcon(%struct.contacts* %0) {
%2 = alloca %struct.contacts*
%3 = alloca [20 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x %struct.contacts*]
store %struct.contacts* %0, %struct.contacts** %2
store i32 0, i32* %5
%9 = call i32 @slowprint(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 30)
br label %10
10: ; preds = %57, %1
%11 = call signext i8 (...) @getch()
store i8 %11, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 13
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 20
br label %17
17: ; preds = %14, %10
%18 = phi i1 [ false, %10 ], [ %16, %14 ]
br i1 %18, label %19, label %64
19: ; preds = %17
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 127
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i8, i8* %4
%25 = call i32 @putchar(i8 signext %24)
%26 = load i8, i8* %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %28
store i8 %26, i8* %29
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = load %struct.contacts*, %struct.contacts** %2
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%38 = getelementptr inbounds [20 x %struct.contacts*], [20 x %struct.contacts*]* %8, i64 0, i64 0
%39 = call i32 @lookup(%struct.contacts* %36, i8* %37, %struct.contacts** %38)
store i32 %39, i32* %7
br label %57
40: ; preds = %19
%41 = load i32, i32* %5
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %56
43: ; preds = %40
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* %5
%48 = add nsw i32 %47, -1
store i32 %48, i32* %5
%49 = call i32 @putchar(i8 signext 8)
%50 = call i32 @putchar(i8 signext 32)
%51 = call i32 @putchar(i8 signext 8)
%52 = load %struct.contacts*, %struct.contacts** %2
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%54 = getelementptr inbounds [20 x %struct.contacts*], [20 x %struct.contacts*]* %8, i64 0, i64 0
%55 = call i32 @lookup(%struct.contacts* %52, i8* %53, %struct.contacts** %54)
store i32 %55, i32* %7
br label %56
56: ; preds = %43, %40
br label %57
57: ; preds = %56, %23
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%60 = getelementptr inbounds [20 x %struct.contacts*], [20 x %struct.contacts*]* %8, i64 0, i64 0
%61 = load i32, i32* %7
%62 = call i32 @printlist(%struct.contacts** %60, i32 %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %10
64: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.contacts = type { i32 }
@.str = [17 x i8] c"Enter Key Word: \00"
@.str.1 = [3 x i8] c"\1B7\00"
@.str.2 = [7 x i8] c"\1B[3;1H\00"
@.str.3 = [3 x i8] c"\1B8\00"
define void @findcon(%struct.contacts* %0) {
%2 = alloca [20 x i8]
%3 = alloca [20 x %struct.contacts*]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = bitcast [20 x %struct.contacts*]* %3 to i8*
%6 = tail call i32 @slowprint(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 30)
%7 = call signext i8 (...) @getch()
%8 = icmp eq i8 %7, 13
br i1 %8, label %46, label %9
9: ; preds = %1
%10 = getelementptr inbounds [20 x %struct.contacts*], [20 x %struct.contacts*]* %3, i64 0, i64 0
br label %11
11: ; preds = %9, %35
%12 = phi i8 [ %7, %9 ], [ %42, %35 ]
%13 = phi i32 [ undef, %9 ], [ %37, %35 ]
%14 = phi i32 [ 0, %9 ], [ %36, %35 ]
%15 = icmp eq i8 %12, 127
br i1 %15, label %23, label %16
16: ; preds = %11
%17 = call i32 @putchar(i8 signext %12)
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %18
store i8 %12, i8* %19
%20 = add nsw i32 %14, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %21
store i8 0, i8* %22
br label %32
23: ; preds = %11
%24 = icmp sgt i32 %14, 0
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = zext i32 %14 to i64
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = add nsw i32 %14, -1
%29 = call i32 @putchar(i8 signext 8)
%30 = call i32 @putchar(i8 signext 32)
%31 = call i32 @putchar(i8 signext 8)
br label %32
32: ; preds = %16, %25
%33 = phi i32 [ %28, %25 ], [ %20, %16 ]
%34 = call i32 @lookup(%struct.contacts* %0, i8* %4, %struct.contacts** %10)
br label %35
35: ; preds = %32, %23
%36 = phi i32 [ %14, %23 ], [ %33, %32 ]
%37 = phi i32 [ %13, %23 ], [ %34, %32 ]
%38 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @printlist(%struct.contacts** %10, i32 %37)
%41 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = call signext i8 (...) @getch()
%43 = icmp ne i8 %42, 13
%44 = icmp slt i32 %36, 20
%45 = select i1 %43, i1 %44, i1 false
br i1 %45, label %11, label %46
46: ; preds = %35, %1
ret void
}