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

/* Variables and functions */
unsigned int LotDocIDOfset(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reclose(struct reformat *);
scalar_t__ renget(struct reformat *, int);
struct reformat *reopen(int, int, char *, char *, int);
int main(int argc, char *argv[]) {
  struct reformat *redi;
  int i;
  int LotNr;
  unsigned int DocID;
  unsigned int rank;
  if (argc < 3) {
    printf("This program reads a PopRank file.\n\n\tUsage: ./readPopRank 1 "
           "subname");
    exit(0);
  }
  LotNr = atoi(argv[1]);
  char *subname = argv[2];
  DocID = 0;
  if ((redi = reopen(LotNr, sizeof(unsigned char), "PopRank", subname, 0x4)) ==
      NULL) {
    perror("reopen");
    exit(-1);
  }
  DocID = LotDocIDOfset(LotNr);
  for (i = 0; i < 500000; i++) {
    rank = *((unsigned char *)renget(redi, i));
    if (rank != 0) {
      printf("DocID: %u, rank: %d\n", DocID, rank);
    }
    ++DocID;
  }
  reclose(redi);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b5 <main+0x35>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
lea    0xe59(%rip),%rdx
mov    $0x4,%r8d
call   1050 <reopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121a <main+0x9a>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
call   10a0 <LotDocIDOfset@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x7a120,-0x1c(%rbp)
jge    1280 <main+0x100>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <renget@plt>
movzbl (%rax),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1269 <main+0xe9>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122c <main+0xac>
mov    -0x18(%rbp),%rdi
call   1060 <reclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jle    121f <main+0x9f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rcx
lea    0xe9a(%rip),%rdx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x4,%r8d
call   1050 <reopen@plt>
test   %rax,%rax
je     1234 <main+0xb4>
mov    %rax,%r12
mov    %ebp,%edi
call   10a0 <LotDocIDOfset@plt>
mov    %eax,%r14d
lea    0xe7e(%rip),%r15
xor    %ebx,%ebx
jmp    11eb <main+0x6b>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x7a120,%ebx
je     120c <main+0x8c>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <renget@plt>
movzbl (%rax),%edx
test   %edx,%edx
je     11e0 <main+0x60>
lea    (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11e0 <main+0x60>
mov    %r12,%rdi
call   1060 <reclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.reformat = type { i32 }
@.str = [68 x i8] c"This program reads a PopRank file.\0A\0A\09Usage: ./readPopRank 1 subname\00"
@.str.1 = [8 x i8] c"PopRank\00"
@.str.2 = [7 x i8] c"reopen\00"
@.str.3 = [21 x i8] c"DocID: %u, rank: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.reformat*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %11
store i32 0, i32* %9
%25 = load i32, i32* %8
%26 = load i8*, i8** %11
%27 = call %struct.reformat* @reopen(i32 %25, i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 4)
store %struct.reformat* %27, %struct.reformat** %6
%28 = icmp eq %struct.reformat* %27, null
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %17
%33 = load i32, i32* %8
%34 = call i32 @LotDocIDOfset(i32 %33)
store i32 %34, i32* %9
store i32 0, i32* %7
br label %35
35: ; preds = %54, %32
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 500000
br i1 %37, label %38, label %57
38: ; preds = %35
%39 = load %struct.reformat*, %struct.reformat** %6
%40 = load i32, i32* %7
%41 = call i64 @renget(%struct.reformat* %39, i32 %40)
%42 = inttoptr i64 %41 to i8*
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %38
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %49)
br label %51
51: ; preds = %47, %38
%52 = load i32, i32* %9
%53 = add i32 %52, 1
store i32 %53, i32* %9
br label %54
54: ; preds = %51
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %35
57: ; preds = %35
%58 = load %struct.reformat*, %struct.reformat** %6
%59 = call i32 @reclose(%struct.reformat* %58)
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.reformat = type { i32 }
@.str = [68 x i8] c"This program reads a PopRank file.\0A\0A\09Usage: ./readPopRank 1 subname\00"
@.str.1 = [8 x i8] c"PopRank\00"
@.str.2 = [7 x i8] c"reopen\00"
@.str.3 = [21 x i8] c"DocID: %u, rank: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call %struct.reformat* @reopen(i32 %10, i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 4)
%14 = icmp eq %struct.reformat* %13, null
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %7
%19 = tail call i32 @LotDocIDOfset(i32 %10)
br label %20
20: ; preds = %18, %30
%21 = phi i32 [ 0, %18 ], [ %32, %30 ]
%22 = phi i32 [ %19, %18 ], [ %31, %30 ]
%23 = tail call i64 @renget(%struct.reformat* %13, i32 %21)
%24 = inttoptr i64 %23 to i8*
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = zext i8 %25 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %28)
br label %30
30: ; preds = %27, %20
%31 = add i32 %22, 1
%32 = add nuw nsw i32 %21, 1
%33 = icmp eq i32 %32, 500000
br i1 %33, label %34, label %20
34: ; preds = %30
%35 = tail call i32 @reclose(%struct.reformat* %13)
ret i32 0
}