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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ index_file_close(struct index_file *);
char *index_search(struct index_file *, char *);
struct index_file *open_index(char const *);
int /*<<< orphan*/ printf(char *, ...);
void search_index(const char *filename, char *key) {
  struct index_file *index = open_index(filename);
  char *value;
  value = index_search(index, key);
  if (value)
    printf("Found value:\n%s\n", value);
  else
    printf("Not found.\n");
  free(value);
  index_file_close(index);
}


x86 assembly (clang, -O0):
<search_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <open_index@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <index_search@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <search_index+0x50>
mov    -0x20(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ae <search_index+0x5e>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <index_file_close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_index>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1080 <open_index@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <index_search@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1195 <search_index+0x35>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11a1 <search_index+0x41>
lea    0xe75(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <index_file_close@plt>

LLVM IR (-O0):
%struct.index_file = type { i32 }
@.str = [17 x i8] c"Found value:\0A%s\0A\00"
@.str.1 = [12 x i8] c"Not found.\0A\00"
define void @search_index(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.index_file*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call %struct.index_file* @open_index(i8* %7)
store %struct.index_file* %8, %struct.index_file** %5
%9 = load %struct.index_file*, %struct.index_file** %5
%10 = load i8*, i8** %4
%11 = call i8* @index_search(%struct.index_file* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = load %struct.index_file*, %struct.index_file** %5
%23 = call i32 @index_file_close(%struct.index_file* %22)
ret void
}

LLVM IR (-O2):
%struct.index_file = type { i32 }
@.str = [17 x i8] c"Found value:\0A%s\0A\00"
@str = [11 x i8] c"Not found.\00"
define void @search_index(i8* %0, i8* %1) {
%3 = tail call %struct.index_file* @open_index(i8* %0)
%4 = tail call i8* @index_search(%struct.index_file* %3, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @free(i8* %4)
%12 = tail call i32 @index_file_close(%struct.index_file* %3)
ret void
}