#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close_bss();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ initialise_bss();
int /*<<< orphan*/ okapi_search(int, char **, int *, int *);
int /*<<< orphan*/ okapi_show(int, int /*<<< orphan*/, int, char *, int);
int open_database(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ show_database(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int db_open = 0;
  char database_name[256];
  int docset;
  int npostings;
  int docs_to_show;
  char result[10 * 1024];
  char **keywords;
  if (argc < 3) {
    fprintf(stderr, "ERROR: Insufficient arguments passed to program.");
    exit(EXIT_FAILURE);
  }
  sprintf(database_name, "%s", argv[1]);
  keywords = argv + 2;
  int i;
  for (i = 0; i < argc - 2; i++) {
    fprintf(stdout, "%s\n", keywords[i]);
  }
  initialise_bss();
  if (show_database(result, 10 * 1024) == 0) {
    printf("database info:\n%s\n", result);
  }
  db_open = open_database(database_name);
  if (db_open) {
    printf("Okapi initialisation complete.\n");
    okapi_search(argc - 2, keywords, &docset, &npostings);
    if ((docset != -1) && (npostings > 0)) {
      fprintf(stderr, "Search OK: set = %d, np = %d\n", docset, npostings);
      docs_to_show = (npostings > 5) ? 5 : npostings;
      okapi_show(docset, 0, docs_to_show, result, 10 * 1024);
      fprintf(stdout, "%s\n", result);
    } else {
      fprintf(stderr, "ERROR: Quitting.\n");
    }
  } else {
    fprintf(stderr, "ERROR opening [%s]\n", database_name);
  }
  close_bss();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2940,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ef <main+0x4f>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2c(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x2938(%rbp)
movl   $0x0,-0x293c(%rbp)
mov    -0x293c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1274 <main+0xd4>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x2938(%rbp),%rax
movslq -0x293c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x293c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x293c(%rbp)
jmp    1223 <main+0x83>
mov    $0x0,%al
call   1080 <initialise_bss@plt>
lea    -0x2930(%rbp),%rdi
mov    $0x2800,%esi
call   1040 <show_database@plt>
cmp    $0x0,%rax
jne    12ab <main+0x10b>
lea    -0x2930(%rbp),%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rdi
call   10a0 <open_database@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     13c3 <main+0x223>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x2938(%rbp),%rsi
lea    -0x124(%rbp),%rdx
lea    -0x128(%rbp),%rcx
call   1030 <okapi_search@plt>
cmpl   $0xffffffff,-0x124(%rbp)
je     13a7 <main+0x207>
cmpl   $0x0,-0x128(%rbp)
jle    13a7 <main+0x207>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    -0x124(%rbp),%edx
mov    -0x128(%rbp),%ecx
lea    0xd3f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x5,-0x128(%rbp)
jle    134c <main+0x1ac>
mov    $0x5,%eax
mov    %eax,-0x2940(%rbp)
jmp    1358 <main+0x1b8>
mov    -0x128(%rbp),%eax
mov    %eax,-0x2940(%rbp)
mov    -0x2940(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x124(%rbp),%edi
mov    -0x12c(%rbp),%edx
lea    -0x2930(%rbp),%rcx
xor    %esi,%esi
mov    $0x2800,%r8d
call   1060 <okapi_show@plt>
mov    0x2c45(%rip),%rax
mov    (%rax),%edi
lea    -0x2930(%rbp),%rdx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13be <main+0x21e>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
lea    0xcce(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13e1 <main+0x241>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1090 <close_bss@plt>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2910,%rsp
cmp    $0x2,%edi
jg     11ea <main+0x3a>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcpy@plt>
add    $0x10,%r14
add    $0xfffffffe,%r15d
mov    0x2dc3(%rip),%r12
lea    0xe2c(%rip),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    (%r14,%rbx,8),%rdx
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1220 <main+0x70>
xor    %eax,%eax
call   10a0 <initialise_bss@plt>
lea    0x110(%rsp),%rdi
mov    $0x2800,%esi
call   1040 <show_database@plt>
test   %rax,%rax
jne    126f <main+0xbf>
lea    0xdd1(%rip),%rdi
lea    0x110(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rdi
call   10c0 <open_database@plt>
test   %eax,%eax
jne    1297 <main+0xe7>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
lea    0x10(%rsp),%rdx
jmp    1319 <main+0x169>
lea    0xdea(%rip),%rdi
call   1060 <puts@plt>
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <okapi_search@plt>
mov    0xc(%rsp),%edx
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
cmp    $0xffffffff,%edx
je     1322 <main+0x172>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
jle    1322 <main+0x172>
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x8(%rsp),%eax
cmp    $0x5,%eax
mov    $0x5,%edx
cmovl  %eax,%edx
mov    0xc(%rsp),%edi
lea    0x110(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rcx
mov    $0x2800,%r8d
call   1080 <okapi_show@plt>
mov    (%r12),%edi
lea    0xd2a(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1330 <main+0x180>
lea    0xd39(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
call   10b0 <close_bss@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Insufficient arguments passed to program.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [19 x i8] c"database info:\0A%s\0A\00"
@.str.4 = [32 x i8] c"Okapi initialisation complete.\0A\00"
@.str.5 = [30 x i8] c"Search OK: set = %d, np = %d\0A\00"
@.str.6 = [18 x i8] c"ERROR: Quitting.\0A\00"
@.str.7 = [20 x i8] c"ERROR opening [%s]\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10240 x i8]
%12 = alloca i8**
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
store i8** %28, i8*** %12
store i32 0, i32* %13
br label %29
29: ; preds = %42, %21
%30 = load i32, i32* %13
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 2
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %45
34: ; preds = %29
%35 = load i32, i32* @stdout
%36 = load i8**, i8*** %12
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %34
%43 = load i32, i32* %13
%44 = add nsw i32 %43, 1
store i32 %44, i32* %13
br label %29
45: ; preds = %29
%46 = call i32 (...) @initialise_bss()
%47 = getelementptr inbounds [10240 x i8], [10240 x i8]* %11, i64 0, i64 0
%48 = call i64 @show_database(i8* %47, i32 10240)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = getelementptr inbounds [10240 x i8], [10240 x i8]* %11, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %45
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%55 = call i32 @open_database(i8* %54)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %92
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%60 = load i32, i32* %4
%61 = sub nsw i32 %60, 2
%62 = load i8**, i8*** %12
%63 = call i32 @okapi_search(i32 %61, i8** %62, i32* %8, i32* %9)
%64 = load i32, i32* %8
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %88
66: ; preds = %58
%67 = load i32, i32* %9
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %88
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i32, i32* %8
%72 = load i32, i32* %9
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %71, i32 %72)
%74 = load i32, i32* %9
%75 = icmp sgt i32 %74, 5
br i1 %75, label %76, label %77
76: ; preds = %69
br label %79
77: ; preds = %69
%78 = load i32, i32* %9
br label %79
79: ; preds = %77, %76
%80 = phi i32 [ 5, %76 ], [ %78, %77 ]
store i32 %80, i32* %10
%81 = load i32, i32* %8
%82 = load i32, i32* %10
%83 = getelementptr inbounds [10240 x i8], [10240 x i8]* %11, i64 0, i64 0
%84 = call i32 @okapi_show(i32 %81, i32 0, i32 %82, i8* %83, i32 10240)
%85 = load i32, i32* @stdout
%86 = getelementptr inbounds [10240 x i8], [10240 x i8]* %11, i64 0, i64 0
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %86)
br label %91
88: ; preds = %66, %58
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %91
91: ; preds = %88, %79
br label %96
92: ; preds = %53
%93 = load i32, i32* @stderr
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %92, %91
%97 = call i32 (...) @close_bss()
%98 = load i32, i32* @EXIT_SUCCESS
%99 = call i32 @exit(i32 %98)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Insufficient arguments passed to program.\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [19 x i8] c"database info:\0A%s\0A\00"
@.str.5 = [30 x i8] c"Search OK: set = %d, np = %d\0A\00"
@.str.6 = [18 x i8] c"ERROR: Quitting.\0A\00"
@.str.7 = [20 x i8] c"ERROR opening [%s]\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [31 x i8] c"Okapi initialisation complete.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10240 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i8* @strcpy(i8* %7, i8* dereferenceable(1) %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = add nsw i32 %0, -2
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %17, %24
%25 = phi i64 [ 0, %17 ], [ %30, %24 ]
%26 = load i32, i32* @stdout
%27 = getelementptr inbounds i8*, i8** %21, i64 %25
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = add nuw nsw i64 %25, 1
%31 = icmp eq i64 %30, %23
br i1 %31, label %32, label %24
32: ; preds = %24
%33 = call i32 (...) @initialise_bss()
%34 = call i64 @show_database(i8* %10, i32 10240)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %38
38: ; preds = %36, %32
%39 = call i32 @open_database(i8* %7)
%40 = icmp eq i32 %39, 0
br i1 %40, label %61, label %41
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%43 = call i32 @okapi_search(i32 %22, i8** %21, i32* %4, i32* %5)
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, -1
%46 = load i32, i32* %5
%47 = icmp sgt i32 %46, 0
%48 = select i1 %45, i1 %47, i1 false
%49 = load i32, i32* @stderr
br i1 %48, label %50, label %59
50: ; preds = %41
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %46)
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 5
%54 = select i1 %53, i32 %52, i32 5
%55 = load i32, i32* %4
%56 = call i32 @okapi_show(i32 %55, i32 0, i32 %54, i8* %10, i32 10240)
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %64
59: ; preds = %41
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %64
61: ; preds = %38
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %7)
br label %64
64: ; preds = %50, %59, %61
%65 = call i32 (...) @close_bss()
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}