#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
unsigned long crc32(unsigned long const, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
unsigned long *malloc(int);
int open(char const *, int /*<<< orphan*/);
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
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) * (200000));
  *out = 0;
  fd = open(path, O_RDONLY);
  len = read(fd, buf, (1536 * 1536));
  close(fd);
  if (len <= 0)
    return pkgs;
  buf[len] = '\0';
  for (curr = buf; curr != NULL; ++*out) {
    if (*out == (200000)) {
      fputs("Too many packages", stderr);
      exit(EXIT_FAILURE);
    }
    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,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x186a00,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x240000,%edx
call   1080 <read@plt>
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
cmpq   $0x0,-0x38(%rbp)
ja     120a <list_pkgs+0x7a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ea <list_pkgs+0x15a>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12e2 <list_pkgs+0x152>
mov    -0x28(%rbp),%rax
cmpl   $0x30d40,(%rax)
jne    125c <list_pkgs+0xcc>
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    0xdb7(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1284 <list_pkgs+0xf4>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    121e <list_pkgs+0x8e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%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,%r13
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x186a00,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
movl   $0x0,(%r12)
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x240000,%edx
call   1080 <read@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1070 <close@plt>
test   %rbx,%rbx
je     1254 <list_pkgs+0xc4>
movb   $0x0,0x0(%r13,%rbx,1)
mov    (%r12),%ecx
jmp    1229 <list_pkgs+0x99>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
movslq (%r12),%rdx
lea    0x1(%rdx),%ecx
mov    %rax,(%r15,%rdx,8)
mov    %ecx,(%r12)
test   %r13,%r13
je     1254 <list_pkgs+0xc4>
cmp    $0x30d40,%ecx
je     1266 <list_pkgs+0xd6>
mov    %r13,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r13
test   %rax,%rax
je     1200 <list_pkgs+0x70>
movb   $0x0,0x0(%r13)
jmp    1200 <list_pkgs+0x70>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
lea    0xd8a(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"Too many packages\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define i64* @list_pkgs(i8* %0, i64 %1, i8* %2, i32* %3) {
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i64*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%15 = call i64* @malloc(i32 1600000)
store i64* %15, i64** %10
%16 = load i32*, i32** %9
store i32 0, i32* %16
%17 = load i8*, i8** %6
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = load i8*, i8** %8
%22 = call i64 @read(i32 %20, i8* %21, i32 2359296)
store i64 %22, i64* %11
%23 = load i32, i32* %12
%24 = call i32 @close(i32 %23)
%25 = load i64, i64* %11
%26 = icmp ule i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %4
%28 = load i64*, i64** %10
store i64* %28, i64** %5
br label %75
29: ; preds = %4
%30 = load i8*, i8** %8
%31 = load i64, i64* %11
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %8
store i8* %33, i8** %13
br label %34
34: ; preds = %69, %29
%35 = load i8*, i8** %13
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %73
37: ; preds = %34
%38 = load i32*, i32** %9
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, 200000
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = load i8*, i8** %13
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = call i8* @strchr(i8* %48, i8 signext 32)
store i8* %49, i8** %14
%50 = load i8*, i8** %14
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = load i8*, i8** %14
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 0, i8* %54
br label %55
55: ; preds = %52, %46
%56 = load i8*, i8** %13
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %13
%58 = load i64, i64* %7
%59 = load i8*, i8** %13
%60 = load i8*, i8** %13
%61 = call i32 @strlen(i8* %60)
%62 = call i64 @crc32(i64 %58, i8* %59, i32 %61)
%63 = load i64*, i64** %10
%64 = load i32*, i32** %9
%65 = load i32, i32* %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i64, i64* %63, i64 %66
store i64 %62, i64* %67
%68 = load i8*, i8** %14
store i8* %68, i8** %13
br label %69
69: ; preds = %55
%70 = load i32*, i32** %9
%71 = load i32, i32* %70
%72 = add nsw i32 %71, 1
store i32 %72, i32* %70
br label %34
73: ; preds = %34
%74 = load i64*, i64** %10
store i64* %74, i64** %5
br label %75
75: ; preds = %73, %27
%76 = load i64*, i64** %5
ret i64* %76
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [18 x i8] c"Too many packages\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i64* @list_pkgs(i8* nocapture %0, i64 %1, i8* %2, i32* nocapture %3) {
%5 = tail call i64* @malloc(i32 1600000)
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 2359296)
%9 = tail call i32 @close(i32 %7)
%10 = icmp eq i64 %8, 0
br i1 %10, label %35, label %11
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %12
%13 = load i32, i32* %3
br label %14
14: ; preds = %11, %28
%15 = phi i32 [ %34, %28 ], [ %13, %11 ]
%16 = phi i8* [ %25, %28 ], [ %2, %11 ]
%17 = icmp eq i32 %15, 200000
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds i8, i8* %16, i64 1
%25 = tail call i8* @strchr(i8* %24, i8 signext 32)
%26 = icmp eq i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %23
store i8 0, i8* %25
br label %28
28: ; preds = %27, %23
%29 = tail call i32 @strlen(i8* %24)
%30 = tail call i64 @crc32(i64 %1, i8* %24, i32 %29)
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i64, i64* %5, i64 %32
store i64 %30, i64* %33
%34 = add nsw i32 %31, 1
store i32 %34, i32* %3
br i1 %26, label %35, label %14
35: ; preds = %28, %4
ret i64* %5
}