#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__ EOF;
int /*<<< orphan*/ add_sort_list(char *, int, int, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int read_sort_file(char *filename, int source, char *source_path[]) {
  FILE *fd;
  char sort_filename[16385];
  int priority;
  if ((fd = fopen(filename, "r")) == NULL) {
    perror("Could not open sort_list file...");
    return 0;
  }
  while (fscanf(fd, "%s %d", sort_filename, &priority) != EOF)
    if (priority >= -32768 && priority <= 32767)
      add_sort_list(sort_filename, priority, source, source_path);
    else
      do {
        fprintf(stderr,
                "Sort file %s, priority %d outside range of "
                "-32767:32768 - skipping...\n",
                sort_filename, priority);
      } while (0);
  fclose(fd);
  return 1;
}


x86 assembly (clang, -O0):
<read_sort_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ac <read_sort_file+0x4c>
lea    0xe67(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <read_sort_file+0xfe>
jmp    11b1 <read_sort_file+0x51>
mov    -0x28(%rbp),%rdi
lea    -0x4030(%rbp),%rdx
lea    0xe60(%rip),%rsi
lea    -0x4034(%rbp),%rcx
call   1040 <fscanf@plt>
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
je     124e <read_sort_file+0xee>
cmpl   $0xffff8000,-0x4034(%rbp)
80 ff ff
jl     121d <read_sort_file+0xbd>
cmpl   $0x7fff,-0x4034(%rbp)
jg     121d <read_sort_file+0xbd>
lea    -0x4030(%rbp),%rdi
mov    -0x4034(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1080 <add_sort_list@plt>
jmp    1249 <read_sort_file+0xe9>
jmp    1222 <read_sort_file+0xc2>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    -0x4030(%rbp),%rdx
mov    -0x4034(%rbp),%ecx
lea    0xdea(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1249 <read_sort_file+0xe9>
jmp    11b1 <read_sort_file+0x51>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sort_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4018,%rsp
mov    %rdx,0x8(%rsp)
mov    %esi,%r15d
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     123d <read_sort_file+0xdd>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e37(%rip),%r14
cmp    (%r14),%rax
jne    11d5 <read_sort_file+0x75>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbp
lea    0xe42(%rip),%r12
lea    0x4(%rsp),%r13
jmp    121e <read_sort_file+0xbe>
nopl   0x0(%rax,%rax,1)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
cmp    (%r14),%rax
je     11b6 <read_sort_file+0x56>
mov    0x4(%rsp),%ecx
movswl %cx,%eax
cmp    %ecx,%eax
jne    11f0 <read_sort_file+0x90>
mov    %rbp,%rdi
mov    %ecx,%esi
mov    %r15d,%edx
mov    0x8(%rsp),%rcx
call   1080 <add_sort_list@plt>
jmp    1208 <read_sort_file+0xa8>
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11c3 <read_sort_file+0x63>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [33 x i8] c"Could not open sort_list file...\00"
@.str.2 = [6 x i8] c"%s %d\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.3 = [71 x i8] c"Sort file %s, priority %d outside range of -32767:32768 - skipping...\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 i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %46
16: ; preds = %3
br label %17
17: ; preds = %42, %16
%18 = load i32*, i32** %8
%19 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%20 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32* %10)
%21 = load i64, i64* @EOF
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %43
23: ; preds = %17
%24 = load i32, i32* %10
%25 = icmp sge i32 %24, -32768
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %10
%28 = icmp sle i32 %27, 32767
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%31 = load i32, i32* %10
%32 = load i32, i32* %6
%33 = load i8**, i8*** %7
%34 = call i32 @add_sort_list(i8* %30, i32 %31, i32 %32, i8** %33)
br label %42
35: ; preds = %26, %23
br label %36
36: ; preds = %35
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%39 = load i32, i32* %10
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i8* %38, i32 %39)
br label %41
41: ; preds = %36
br label %42
42: ; preds = %41, %29
br label %17
43: ; preds = %17
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
store i32 1, i32* %4
br label %46
46: ; preds = %43, %14
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [33 x i8] c"Could not open sort_list file...\00"
@.str.2 = [6 x i8] c"%s %d\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.3 = [71 x i8] c"Sort file %s, priority %d outside range of -32767:32768 - skipping...\0A\00"
define i32 @read_sort_file(i8* nocapture %0, i32 %1, i8** %2) {
%4 = alloca [16385 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [16385 x i8], [16385 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32* %5)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %29, label %16
14: ; preds = %3
%15 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %31
16: ; preds = %10, %25
%17 = load i32, i32* %5
%18 = add i32 %17, 32768
%19 = icmp ult i32 %18, 65536
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @add_sort_list(i8* %6, i32 %17, i32 %1, i8** %2)
br label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %17)
br label %25
25: ; preds = %22, %20
%26 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32* %5)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %16
29: ; preds = %25, %10
%30 = call i32 @fclose(i32* %8)
br label %31
31: ; preds = %29, %14
%32 = phi i32 [ 0, %14 ], [ 1, %29 ]
ret i32 %32
}