#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*/ cache_results();
int /*<<< orphan*/ free_up_local_mem();
int /*<<< orphan*/ get_the_file_and_index(char *);
int /*<<< orphan*/ merge_and_print_results();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ search_init();
int strlen(char *);
void do_search(char *search_word) {
  int i, temp_len = 0;
  char temp[100];
  search_init();
  for (i = 0; i < strlen(search_word); i++) {
    if (search_word[i] == ' ' || search_word[i] == '\t' ||
        search_word[i] == '\n') {
      temp[temp_len] = '\0';
      get_the_file_and_index(temp);
      temp_len = 0;
      continue;
    }
    temp[temp_len++] = search_word[i];
  }
  if (temp_len != 0) {
    temp[temp_len] = '\0';
    get_the_file_and_index(temp);
  }
  merge_and_print_results();
  cache_results();
  printf("just before freeing the mem\n");
  free_up_local_mem();
}


x86 assembly (clang, -O0):
<do_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <search_init@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
cmp    %ecx,%eax
jge    123d <do_search+0xcd>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11f5 <do_search+0x85>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     11f5 <do_search+0x85>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1213 <do_search+0xa3>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
call   1080 <get_the_file_and_index@plt>
movl   $0x0,-0x10(%rbp)
jmp    122f <do_search+0xbf>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <do_search+0x24>
cmpl   $0x0,-0x10(%rbp)
je     1259 <do_search+0xe9>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
call   1080 <get_the_file_and_index@plt>
mov    $0x0,%al
call   1060 <merge_and_print_results@plt>
mov    $0x0,%al
call   1090 <cache_results@plt>
lea    0xd92(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <free_up_local_mem@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_search>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%r15
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <search_init@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1203 <do_search+0x93>
movabs $0x100000600,%r12
mov    %rsp,%r14
xor    %ebx,%ebx
jmp    11ca <do_search+0x5a>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%r13d
mov    %al,(%rsp,%rcx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11ef <do_search+0x7f>
movzbl (%r15,%rbx,1),%eax
movslq %r13d,%rcx
cmp    $0x20,%rax
ja     11b0 <do_search+0x40>
bt     %rax,%r12
jae    11b0 <do_search+0x40>
movb   $0x0,(%rsp,%rcx,1)
mov    %r14,%rdi
call   1080 <get_the_file_and_index@plt>
xor    %r13d,%r13d
jmp    11b7 <do_search+0x47>
test   %r13d,%r13d
je     1203 <do_search+0x93>
movslq %r13d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1080 <get_the_file_and_index@plt>
xor    %eax,%eax
call   1060 <merge_and_print_results@plt>
xor    %eax,%eax
call   1090 <cache_results@plt>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <free_up_local_mem@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"just before freeing the mem\0A\00"
define void @do_search(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = call i32 (...) @search_init()
store i32 0, i32* %3
br label %7
7: ; preds = %52, %1
%8 = load i32, i32* %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %55
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %36, label %20
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 9
br i1 %27, label %36, label %28
28: ; preds = %20
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %42
36: ; preds = %28, %20, %12
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%41 = call i32 @get_the_file_and_index(i8* %40)
store i32 0, i32* %4
br label %52
42: ; preds = %28
%43 = load i8*, i8** %2
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %42, %36
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %7
55: ; preds = %7
%56 = load i32, i32* %4
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%63 = call i32 @get_the_file_and_index(i8* %62)
br label %64
64: ; preds = %58, %55
%65 = call i32 (...) @merge_and_print_results()
%66 = call i32 (...) @cache_results()
%67 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%68 = call i32 (...) @free_up_local_mem()
ret void
}

LLVM IR (-O2):
@str = [28 x i8] c"just before freeing the mem\00"
define void @do_search(i8* %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @search_init()
%5 = call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %1, %20
%8 = phi i64 [ %22, %20 ], [ 0, %1 ]
%9 = phi i32 [ %21, %20 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
switch i8 %11, label %16 [
i8 32, label %12
i8 9, label %12
i8 10, label %12
]
12: ; preds = %7, %7, %7
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @get_the_file_and_index(i8* %3)
br label %20
16: ; preds = %7
%17 = add nsw i32 %9, 1
%18 = sext i32 %9 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
store i8 %11, i8* %19
br label %20
20: ; preds = %16, %12
%21 = phi i32 [ 0, %12 ], [ %17, %16 ]
%22 = add nuw nsw i64 %8, 1
%23 = call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %7, label %26
26: ; preds = %20
%27 = icmp eq i32 %21, 0
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = sext i32 %21 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i32 @get_the_file_and_index(i8* %3)
br label %32
32: ; preds = %1, %28, %26
%33 = call i32 (...) @merge_and_print_results()
%34 = call i32 (...) @cache_results()
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%36 = call i32 (...) @free_up_local_mem()
ret void
}