#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ barf_perror(char *, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ init_hash_indexes();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, long long);
scalar_t__ stream_search(int);
int main(int argc, char *argv[]) {
  unsigned int i;
  init_hash_indexes();
  for (i = 1; i < argc; i++) {
    off_t len;
    int fd = open(argv[i], O_RDONLY);
    if (fd < 0)
      barf_perror("Opening %s", argv[i]);
    len = stream_search(fd);
    close(fd);
    printf("Length of %s: %llu\n", argv[i], (long long)len);
  }
  return 0;
}


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)
mov    $0x0,%al
call   1060 <init_hash_indexes@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    120a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11cd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
lea    0xe38(%rip),%rdi
call   1050 <barf_perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <stream_search@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <main+0x24>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <init_hash_indexes@plt>
cmp    $0x2,%ebp
jb     11e3 <main+0x83>
mov    %ebp,%r13d
mov    $0x1,%r14d
lea    0xe7f(%rip),%r15
jmp    11b9 <main+0x59>
xchg   %ax,%ax
mov    %ebp,%edi
call   1080 <stream_search@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r12,%r14,8),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1030 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     11e3 <main+0x83>
mov    (%r12,%r14,8),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1190 <main+0x30>
mov    (%r12,%r14,8),%rsi
lea    0xe24(%rip),%rdi
call   1050 <barf_perror@plt>
jmp    1190 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [11 x i8] c"Opening %s\00"
@.str.1 = [20 x i8] c"Length of %s: %llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @init_hash_indexes()
store i32 1, i32* %6
br label %10
10: ; preds = %43, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = load i32, i32* %6
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @barf_perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %24, %14
%32 = load i32, i32* %8
%33 = call i64 @stream_search(i32 %32)
store i64 %33, i64* %7
%34 = load i32, i32* %8
%35 = call i32 @close(i32 %34)
%36 = load i8**, i8*** %5
%37 = load i32, i32* %6
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = load i64, i64* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %40, i64 %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %6
%45 = add i32 %44, 1
store i32 %45, i32* %6
br label %10
46: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [11 x i8] c"Opening %s\00"
@.str.1 = [20 x i8] c"Length of %s: %llu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @init_hash_indexes()
%4 = icmp ugt i32 %0, 1
br i1 %4, label %5, label %24
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %17
%8 = phi i64 [ 1, %5 ], [ %22, %17 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i8*, i8** %9
%16 = tail call i32 @barf_perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %7
%18 = tail call i64 @stream_search(i32 %12)
%19 = tail call i32 @close(i32 %12)
%20 = load i8*, i8** %9
%21 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %20, i64 %18)
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, %6
br i1 %23, label %24, label %7
24: ; preds = %17, %2
ret i32 0
}