#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 */
scalar_t__ ERANGE;
int add_sort_list(char *, int, int, char **);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ progressbar_error(char *, char *, ...);
int sscanf(char *, char *, int *, int *);
char *strerror(scalar_t__);
int strlen(char *);
int read_sort_file(char *filename, int source, char *source_path[]) {
  FILE *fd;
  char line_buffer[16384 + 1];
  char sort_filename[16384 + 1];
  char *line, *name;
  int n, priority, res;
  if ((fd = fopen(filename, "r")) == NULL) {
    do {
      progressbar_error("Failed to open sort file \"%s\" because %s\n",
                        filename, strerror(errno));
    } while (0);
    return 0;
  }
  while (fgets(line = line_buffer, 16384 + 1, fd) != NULL) {
    int len = strlen(line);
    if (len == 16384 && line[len - 1] != '\n') {
      do {
        progressbar_error("Line too long when reading "
                          "sort file \"%s\", larger than %d "
                          "bytes\n",
                          filename, 16384);
      } while (0);
      goto failed;
    }
    if (len && line[len - 1] == '\n')
      line[len - 1] = '\0';
    while (isspace(*line))
      line++;
    if (*line == '#')
      continue;
    for (name = sort_filename; !isspace(*line) && *line != '\0';) {
      if (*line == '\\') {
        line++;
        if (*line == '\0')
          break;
      }
      *name++ = *line++;
    }
    *name = '\0';
    if (sort_filename[0] == '\0')
      continue;
    errno = 0;
    res = sscanf(line, "%d%n", &priority, &n);
    if ((res < 1 || errno) && errno != ERANGE) {
      if (errno == 0)
        do {
          progressbar_error("Sort file \"%s\", can't find priority "
                            "in entry \"%s\", EOL or match "
                            "failure\n",
                            filename, line_buffer);
        } while (0);
      else
        do {
          progressbar_error("Sscanf failed reading sort file \"%s\" "
                            "because %s\n",
                            filename, strerror(errno));
        } while (0);
      goto failed;
    } else if ((errno == ERANGE) || (priority < -32768 || priority > 32767)) {
      do {
        progressbar_error("Sort file \"%s\", entry \"%s\" has priority "
                          "outside range of -32767:32768.\n",
                          filename, line_buffer);
      } while (0);
      goto failed;
    }
    line += n;
    while (isspace(*line))
      line++;
    if (*line != '\0') {
      do {
        progressbar_error("Sort file \"%s\", trailing characters after "
                          "priority in entry \"%s\"\n",
                          filename, line_buffer);
      } while (0);
      goto failed;
    }
    res = add_sort_list(sort_filename, priority, source, source_path);
    if (res == 0)
      goto failed;
  }
  if (ferror(fd)) {
    do {
      progressbar_error("Reading sort file \"%s\" failed because %s\n",
                        filename, strerror(errno));
    } while (0);
    goto failed;
  }
  fclose(fd);
  return 1;
failed:
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<read_sort_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8080,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1217 <read_sort_file+0x77>
jmp    11d9 <read_sort_file+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8068(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x8068(%rbp),%rsi
mov    %rax,%rdx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1693 <read_sort_file+0x4f3>
jmp    121c <read_sort_file+0x7c>
lea    -0x4030(%rbp),%rdi
mov    %rdi,-0x8048(%rbp)
mov    -0x28(%rbp),%rdx
mov    $0x4001,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     161f <read_sort_file+0x47f>
mov    -0x8048(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x8060(%rbp)
cmpl   $0x4000,-0x8060(%rbp)
jne    12a5 <read_sort_file+0x105>
mov    -0x8048(%rbp),%rax
mov    -0x8060(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12a5 <read_sort_file+0x105>
jmp    1289 <read_sort_file+0xe9>
mov    -0x10(%rbp),%rsi
lea    0xd98(%rip),%rdi
mov    $0x4000,%edx
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1683 <read_sort_file+0x4e3>
cmpl   $0x0,-0x8060(%rbp)
je     12e9 <read_sort_file+0x149>
mov    -0x8048(%rbp),%rax
mov    -0x8060(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12e9 <read_sort_file+0x149>
mov    -0x8048(%rbp),%rax
mov    -0x8060(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12ee <read_sort_file+0x14e>
mov    -0x8048(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     131e <read_sort_file+0x17e>
mov    -0x8048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8048(%rbp)
jmp    12ee <read_sort_file+0x14e>
mov    -0x8048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1336 <read_sort_file+0x196>
jmp    121c <read_sort_file+0x7c>
lea    -0x8040(%rbp),%rax
mov    %rax,-0x8050(%rbp)
mov    -0x8048(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x8069(%rbp)
jne    137e <read_sort_file+0x1de>
mov    -0x8048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x8069(%rbp)
mov    -0x8069(%rbp),%al
test   $0x1,%al
jne    1391 <read_sort_file+0x1f1>
jmp    1406 <read_sort_file+0x266>
mov    -0x8048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    13d3 <read_sort_file+0x233>
mov    -0x8048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8048(%rbp)
mov    -0x8048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    13ce <read_sort_file+0x22e>
jmp    1406 <read_sort_file+0x266>
jmp    13d3 <read_sort_file+0x233>
mov    -0x8048(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8048(%rbp)
mov    (%rax),%cl
mov    -0x8050(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8050(%rbp)
mov    %cl,(%rax)
jmp    1344 <read_sort_file+0x1a4>
mov    -0x8050(%rbp),%rax
movb   $0x0,(%rax)
movsbl -0x8040(%rbp),%eax
cmp    $0x0,%eax
jne    1425 <read_sort_file+0x285>
jmp    121c <read_sort_file+0x7c>
mov    0x2bac(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8048(%rbp),%rdi
lea    0xc2c(%rip),%rsi
lea    -0x8058(%rbp),%rdx
lea    -0x8054(%rbp),%rcx
call   1080 <sscanf@plt>
mov    %eax,-0x805c(%rbp)
cmpl   $0x1,-0x805c(%rbp)
jl     1478 <read_sort_file+0x2d8>
mov    0x2b6a(%rip),%rax
cmpq   $0x0,(%rax)
je     1507 <read_sort_file+0x367>
mov    0x2b59(%rip),%rax
mov    (%rax),%rax
mov    0x2b5f(%rip),%rcx
cmp    (%rcx),%rax
je     1507 <read_sort_file+0x367>
mov    0x2b3f(%rip),%rax
cmpq   $0x0,(%rax)
jne    14c6 <read_sort_file+0x326>
jmp    14a8 <read_sort_file+0x308>
mov    -0x10(%rbp),%rsi
lea    -0x4030(%rbp),%rdx
lea    0xbb8(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1502 <read_sort_file+0x362>
jmp    14cb <read_sort_file+0x32b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8078(%rbp)
mov    0x2afb(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x8078(%rbp),%rsi
mov    %rax,%rdx
lea    0xbc5(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1502 <read_sort_file+0x362>
jmp    1683 <read_sort_file+0x4e3>
mov    0x2aca(%rip),%rax
mov    (%rax),%rax
mov    0x2ad0(%rip),%rcx
cmp    (%rcx),%rax
je     1541 <read_sort_file+0x3a1>
cmpl   $0xffff8000,-0x8058(%rbp)
80 ff ff
jl     1541 <read_sort_file+0x3a1>
cmpl   $0x7fff,-0x8058(%rbp)
jle    1564 <read_sort_file+0x3c4>
jmp    1546 <read_sort_file+0x3a6>
mov    -0x10(%rbp),%rsi
lea    -0x4030(%rbp),%rdx
lea    0xb94(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1683 <read_sort_file+0x4e3>
jmp    1569 <read_sort_file+0x3c9>
mov    -0x8054(%rbp),%ecx
mov    -0x8048(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8048(%rbp)
mov    -0x8048(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     15b3 <read_sort_file+0x413>
mov    -0x8048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8048(%rbp)
jmp    1583 <read_sort_file+0x3e3>
mov    -0x8048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     15e9 <read_sort_file+0x449>
jmp    15cb <read_sort_file+0x42b>
mov    -0x10(%rbp),%rsi
lea    -0x4030(%rbp),%rdx
lea    0xb57(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1683 <read_sort_file+0x4e3>
lea    -0x8040(%rbp),%rdi
mov    -0x8058(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   10a0 <add_sort_list@plt>
mov    %eax,-0x805c(%rbp)
cmpl   $0x0,-0x805c(%rbp)
jne    161a <read_sort_file+0x47a>
jmp    1683 <read_sort_file+0x4e3>
jmp    121c <read_sort_file+0x7c>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     166e <read_sort_file+0x4ce>
jmp    1637 <read_sort_file+0x497>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8080(%rbp)
mov    0x298f(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x8080(%rbp),%rsi
mov    %rax,%rdx
lea    0xb14(%rip),%rdi
mov    $0x0,%al
call   10b0 <progressbar_error@plt>
jmp    1683 <read_sort_file+0x4e3>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1693 <read_sort_file+0x4f3>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sort_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8038,%rsp
mov    %rdx,0x18(%rsp)
mov    %esi,0x10(%rsp)
mov    %rdi,%rbp
lea    0xe3c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1385 <read_sort_file+0x1e5>
mov    %rax,%r14
mov    %rbp,(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4001,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     13af <read_sort_file+0x20f>
lea    0x1f(%rsp),%r15
jmp    1219 <read_sort_file+0x79>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x4001,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     13af <read_sort_file+0x20f>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    $0x4000,%eax
jne    1236 <read_sort_file+0x96>
cmpb   $0xa,0x401f(%rsp)
0a
jne    13ea <read_sort_file+0x24a>
test   %eax,%eax
je     1248 <read_sort_file+0xa8>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1248 <read_sort_file+0xa8>
movb   $0x0,0x1f(%rsp,%rax,1)
mov    %r15,%r13
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%r13),%edi
add    $0x1,%r13
call   1060 <isspace@plt>
test   %rax,%rax
jne    1250 <read_sort_file+0xb0>
mov    0x0(%r13),%al
cmp    $0x23,%al
je     1200 <read_sort_file+0x60>
movsbl %al,%edi
call   1060 <isspace@plt>
lea    0x4030(%rsp),%r12
test   %rax,%rax
jne    12b1 <read_sort_file+0x111>
movzbl 0x0(%r13),%eax
cmp    $0x5c,%al
jne    1292 <read_sort_file+0xf2>
movzbl 0x1(%r13),%eax
add    $0x1,%r13
test   %al,%al
je     12b1 <read_sort_file+0x111>
mov    %al,(%r12)
add    $0x1,%r12
movsbl 0x1(%r13),%edi
add    $0x1,%r13
call   1060 <isspace@plt>
test   %rax,%rax
je     1280 <read_sort_file+0xe0>
movb   $0x0,(%r12)
cmpb   $0x0,0x4030(%rsp)
je     1200 <read_sort_file+0x60>
mov    0x2d0d(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r13,%rdi
lea    0xd91(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%rcx
call   1080 <sscanf@plt>
test   %eax,%eax
setg   %cl
mov    (%rbx),%rdi
test   %rdi,%rdi
sete   %dl
mov    0x2ce8(%rip),%rax
mov    (%rax),%rax
test   %dl,%cl
jne    1310 <read_sort_file+0x170>
cmp    %rax,%rdi
jne    1403 <read_sort_file+0x263>
cmp    %rax,%rdi
je     1416 <read_sort_file+0x276>
mov    0xc(%rsp),%eax
cmp    $0xffff8000,%eax
jl     1416 <read_sort_file+0x276>
cmp    $0x8000,%eax
jge    1416 <read_sort_file+0x276>
movslq 0x14(%rsp),%rax
add    %rax,%r13
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13),%edi
call   1060 <isspace@plt>
add    $0x1,%r13
test   %rax,%rax
jne    1340 <read_sort_file+0x1a0>
cmpb   $0x0,-0x1(%r13)
jne    141f <read_sort_file+0x27f>
mov    0xc(%rsp),%esi
lea    0x4030(%rsp),%rdi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%rcx
call   10a0 <add_sort_list@plt>
test   %eax,%eax
jne    1200 <read_sort_file+0x60>
jmp    143f <read_sort_file+0x29f>
mov    0x2c4c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xc67(%rip),%rdi
xor    %ebx,%ebx
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <progressbar_error@plt>
jmp    1449 <read_sort_file+0x2a9>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     13db <read_sort_file+0x23b>
mov    0x2c15(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xda4(%rip),%rdi
mov    (%rsp),%rsi
mov    %rax,%rdx
jmp    1438 <read_sort_file+0x298>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebx
jmp    1449 <read_sort_file+0x2a9>
lea    0xc3b(%rip),%rdi
mov    (%rsp),%rsi
mov    $0x4000,%edx
xor    %eax,%eax
call   10b0 <progressbar_error@plt>
jmp    143f <read_sort_file+0x29f>
test   %rdi,%rdi
je     1428 <read_sort_file+0x288>
call   10c0 <strerror@plt>
lea    0xca7(%rip),%rdi
jmp    13d2 <read_sort_file+0x232>
lea    0xccf(%rip),%rdi
jmp    142f <read_sort_file+0x28f>
lea    0xd0e(%rip),%rdi
jmp    142f <read_sort_file+0x28f>
lea    0xc43(%rip),%rdi
lea    0x20(%rsp),%rdx
mov    (%rsp),%rsi
xor    %eax,%eax
call   10b0 <progressbar_error@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [42 x i8] c"Failed to open sort file \22%s\22 because %s\0A\00"
@errno = global i64 0
@.str.2 = [65 x i8] c"Line too long when reading sort file \22%s\22, larger than %d bytes\0A\00"
@.str.3 = [5 x i8] c"%d%n\00"
@ERANGE = global i64 0
@.str.4 = [73 x i8] c"Sort file \22%s\22, can't find priority in entry \22%s\22, EOL or match failure\0A\00"
@.str.5 = [49 x i8] c"Sscanf failed reading sort file \22%s\22 because %s\0A\00"
@.str.6 = [72 x i8] c"Sort file \22%s\22, entry \22%s\22 has priority outside range of -32767:32768.\0A\00"
@.str.7 = [66 x i8] c"Sort file \22%s\22, trailing characters after priority in entry \22%s\22\0A\00"
@.str.8 = [42 x i8] c"Reading sort file \22%s\22 failed because %s\0A\00"
define i32 @read_sort_file(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca [16385 x i8]
%10 = alloca [16385 x i8]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %8
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %27
20: ; preds = %3
br label %21
21: ; preds = %20
%22 = load i8*, i8** %5
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
br label %26
26: ; preds = %21
store i32 0, i32* %4
br label %223
27: ; preds = %3
br label %28
28: ; preds = %205, %125, %84, %27
%29 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
store i8* %29, i8** %11
%30 = load i32*, i32** %8
%31 = call i32* @fgets(i8* %29, i32 16385, i32* %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %206
33: ; preds = %28
%34 = load i8*, i8** %11
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %16
%36 = load i32, i32* %16
%37 = icmp eq i32 %36, 16384
br i1 %37, label %38, label %52
38: ; preds = %33
%39 = load i8*, i8** %11
%40 = load i32, i32* %16
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %52
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i8*, i8** %5
%50 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %49, i32 16384)
br label %51
51: ; preds = %48
br label %220
52: ; preds = %38, %33
%53 = load i32, i32* %16
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %70
55: ; preds = %52
%56 = load i8*, i8** %11
%57 = load i32, i32* %16
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 10
br i1 %63, label %64, label %70
64: ; preds = %55
%65 = load i8*, i8** %11
%66 = load i32, i32* %16
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %64, %55, %52
br label %71
71: ; preds = %76, %70
%72 = load i8*, i8** %11
%73 = load i8, i8* %72
%74 = call i64 @isspace(i8 signext %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i8*, i8** %11
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %11
br label %71
79: ; preds = %71
%80 = load i8*, i8** %11
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 35
br i1 %83, label %84, label %85
84: ; preds = %79
br label %28
85: ; preds = %79
%86 = getelementptr inbounds [16385 x i8], [16385 x i8]* %10, i64 0, i64 0
store i8* %86, i8** %12
br label %87
87: ; preds = %113, %85
%88 = load i8*, i8** %11
%89 = load i8, i8* %88
%90 = call i64 @isspace(i8 signext %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = load i8*, i8** %11
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp ne i32 %95, 0
br label %97
97: ; preds = %92, %87
%98 = phi i1 [ false, %87 ], [ %96, %92 ]
br i1 %98, label %99, label %119
99: ; preds = %97
%100 = load i8*, i8** %11
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp eq i32 %102, 92
br i1 %103, label %104, label %113
104: ; preds = %99
%105 = load i8*, i8** %11
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %11
%107 = load i8*, i8** %11
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %104
br label %119
112: ; preds = %104
br label %113
113: ; preds = %112, %99
%114 = load i8*, i8** %11
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %11
%116 = load i8, i8* %114
%117 = load i8*, i8** %12
%118 = getelementptr inbounds i8, i8* %117, i32 1
store i8* %118, i8** %12
store i8 %116, i8* %117
br label %87
119: ; preds = %111, %97
%120 = load i8*, i8** %12
store i8 0, i8* %120
%121 = getelementptr inbounds [16385 x i8], [16385 x i8]* %10, i64 0, i64 0
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %126
125: ; preds = %119
br label %28
126: ; preds = %119
store i64 0, i64* @errno
%127 = load i8*, i8** %11
%128 = call i32 @sscanf(i8* %127, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %14, i32* %13)
store i32 %128, i32* %15
%129 = load i32, i32* %15
%130 = icmp slt i32 %129, 1
br i1 %130, label %134, label %131
131: ; preds = %126
%132 = load i64, i64* @errno
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %155
134: ; preds = %131, %126
%135 = load i64, i64* @errno
%136 = load i64, i64* @ERANGE
%137 = icmp ne i64 %135, %136
br i1 %137, label %138, label %155
138: ; preds = %134
%139 = load i64, i64* @errno
%140 = icmp eq i64 %139, 0
br i1 %140, label %141, label %147
141: ; preds = %138
br label %142
142: ; preds = %141
%143 = load i8*, i8** %5
%144 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%145 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), i8* %143, i8* %144)
br label %146
146: ; preds = %142
br label %154
147: ; preds = %138
br label %148
148: ; preds = %147
%149 = load i8*, i8** %5
%150 = load i64, i64* @errno
%151 = call i8* @strerror(i64 %150)
%152 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %149, i8* %151)
br label %153
153: ; preds = %148
br label %154
154: ; preds = %153, %146
br label %220
155: ; preds = %134, %131
%156 = load i64, i64* @errno
%157 = load i64, i64* @ERANGE
%158 = icmp eq i64 %156, %157
br i1 %158, label %165, label %159
159: ; preds = %155
%160 = load i32, i32* %14
%161 = icmp slt i32 %160, -32768
br i1 %161, label %165, label %162
162: ; preds = %159
%163 = load i32, i32* %14
%164 = icmp sgt i32 %163, 32767
br i1 %164, label %165, label %171
165: ; preds = %162, %159, %155
br label %166
166: ; preds = %165
%167 = load i8*, i8** %5
%168 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%169 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i8* %167, i8* %168)
br label %170
170: ; preds = %166
br label %220
171: ; preds = %162
br label %172
172: ; preds = %171
%173 = load i32, i32* %13
%174 = load i8*, i8** %11
%175 = sext i32 %173 to i64
%176 = getelementptr inbounds i8, i8* %174, i64 %175
store i8* %176, i8** %11
br label %177
177: ; preds = %182, %172
%178 = load i8*, i8** %11
%179 = load i8, i8* %178
%180 = call i64 @isspace(i8 signext %179)
%181 = icmp ne i64 %180, 0
br i1 %181, label %182, label %185
182: ; preds = %177
%183 = load i8*, i8** %11
%184 = getelementptr inbounds i8, i8* %183, i32 1
store i8* %184, i8** %11
br label %177
185: ; preds = %177
%186 = load i8*, i8** %11
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = icmp ne i32 %188, 0
br i1 %189, label %190, label %196
190: ; preds = %185
br label %191
191: ; preds = %190
%192 = load i8*, i8** %5
%193 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%194 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0), i8* %192, i8* %193)
br label %195
195: ; preds = %191
br label %220
196: ; preds = %185
%197 = getelementptr inbounds [16385 x i8], [16385 x i8]* %10, i64 0, i64 0
%198 = load i32, i32* %14
%199 = load i32, i32* %6
%200 = load i8**, i8*** %7
%201 = call i32 @add_sort_list(i8* %197, i32 %198, i32 %199, i8** %200)
store i32 %201, i32* %15
%202 = load i32, i32* %15
%203 = icmp eq i32 %202, 0
br i1 %203, label %204, label %205
204: ; preds = %196
br label %220
205: ; preds = %196
br label %28
206: ; preds = %28
%207 = load i32*, i32** %8
%208 = call i64 @ferror(i32* %207)
%209 = icmp ne i64 %208, 0
br i1 %209, label %210, label %217
210: ; preds = %206
br label %211
211: ; preds = %210
%212 = load i8*, i8** %5
%213 = load i64, i64* @errno
%214 = call i8* @strerror(i64 %213)
%215 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i8* %212, i8* %214)
br label %216
216: ; preds = %211
br label %220
217: ; preds = %206
%218 = load i32*, i32** %8
%219 = call i32 @fclose(i32* %218)
store i32 1, i32* %4
br label %223
220: ; preds = %216, %204, %195, %170, %154, %51
%221 = load i32*, i32** %8
%222 = call i32 @fclose(i32* %221)
store i32 0, i32* %4
br label %223
223: ; preds = %220, %217, %26
%224 = load i32, i32* %4
ret i32 %224
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [42 x i8] c"Failed to open sort file \22%s\22 because %s\0A\00"
@errno = global i64 0
@.str.2 = [65 x i8] c"Line too long when reading sort file \22%s\22, larger than %d bytes\0A\00"
@.str.3 = [5 x i8] c"%d%n\00"
@ERANGE = global i64 0
@.str.4 = [73 x i8] c"Sort file \22%s\22, can't find priority in entry \22%s\22, EOL or match failure\0A\00"
@.str.5 = [49 x i8] c"Sscanf failed reading sort file \22%s\22 because %s\0A\00"
@.str.6 = [72 x i8] c"Sort file \22%s\22, entry \22%s\22 has priority outside range of -32767:32768.\0A\00"
@.str.7 = [66 x i8] c"Sort file \22%s\22, trailing characters after priority in entry \22%s\22\0A\00"
@.str.8 = [42 x i8] c"Reading sort file \22%s\22 failed because %s\0A\00"
define i32 @read_sort_file(i8* %0, i32 %1, i8** %2) {
%4 = alloca [16385 x i8]
%5 = alloca [16385 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [16385 x i8], [16385 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [16385 x i8], [16385 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = call i32* @fgets(i8* %8, i32 16385, i32* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %119, label %17
17: ; preds = %14
%18 = getelementptr inbounds [16385 x i8], [16385 x i8]* %4, i64 0, i64 16383
br label %23
19: ; preds = %3
%20 = load i64, i64* @errno
%21 = tail call i8* @strerror(i64 %20)
%22 = tail call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %21)
br label %130
23: ; preds = %17, %116
%24 = call i32 @strlen(i8* %8)
%25 = icmp ne i32 %24, 16384
%26 = load i8, i8* %18
%27 = icmp eq i8 %26, 10
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 16384)
br label %128
31: ; preds = %23
%32 = icmp eq i32 %24, 0
br i1 %32, label %40, label %33
33: ; preds = %31
%34 = add nsw i32 %24, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [16385 x i8], [16385 x i8]* %4, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %33
store i8 0, i8* %36
br label %40
40: ; preds = %39, %33, %31
br label %41
41: ; preds = %40, %41
%42 = phi i8* [ %46, %41 ], [ %8, %40 ]
%43 = load i8, i8* %42
%44 = call i64 @isspace(i8 signext %43)
%45 = icmp eq i64 %44, 0
%46 = getelementptr inbounds i8, i8* %42, i64 1
br i1 %45, label %47, label %41
47: ; preds = %41
%48 = load i8, i8* %42
%49 = icmp eq i8 %48, 35
br i1 %49, label %116, label %50
50: ; preds = %47
%51 = call i64 @isspace(i8 signext %48)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %69
53: ; preds = %50, %61
%54 = phi i8* [ %65, %61 ], [ %9, %50 ]
%55 = phi i8* [ %64, %61 ], [ %42, %50 ]
%56 = load i8, i8* %55
switch i8 %56, label %61 [
i8 0, label %69
i8 92, label %57
]
57: ; preds = %53
%58 = getelementptr inbounds i8, i8* %55, i64 1
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
br i1 %60, label %69, label %61
61: ; preds = %53, %57
%62 = phi i8 [ %59, %57 ], [ %56, %53 ]
%63 = phi i8* [ %58, %57 ], [ %55, %53 ]
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = getelementptr inbounds i8, i8* %54, i64 1
store i8 %62, i8* %54
%66 = load i8, i8* %64
%67 = call i64 @isspace(i8 signext %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %53, label %69
69: ; preds = %57, %61, %53, %50
%70 = phi i8* [ %9, %50 ], [ %54, %53 ], [ %65, %61 ], [ %54, %57 ]
%71 = phi i8* [ %42, %50 ], [ %55, %53 ], [ %64, %61 ], [ %58, %57 ]
store i8 0, i8* %70
%72 = load i8, i8* %9
%73 = icmp eq i8 %72, 0
br i1 %73, label %116, label %74
74: ; preds = %69
store i64 0, i64* @errno
%75 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %7, i32* %6)
%76 = icmp sgt i32 %75, 0
%77 = load i64, i64* @errno
%78 = icmp eq i64 %77, 0
%79 = select i1 %76, i1 %78, i1 false
%80 = load i64, i64* @ERANGE
%81 = icmp eq i64 %77, %80
%82 = select i1 %79, i1 true, i1 %81
br i1 %82, label %89, label %83
83: ; preds = %74
br i1 %78, label %84, label %86
84: ; preds = %83
%85 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %8)
br label %128
86: ; preds = %83
%87 = call i8* @strerror(i64 %77)
%88 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %87)
br label %128
89: ; preds = %74
%90 = load i32, i32* %7
%91 = icmp slt i32 %90, -32768
%92 = select i1 %81, i1 true, i1 %91
%93 = icmp sgt i32 %90, 32767
%94 = select i1 %92, i1 true, i1 %93
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %8)
br label %128
97: ; preds = %89
%98 = load i32, i32* %6
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %71, i64 %99
br label %101
101: ; preds = %101, %97
%102 = phi i8* [ %100, %97 ], [ %106, %101 ]
%103 = load i8, i8* %102
%104 = call i64 @isspace(i8 signext %103)
%105 = icmp eq i64 %104, 0
%106 = getelementptr inbounds i8, i8* %102, i64 1
br i1 %105, label %107, label %101
107: ; preds = %101
%108 = load i8, i8* %102
%109 = icmp eq i8 %108, 0
br i1 %109, label %112, label %110
110: ; preds = %107
%111 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %8)
br label %128
112: ; preds = %107
%113 = load i32, i32* %7
%114 = call i32 @add_sort_list(i8* %9, i32 %113, i32 %1, i8** %2)
%115 = icmp eq i32 %114, 0
br i1 %115, label %128, label %116
116: ; preds = %112, %69, %47
%117 = call i32* @fgets(i8* %8, i32 16385, i32* %12)
%118 = icmp eq i32* %117, null
br i1 %118, label %119, label %23
119: ; preds = %116, %14
%120 = call i64 @ferror(i32* %12)
%121 = icmp eq i64 %120, 0
br i1 %121, label %126, label %122
122: ; preds = %119
%123 = load i64, i64* @errno
%124 = call i8* @strerror(i64 %123)
%125 = call i32 (i8*, i8*, ...) @progressbar_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* %124)
br label %128
126: ; preds = %119
%127 = call i32 @fclose(i32* %12)
br label %130
128: ; preds = %112, %84, %86, %110, %95, %29, %122
%129 = call i32 @fclose(i32* %12)
br label %130
130: ; preds = %128, %126, %19
%131 = phi i32 [ 0, %19 ], [ 0, %128 ], [ 1, %126 ]
ret i32 %131
}