#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 */
unsigned int HashValue(void *, unsigned int);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ stdout;
unsigned int getBuckets(void *queryCompleteRecord, unsigned int *temp) {
  unsigned int i;
  unsigned int qhash;
  unsigned int tempid;
  unsigned int itemCount;
  unsigned int sofar;
  unsigned int queryID;
  char fname[7];
  FILE *fp;
  queryID = *(unsigned int *)queryCompleteRecord;
  sofar = 0;
  for (i = 0; i < 32; i++) {
    qhash = HashValue(queryCompleteRecord, i);
    memset(fname, '\0', 4);
    sprintf(fname, "%u.hash", qhash & 7);
    fp = fopen(fname, "rb");
    if (fp == NULL) {
      perror("qhash file");
      exit(-1);
    }
    if (fseek(fp, sizeof(unsigned int) * 64 * (qhash / 8), SEEK_SET) < 0) {
      perror("fseek in fp");
    }
    itemCount = 0;
    while (itemCount < 64) {
      fread(&tempid, sizeof(unsigned int), 1, fp);
      if (tempid == 0)
        break;
      if (tempid == queryID)
        continue;
      temp[sofar++] = tempid;
      if (sofar >= 500) {
        fprintf(stdout, "Max look up reached\n");
        fclose(fp);
        return sofar - 1;
      }
      itemCount++;
    }
    fclose(fp);
  }
  return sofar == 0 ? 0 : (sofar - 1);
}


x86 assembly (clang, -O0):
<getBuckets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jae    132e <getBuckets+0x18e>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <HashValue@plt>
mov    %eax,-0x20(%rbp)
lea    -0x37(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x37(%rbp),%rdi
mov    -0x20(%rbp),%edx
and    $0x7,%edx
lea    0xdff(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x37(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    123b <getBuckets+0x9b>
lea    0xddf(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%eax
shr    $0x3,%eax
mov    %eax,%eax
shl    $0x8,%rax
mov    %eax,%esi
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
jge    1271 <getBuckets+0xd1>
lea    0xdaa(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x40,-0x28(%rbp)
jae    1317 <getBuckets+0x177>
mov    -0x40(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmpl   $0x0,-0x24(%rbp)
jne    12a8 <getBuckets+0x108>
jmp    1317 <getBuckets+0x177>
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    12b9 <getBuckets+0x119>
jmp    1278 <getBuckets+0xd8>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
cmpl   $0x1f4,-0x2c(%rbp)
jb     1309 <getBuckets+0x169>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1351 <getBuckets+0x1b1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1278 <getBuckets+0xd8>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c7 <getBuckets+0x27>
cmpl   $0x0,-0x2c(%rbp)
jne    1342 <getBuckets+0x1a2>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    134b <getBuckets+0x1ab>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBuckets>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,0x18(%rsp)
mov    (%rdi),%r15d
xor    %ebp,%ebp
lea    0xc(%rsp),%r12
xor    %eax,%eax
mov    %rax,(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rdi
mov    %ebp,%esi
call   1080 <HashValue@plt>
mov    %eax,%ebx
lea    0x21(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %ebx,%edx
and    $0x7,%edx
mov    %r14,%rdi
lea    0xdff(%rip),%rsi
call   10b0 <sprintf@plt>
mov    %r14,%rdi
lea    0xdf8(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ff <getBuckets+0x15f>
mov    %rax,%r13
and    $0xfffffff8,%ebx
shl    $0x5,%ebx
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %ebx,%esi
call   1070 <fseek@plt>
test   %rax,%rax
js     12aa <getBuckets+0x10a>
mov    (%rsp),%rsi
lea    0x40(%rsi),%ebx
cmp    %ebx,%esi
je     12b8 <getBuckets+0x118>
mov    %esi,%r14d
nopl   (%rax)
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1290 <getBuckets+0xf0>
cmp    %r15d,%eax
je     1250 <getBuckets+0xb0>
lea    0x1(%r14),%esi
mov    %r14d,%ecx
mov    0x10(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
cmp    $0x1f4,%esi
jb     1246 <getBuckets+0xa6>
jmp    12d0 <getBuckets+0x130>
nopl   0x0(%rax,%rax,1)
mov    %r14,(%rsp)
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebp
cmp    $0x20,%ebp
jne    11d0 <getBuckets+0x30>
jmp    12c0 <getBuckets+0x120>
lea    0xd65(%rip),%rdi
call   10a0 <perror@plt>
jmp    123f <getBuckets+0x9f>
mov    %ebx,%eax
mov    %rax,(%rsp)
jmp    1294 <getBuckets+0xf4>
xor    %eax,%eax
mov    (%rsp),%r14
sub    $0x1,%r14d
cmovb  %eax,%r14d
jmp    12ed <getBuckets+0x14d>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd05(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%u.hash\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"qhash file\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"fseek in fp\00"
@stdout = global i32 0
@.str.4 = [21 x i8] c"Max look up reached\0A\00"
define i32 @getBuckets(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [7 x i8]
%13 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
store i32 %16, i32* %11
store i32 0, i32* %10
store i32 0, i32* %6
br label %17
17: ; preds = %86, %2
%18 = load i32, i32* %6
%19 = icmp ult i32 %18, 32
br i1 %19, label %20, label %89
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = call i32 @HashValue(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i8 signext 0, i32 4)
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%27 = load i32, i32* %7
%28 = and i32 %27, 7
%29 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %13
%32 = load i32*, i32** %13
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %20
%38 = load i32*, i32** %13
%39 = load i32, i32* %7
%40 = udiv i32 %39, 8
%41 = zext i32 %40 to i64
%42 = mul i64 256, %41
%43 = trunc i64 %42 to i32
%44 = load i32, i32* @SEEK_SET
%45 = call i64 @fseek(i32* %38, i32 %43, i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %37
store i32 0, i32* %9
br label %50
50: ; preds = %80, %63, %49
%51 = load i32, i32* %9
%52 = icmp ult i32 %51, 64
br i1 %52, label %53, label %83
53: ; preds = %50
%54 = load i32*, i32** %13
%55 = call i32 @fread(i32* %8, i32 4, i32 1, i32* %54)
%56 = load i32, i32* %8
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
br label %83
59: ; preds = %53
%60 = load i32, i32* %8
%61 = load i32, i32* %11
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %64
63: ; preds = %59
br label %50
64: ; preds = %59
%65 = load i32, i32* %8
%66 = load i32*, i32** %5
%67 = load i32, i32* %10
%68 = add i32 %67, 1
store i32 %68, i32* %10
%69 = zext i32 %67 to i64
%70 = getelementptr inbounds i32, i32* %66, i64 %69
store i32 %65, i32* %70
%71 = load i32, i32* %10
%72 = icmp uge i32 %71, 500
br i1 %72, label %73, label %80
73: ; preds = %64
%74 = load i32, i32* @stdout
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32*, i32** %13
%77 = call i32 @fclose(i32* %76)
%78 = load i32, i32* %10
%79 = sub i32 %78, 1
store i32 %79, i32* %3
br label %98
80: ; preds = %64
%81 = load i32, i32* %9
%82 = add i32 %81, 1
store i32 %82, i32* %9
br label %50
83: ; preds = %58, %50
%84 = load i32*, i32** %13
%85 = call i32 @fclose(i32* %84)
br label %86
86: ; preds = %83
%87 = load i32, i32* %6
%88 = add i32 %87, 1
store i32 %88, i32* %6
br label %17
89: ; preds = %17
%90 = load i32, i32* %10
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %89
br label %96
93: ; preds = %89
%94 = load i32, i32* %10
%95 = sub i32 %94, 1
br label %96
96: ; preds = %93, %92
%97 = phi i32 [ 0, %92 ], [ %95, %93 ]
store i32 %97, i32* %3
br label %98
98: ; preds = %96, %73
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@.str = [8 x i8] c"%u.hash\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"qhash file\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"fseek in fp\00"
@stdout = global i32 0
@.str.4 = [21 x i8] c"Max look up reached\0A\00"
define i32 @getBuckets(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [7 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%7 = bitcast i8* %0 to i32*
%8 = load i32, i32* %7
br label %9
9: ; preds = %2, %49
%10 = phi i32 [ 0, %2 ], [ %52, %49 ]
%11 = phi i32 [ 0, %2 ], [ %50, %49 ]
%12 = call i32 @HashValue(i8* %0, i32 %10)
%13 = call i32 @memset(i8* %6, i8 signext 0, i32 4)
%14 = and i32 %12, 7
%15 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %9
%22 = shl i32 %12, 5
%23 = and i32 %22, -256
%24 = load i32, i32* @SEEK_SET
%25 = call i64 @fseek(i32* %16, i32 %23, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = add i32 %11, 64
br label %31
31: ; preds = %40, %29
%32 = phi i32 [ %41, %40 ], [ %11, %29 ]
%33 = icmp eq i32 %32, %30
br i1 %33, label %49, label %34
34: ; preds = %31, %38
%35 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %16)
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %34
%39 = icmp eq i32 %36, %8
br i1 %39, label %34, label %40
40: ; preds = %38
%41 = add i32 %32, 1
%42 = zext i32 %32 to i64
%43 = getelementptr inbounds i32, i32* %1, i64 %42
store i32 %36, i32* %43
%44 = icmp ugt i32 %41, 499
br i1 %44, label %45, label %31
45: ; preds = %40
%46 = load i32, i32* @stdout
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @fclose(i32* %16)
br label %58
49: ; preds = %31, %34
%50 = phi i32 [ %32, %34 ], [ %30, %31 ]
%51 = call i32 @fclose(i32* %16)
%52 = add nuw nsw i32 %10, 1
%53 = icmp eq i32 %52, 32
br i1 %53, label %54, label %9
54: ; preds = %49
%55 = icmp eq i32 %50, 0
%56 = add i32 %50, -1
%57 = select i1 %55, i32 0, i32 %56
br label %58
58: ; preds = %54, %45
%59 = phi i32 [ %32, %45 ], [ %57, %54 ]
ret i32 %59
}