#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ errx(int, char *);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char readbuf[1];
  int j = 0;
  if (argc != 2) {
    errx(1, "Usage: hash filename");
  }
  fd = open(argv[1], O_RDONLY, 0664);
  if (fd < 0) {
    err(1, "%s", argv[1]);
  }
  for (;;) {
    if (read(fd, readbuf, 1) <= 0)
      break;
    j = ((j * 8) + (int)readbuf[0]) % 104729;
  }
  close(fd);
  printf("Hash : %d\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
mov    $0x1,%edi
lea    0xe6d(%rip),%rsi
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    $0x1b4,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d9 <main+0x79>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%edi
lea    0xe41(%rip),%rsi
call   1070 <err@plt>
jmp    11de <main+0x7e>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jg     11fe <main+0x9e>
jmp    121a <main+0xba>
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
movsbl -0x15(%rbp),%ecx
add    %ecx,%eax
mov    $0x19919,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
jmp    11de <main+0x7e>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%esi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1181 <main+0x21>
lea    0xe89(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    0x8(%rbx),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
mov    $0x1b4,%edx
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b3 <main+0x53>
mov    0x8(%rbx),%rdx
lea    0xe6c(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1060 <read@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    120e <main+0xae>
lea    0xf(%rsp),%r14
movsbl 0xf(%rsp),%eax
lea    (%rax,%rbx,8),%eax
movslq %eax,%rbx
imul   $0xffffffffa0324bcb,%rbx,%rax
shr    $0x20,%rax
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x10,%eax
add    %ecx,%eax
imul   $0x19919,%eax,%eax
sub    %eax,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11d0 <main+0x70>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xdfc(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: hash filename\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"Hash : %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17, i32 436)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %13
br label %27
27: ; preds = %33, %26
%28 = load i32, i32* %6
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%30 = call i64 @read(i32 %28, i8* %29, i32 1)
%31 = icmp sle i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %41
33: ; preds = %27
%34 = load i32, i32* %8
%35 = mul nsw i32 %34, 8
%36 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = add nsw i32 %35, %38
%40 = srem i32 %39, 104729
store i32 %40, i32* %8
br label %27
41: ; preds = %32
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %8
%45 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Usage: hash filename\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"Hash : %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11, i32 436)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** %9
%16 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %8
%18 = call i64 @read(i32 %12, i8* %4, i32 1)
%19 = icmp slt i64 %18, 1
br i1 %19, label %29, label %20
20: ; preds = %17, %20
%21 = phi i32 [ %26, %20 ], [ 0, %17 ]
%22 = shl nsw i32 %21, 3
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = add nsw i32 %22, %24
%26 = srem i32 %25, 104729
%27 = call i64 @read(i32 %12, i8* %4, i32 1)
%28 = icmp slt i64 %27, 1
br i1 %28, label %29, label %20
29: ; preds = %20, %17
%30 = phi i32 [ 0, %17 ], [ %26, %20 ]
%31 = tail call i32 @close(i32 %12)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret i32 0
}