#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
unsigned long crc32(unsigned long const, unsigned char *, int /*<<< orphan*/);
unsigned long *malloc(int);
int open(char const *, int /*<<< orphan*/);
size_t read(int, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
unsigned long *list_pkgs(const char *path, const unsigned long initcrc,
                         char *buf, int *out) {
  unsigned long *pkgs;
  ssize_t len;
  int fd;
  char *curr, *next;
  pkgs = malloc(sizeof(unsigned long) * (60000));
  *out = 0;
  fd = open(path, O_RDONLY);
  len = read(fd, buf, (1024 * 1024));
  close(fd);
  buf[len] = '\0';
  for (curr = buf; curr != NULL; ++*out) {
    next = strchr(curr + 1, ' ');
    if (next != NULL)
      next[0] = '\0';
    ++curr;
    pkgs[*out] = crc32(initcrc, (unsigned char *)curr, strlen(curr));
    curr = next;
  }
  return pkgs;
}


x86 assembly (clang, -O0):
<list_pkgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x75300,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x100000,%edx
call   1070 <read@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1277 <list_pkgs+0x107>
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1219 <list_pkgs+0xa9>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11e6 <list_pkgs+0x76>
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_pkgs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
mov    $0x75300,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
movl   $0x0,(%r12)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100000,%edx
call   1070 <read@plt>
mov    %rax,%r13
mov    %ebp,%edi
call   1060 <close@plt>
movb   $0x0,(%rbx,%r13,1)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1235 <list_pkgs+0xc5>
mov    %rax,%r13
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,0x0(%r13)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
movslq (%r12),%rcx
mov    %rax,(%r14,%rcx,8)
lea    0x1(%rcx),%eax
mov    %eax,(%r12)
mov    %r13,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11f0 <list_pkgs+0x80>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
movslq (%r12),%rcx
mov    %rax,(%r14,%rcx,8)
lea    0x1(%rcx),%eax
mov    %eax,(%r12)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i64* @list_pkgs(i8* %0, i64 %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%14 = call i64* @malloc(i32 480000)
store i64* %14, i64** %9
%15 = load i32*, i32** %8
store i32 0, i32* %15
%16 = load i8*, i8** %5
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = load i8*, i8** %7
%21 = call i64 @read(i32 %19, i8* %20, i32 1048576)
store i64 %21, i64* %10
%22 = load i32, i32* %11
%23 = call i32 @close(i32 %22)
%24 = load i8*, i8** %7
%25 = load i64, i64* %10
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %7
store i8* %27, i8** %12
br label %28
28: ; preds = %54, %4
%29 = load i8*, i8** %12
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %58
31: ; preds = %28
%32 = load i8*, i8** %12
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i8* @strchr(i8* %33, i8 signext 32)
store i8* %34, i8** %13
%35 = load i8*, i8** %13
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i8*, i8** %13
%39 = getelementptr inbounds i8, i8* %38, i64 0
store i8 0, i8* %39
br label %40
40: ; preds = %37, %31
%41 = load i8*, i8** %12
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %12
%43 = load i64, i64* %6
%44 = load i8*, i8** %12
%45 = load i8*, i8** %12
%46 = call i32 @strlen(i8* %45)
%47 = call i64 @crc32(i64 %43, i8* %44, i32 %46)
%48 = load i64*, i64** %9
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i64, i64* %48, i64 %51
store i64 %47, i64* %52
%53 = load i8*, i8** %13
store i8* %53, i8** %12
br label %54
54: ; preds = %40
%55 = load i32*, i32** %8
%56 = load i32, i32* %55
%57 = add nsw i32 %56, 1
store i32 %57, i32* %55
br label %28
58: ; preds = %28
%59 = load i64*, i64** %9
ret i64* %59
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define noalias i64* @list_pkgs(i8* nocapture %0, i64 %1, i8* %2, i32* nocapture %3) {
%5 = tail call i64* @malloc(i32 480000)
store i32 0, i32* %3
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = tail call i64 @read(i32 %7, i8* %2, i32 1048576)
%9 = tail call i32 @close(i32 %7)
%10 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %10
%11 = getelementptr inbounds i8, i8* %2, i64 1
%12 = tail call i8* @strchr(i8* %11, i8 signext 32)
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %4, %14
%15 = phi i8* [ %24, %14 ], [ %12, %4 ]
%16 = phi i8* [ %23, %14 ], [ %11, %4 ]
store i8 0, i8* %15
%17 = tail call i32 @strlen(i8* %16)
%18 = tail call i64 @crc32(i64 %1, i8* %16, i32 %17)
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %5, i64 %20
store i64 %18, i64* %21
%22 = add nsw i32 %19, 1
store i32 %22, i32* %3
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = tail call i8* @strchr(i8* %23, i8 signext 32)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %14
26: ; preds = %14, %4
%27 = phi i8* [ %11, %4 ], [ %23, %14 ]
%28 = tail call i32 @strlen(i8* %27)
%29 = tail call i64 @crc32(i64 %1, i8* %27, i32 %28)
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %5, i64 %31
store i64 %29, i64* %32
%33 = add nsw i32 %30, 1
store i32 %33, i32* %3
ret i64* %5
}