#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 fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ processfile(char *, char *);
char *strstr(char *, char *);
void wsjread(FILE *fp) {
  char *doc_start;
  char *doc_end;
  char buf[(512 * 1024)];
  int buflen = fread(buf, 1, (512 * 1024) - 1, fp);
  int doclen;
  buf[buflen] = '\0';
  for (;;) {
    if ((doc_start = strstr(buf, "<DOC>")) != NULL) {
      if ((doc_end = strstr(buf, "</DOC>")) != NULL) {
        doc_end += 7;
        doclen = doc_end - buf;
        char *docid_start = strstr(buf, "<DOCNO>");
        char *docid_end = strstr(docid_start + 1, "</DOCNO>");
        docid_start += 1;
        docid_end -= 1;
        docid_start += 7;
        int docid_len = docid_end - docid_start;
        char *docid = malloc(docid_len + 1);
        memcpy(docid, docid_start, docid_len);
        docid[docid_len] = '\0';
        char *title_start = strstr(buf, "<HL>");
        char *title_end = strstr(title_start + 1, "</HL>");
        title_start += 1;
        title_end -= 0;
        title_start += 4;
        int title_len = title_end - title_start;
        char *filename = malloc(title_len + 1);
        memcpy(filename, title_start, title_len);
        filename[title_len] = '\0';
        processfile(docid, filename);
        memmove(buf, doc_end, buflen - doclen);
        buflen -= doclen;
        buflen += fread(buf + buflen, 1, (512 * 1024) - 1 - buflen, fp);
        buf[buflen] = '\0';
      }
    } else {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<wsjread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80070,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x80020(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7ffff,%edx
call   1040 <fread@plt>
mov    %eax,-0x80024(%rbp)
movslq -0x80024(%rbp),%rax
movb   $0x0,-0x80020(%rbp,%rax,1)
lea    -0x80020(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1413 <wsjread+0x2b3>
lea    -0x80020(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     140e <wsjread+0x2ae>
mov    -0x18(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
lea    -0x80020(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x80028(%rbp)
lea    -0x80020(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x80030(%rbp)
mov    -0x80030(%rbp),%rdi
add    $0x1,%rdi
lea    0xde9(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x80038(%rbp)
mov    -0x80030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80030(%rbp)
mov    -0x80038(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x80038(%rbp)
mov    -0x80030(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x80030(%rbp)
mov    -0x80038(%rbp),%rax
mov    -0x80030(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x8003c(%rbp)
mov    -0x8003c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x80048(%rbp)
mov    -0x80048(%rbp),%rdi
mov    -0x80030(%rbp),%rsi
mov    -0x8003c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x80048(%rbp),%rax
movslq -0x8003c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x80020(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x80050(%rbp)
mov    -0x80050(%rbp),%rdi
add    $0x1,%rdi
lea    0xd32(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x80058(%rbp)
mov    -0x80050(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80050(%rbp)
mov    -0x80058(%rbp),%rax
mov    %rax,-0x80058(%rbp)
mov    -0x80050(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x80050(%rbp)
mov    -0x80058(%rbp),%rax
mov    -0x80050(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x8005c(%rbp)
mov    -0x8005c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x80068(%rbp)
mov    -0x80068(%rbp),%rdi
mov    -0x80050(%rbp),%rsi
mov    -0x8005c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x80068(%rbp),%rax
movslq -0x8005c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x80048(%rbp),%rdi
mov    -0x80068(%rbp),%rsi
call   1030 <processfile@plt>
lea    -0x80020(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x80024(%rbp),%edx
sub    -0x80028(%rbp),%edx
call   1070 <memmove@plt>
mov    -0x80028(%rbp),%ecx
mov    -0x80024(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80024(%rbp)
lea    -0x80020(%rbp),%rdi
movslq -0x80024(%rbp),%rax
add    %rax,%rdi
mov    $0x7ffff,%edx
sub    -0x80024(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
add    -0x80024(%rbp),%eax
mov    %eax,-0x80024(%rbp)
movslq -0x80024(%rbp),%rax
movb   $0x0,-0x80020(%rbp,%rax,1)
jmp    1418 <wsjread+0x2b8>
jmp    141d <wsjread+0x2bd>
jmp    119e <wsjread+0x3e>
add    $0x80070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wsjread>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80018,%rsp
mov    %rdi,%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x7ffff,%edx
mov    %rcx,0x8(%rsp)
call   1040 <fread@plt>
mov    %eax,(%rsp)
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     12f5 <wsjread+0x195>
lea    0x10(%rsp),%rbp
jmp    11d8 <wsjread+0x78>
nopl   0x0(%rax)
mov    %rbp,%rdi
lea    0xe36(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     12f5 <wsjread+0x195>
mov    %rbp,%rdi
lea    0xe24(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11c0 <wsjread+0x60>
mov    %rax,%r13
add    $0x7,%r13
mov    %ebp,%eax
sub    %r13d,%eax
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
lea    0xe07(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
lea    0xdfc(%rip),%rsi
call   1080 <strstr@plt>
add    $0x8,%r15
mov    %r15,%r12
not    %r12
add    %rax,%r12
lea    0x1(%r12),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
lea    0x10(%rsp),%rdi
lea    0xdc4(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
lea    0xdb6(%rip),%rsi
call   1080 <strstr@plt>
mov    (%rsp),%r12d
mov    %rax,%rbp
add    $0x5,%rbx
sub    %rbx,%rbp
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
lea    0x10(%rsp),%rbp
mov    %r15,%rsi
call   1030 <processfile@plt>
add    0x4(%rsp),%r12d
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1070 <memmove@plt>
movslq %r12d,%rbx
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x7ffff,%edx
sub    %ebx,%edx
mov    $0x1,%esi
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
add    %ebx,%eax
mov    %eax,(%rsp)
cltq
movb   $0x0,0x10(%rsp,%rax,1)
jmp    11c0 <wsjread+0x60>
add    $0x80018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"<DOC>\00"
@.str.1 = [7 x i8] c"</DOC>\00"
@.str.2 = [8 x i8] c"<DOCNO>\00"
@.str.3 = [9 x i8] c"</DOCNO>\00"
@.str.4 = [5 x i8] c"<HL>\00"
@.str.5 = [6 x i8] c"</HL>\00"
define void @wsjread(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [524288 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
store i32* %0, i32** %2
%16 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %2
%18 = call i32 @fread(i8* %16, i32 1, i32 524287, i32* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %122, %1
%23 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %121
26: ; preds = %22
%27 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %120
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 7
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %7
%39 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%40 = call i8* @strstr(i8* %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i8* @strstr(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %43, i8** %9
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %45, i8** %8
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i64 -1
store i8* %47, i8** %9
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i64 7
store i8* %49, i8** %8
%50 = load i8*, i8** %9
%51 = load i8*, i8** %8
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = trunc i64 %54 to i32
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
%58 = call i8* @malloc(i32 %57)
store i8* %58, i8** %11
%59 = load i8*, i8** %11
%60 = load i8*, i8** %8
%61 = load i32, i32* %10
%62 = call i32 @memcpy(i8* %59, i8* %60, i32 %61)
%63 = load i8*, i8** %11
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%68 = call i8* @strstr(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %68, i8** %12
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = call i8* @strstr(i8* %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i8* %71, i8** %13
%72 = load i8*, i8** %12
%73 = getelementptr inbounds i8, i8* %72, i64 1
store i8* %73, i8** %12
%74 = load i8*, i8** %13
%75 = getelementptr inbounds i8, i8* %74, i64 0
store i8* %75, i8** %13
%76 = load i8*, i8** %12
%77 = getelementptr inbounds i8, i8* %76, i64 4
store i8* %77, i8** %12
%78 = load i8*, i8** %13
%79 = load i8*, i8** %12
%80 = ptrtoint i8* %78 to i64
%81 = ptrtoint i8* %79 to i64
%82 = sub i64 %80, %81
%83 = trunc i64 %82 to i32
store i32 %83, i32* %14
%84 = load i32, i32* %14
%85 = add nsw i32 %84, 1
%86 = call i8* @malloc(i32 %85)
store i8* %86, i8** %15
%87 = load i8*, i8** %15
%88 = load i8*, i8** %12
%89 = load i32, i32* %14
%90 = call i32 @memcpy(i8* %87, i8* %88, i32 %89)
%91 = load i8*, i8** %15
%92 = load i32, i32* %14
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
store i8 0, i8* %94
%95 = load i8*, i8** %11
%96 = load i8*, i8** %15
%97 = call i32 @processfile(i8* %95, i8* %96)
%98 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%99 = load i8*, i8** %4
%100 = load i32, i32* %6
%101 = load i32, i32* %7
%102 = sub nsw i32 %100, %101
%103 = call i32 @memmove(i8* %98, i8* %99, i32 %102)
%104 = load i32, i32* %7
%105 = load i32, i32* %6
%106 = sub nsw i32 %105, %104
store i32 %106, i32* %6
%107 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 0
%108 = load i32, i32* %6
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = load i32, i32* %6
%112 = sub nsw i32 524287, %111
%113 = load i32*, i32** %2
%114 = call i32 @fread(i8* %110, i32 1, i32 %112, i32* %113)
%115 = load i32, i32* %6
%116 = add nsw i32 %115, %114
store i32 %116, i32* %6
%117 = load i32, i32* %6
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [524288 x i8], [524288 x i8]* %5, i64 0, i64 %118
store i8 0, i8* %119
br label %120
120: ; preds = %30, %26
br label %122
121: ; preds = %22
br label %123
122: ; preds = %120
br label %22
123: ; preds = %121
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"<DOC>\00"
@.str.1 = [7 x i8] c"</DOC>\00"
@.str.2 = [8 x i8] c"<DOCNO>\00"
@.str.3 = [9 x i8] c"</DOCNO>\00"
@.str.4 = [5 x i8] c"<HL>\00"
@.str.5 = [6 x i8] c"</HL>\00"
define void @wsjread(i32* nocapture %0) {
%2 = alloca [524288 x i8]
%3 = getelementptr inbounds [524288 x i8], [524288 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i32 524287, i32* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [524288 x i8], [524288 x i8]* %2, i64 0, i64 %5
store i8 0, i8* %6
%7 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %63, label %9
9: ; preds = %1
%10 = ptrtoint [524288 x i8]* %2 to i64
br label %11
11: ; preds = %9, %59
%12 = phi i32 [ %4, %9 ], [ %60, %59 ]
%13 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %59, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %13, i64 7
%17 = ptrtoint i8* %16 to i64
%18 = sub i64 %10, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i8* @strstr(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = getelementptr inbounds i8, i8* %20, i64 8
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = add nsw i32 %28, 1
%30 = call i8* @malloc(i32 %29)
%31 = call i32 @memcpy(i8* %30, i8* %24, i32 %28)
%32 = shl i64 %27, 32
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
%35 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = call i8* @strstr(i8* %36, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%38 = getelementptr inbounds i8, i8* %35, i64 5
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
%43 = add nsw i32 %42, 1
%44 = call i8* @malloc(i32 %43)
%45 = call i32 @memcpy(i8* %44, i8* %38, i32 %42)
%46 = shl i64 %41, 32
%47 = ashr exact i64 %46, 32
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
%49 = call i32 @processfile(i8* %30, i8* %44)
%50 = add i32 %12, %19
%51 = call i32 @memmove(i8* %3, i8* %16, i32 %50)
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds [524288 x i8], [524288 x i8]* %2, i64 0, i64 %52
%54 = sub nsw i32 524287, %50
%55 = call i32 @fread(i8* %53, i32 1, i32 %54, i32* %0)
%56 = add nsw i32 %55, %50
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [524288 x i8], [524288 x i8]* %2, i64 0, i64 %57
store i8 0, i8* %58
br label %59
59: ; preds = %11, %15
%60 = phi i32 [ %56, %15 ], [ %12, %11 ]
%61 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %11
63: ; preds = %59, %1
ret void
}