#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: ./wiki-link-lookup [TREC results file]\n");
    exit(1);
  }
  FILE *fi_in = fopen(argv[1], "r");
  printf("<html><body><pre>\n");
  for (;;) {
    char orig_doc[128];
    char dummy[16];
    char comp_doc[128];
    char rest_of_line[1024];
    int doc_dist;
    if (fscanf(fi_in, "%s%s%s%[^\n]\n", orig_doc, dummy, comp_doc,
               rest_of_line) < 4)
      break;
    int orig_doc_id = atoi(orig_doc);
    int comp_doc_id = atoi(comp_doc);
    if ((orig_doc_id != 0) && (comp_doc_id != 0)) {
      printf("<p><a href=\"http://en.wikipedia.org/wiki/?curid=%d\">%d</a> %s "
             "<a href=\"http://en.wikipedia.org/wiki/?curid=%d\">%d</a>%s</p>",
             doc_dist, orig_doc_id, dummy, orig_doc_id, comp_doc_id,
             rest_of_line);
      fflush(stdout);
    }
  }
  printf("</pre></body></html>\n");
  fclose(fi_in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c2 <main+0x42>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0xb0(%rbp),%rcx
lea    -0x130(%rbp),%r8
lea    -0x530(%rbp),%r9
lea    0xe35(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x4,%eax
jge    1222 <main+0xa2>
jmp    12ad <main+0x12d>
lea    -0xa0(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x538(%rbp)
lea    -0x130(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x53c(%rbp)
cmpl   $0x0,-0x538(%rbp)
je     12a8 <main+0x128>
cmpl   $0x0,-0x53c(%rbp)
je     12a8 <main+0x128>
mov    -0x534(%rbp),%esi
mov    -0x538(%rbp),%edx
lea    -0xb0(%rbp),%rcx
mov    -0x538(%rbp),%r8d
mov    -0x53c(%rbp),%r9d
lea    -0x530(%rbp),%rax
lea    0xdc2(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    11e8 <main+0x68>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x528,%rsp
cmp    $0x1,%edi
jle    12aa <main+0x11a>
mov    0x8(%rsi),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%rsi
lea    0xa0(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x120(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%r9
call   1060 <fscanf@plt>
cmp    $0x4,%eax
jge    1222 <main+0x92>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xa0(%rsp),%r12
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%rbp
jmp    1260 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xde7(%rip),%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
mov    %r14,%r9
call   1060 <fscanf@plt>
cmp    $0x3,%eax
jle    11fa <main+0x6a>
mov    %r12,%rdi
call   10a0 <atoi@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   10a0 <atoi@plt>
test   %r13d,%r13d
je     1240 <main+0xb0>
test   %eax,%eax
je     1240 <main+0xb0>
mov    %r14,(%rsp)
lea    0xdb7(%rip),%rdi
mov    %r13d,%edx
mov    %rbp,%rcx
mov    %r13d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1240 <main+0xb0>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"Usage: ./wiki-link-lookup [TREC results file]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"<html><body><pre>\0A\00"
@.str.3 = [13 x i8] c"%s%s%s%[^\0A]\0A\00"
@.str.4 = [124 x i8] c"<p><a href=\22http://en.wikipedia.org/wiki/?curid=%d\22>%d</a> %s <a href=\22http://en.wikipedia.org/wiki/?curid=%d\22>%d</a>%s</p>\00"
@stdout = global i32 0
@.str.5 = [22 x i8] c"</pre></body></html>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [128 x i8]
%8 = alloca [16 x i8]
%9 = alloca [128 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %55, %20
%27 = load i32*, i32** %6
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%32 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %29, i8* %30, i8* %31)
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %35
34: ; preds = %26
br label %56
35: ; preds = %26
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %12
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %13
%40 = load i32, i32* %12
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %35
%43 = load i32, i32* %13
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %42
%46 = load i32, i32* %11
%47 = load i32, i32* %12
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* %12
%50 = load i32, i32* %13
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %47, i8* %48, i32 %49, i32 %50, i8* %51)
%53 = load i32, i32* @stdout
%54 = call i32 @fflush(i32 %53)
br label %55
55: ; preds = %45, %42, %35
br label %26
56: ; preds = %34
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"Usage: ./wiki-link-lookup [TREC results file]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"%s%s%s%[^\0A]\0A\00"
@.str.4 = [124 x i8] c"<p><a href=\22http://en.wikipedia.org/wiki/?curid=%d\22>%d</a> %s <a href=\22http://en.wikipedia.org/wiki/?curid=%d\22>%d</a>%s</p>\00"
@stdout = global i32 0
@str = [18 x i8] c"<html><body><pre>\00"
@str.6 = [21 x i8] c"</pre></body></html>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [16 x i8]
%5 = alloca [128 x i8]
%6 = alloca [1024 x i8]
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18, i8* %19, i8* %20)
%22 = icmp slt i32 %21, 4
br i1 %22, label %36, label %23
23: ; preds = %12, %33
%24 = call i32 @atoi(i8* %17)
%25 = call i32 @atoi(i8* %19)
%26 = icmp ne i32 %24, 0
%27 = icmp ne i32 %25, 0
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([124 x i8], [124 x i8]* @.str.4, i64 0, i64 0), i32 undef, i32 %24, i8* %18, i32 %24, i32 %25, i8* %20)
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
br label %33
33: ; preds = %23, %29
%34 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18, i8* %19, i8* %20)
%35 = icmp slt i32 %34, 4
br i1 %35, label %36, label %23
36: ; preds = %33, %12
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%38 = call i32 @fclose(i32* %15)
ret i32 0
}