#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int R_OK;
int W_OK;
int X_OK;
int /*<<< orphan*/ cctools_fatal(char *, char const *, int);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ pfs_resolve_add_entry(char *, char *, int);
int pfs_resolve_parse_mode(char *);
int sscanf(char *, char *, char *, char *, char *);
int strerror(scalar_t__);
int /*<<< orphan*/ string_chomp(char *);
void pfs_resolve_file_config(const char *filename) {
  FILE *file;
  char line[1024];
  char prefix[1024];
  char redirect[1024];
  char options[1024];
  int fields;
  int linenum = 0;
  int mode;
  file = fopen(filename, "r");
  if (!file)
    cctools_fatal("couldn't open mountfile %s: %s\n", filename,
                  strerror(errno));
  while (1) {
    if (!fgets(line, sizeof(line), file)) {
      if (errno == EINTR) {
        continue;
      } else {
        break;
      }
    }
    linenum++;
    if (line[0] == '#')
      continue;
    string_chomp(line);
    if (!line[0])
      continue;
    fields = sscanf(line, "%s %s %s", prefix, redirect, options);
    if (fields == 0) {
      continue;
    } else if (fields < 2) {
      cctools_fatal("%s has an error on line %d\n", filename, linenum);
    } else if (fields == 2) {
      mode = pfs_resolve_parse_mode(redirect);
      if (mode < 0) {
        mode = R_OK | W_OK | X_OK;
        pfs_resolve_add_entry(prefix, redirect, mode);
      } else {
        pfs_resolve_add_entry(prefix, prefix, mode);
      }
    } else {
      mode = pfs_resolve_parse_mode(options);
      if (mode < 0) {
        cctools_fatal("%s has invalid options on line %d\n", filename, linenum);
      }
      pfs_resolve_add_entry(prefix, redirect, mode);
    }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<pfs_resolve_file_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1018(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f7 <pfs_resolve_file_config+0x67>
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x1028(%rbp),%rsi
mov    %eax,%edx
lea    0xe10(%rip),%rdi
call   1070 <cctools_fatal@plt>
jmp    11fc <pfs_resolve_file_config+0x6c>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    123e <pfs_resolve_file_config+0xae>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%rax
jne    1239 <pfs_resolve_file_config+0xa9>
jmp    11fc <pfs_resolve_file_config+0x6c>
jmp    13ce <pfs_resolve_file_config+0x23e>
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
jne    1262 <pfs_resolve_file_config+0xd2>
jmp    11fc <pfs_resolve_file_config+0x6c>
lea    -0x410(%rbp),%rdi
call   1050 <string_chomp@plt>
cmpb   $0x0,-0x410(%rbp)
jne    1280 <pfs_resolve_file_config+0xf0>
jmp    11fc <pfs_resolve_file_config+0x6c>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    -0xc10(%rbp),%rcx
lea    -0x1010(%rbp),%r8
lea    0xd7f(%rip),%rsi
call   1080 <sscanf@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jne    12c0 <pfs_resolve_file_config+0x130>
jmp    11fc <pfs_resolve_file_config+0x6c>
cmpl   $0x2,-0x1014(%rbp)
jge    12e8 <pfs_resolve_file_config+0x158>
mov    -0x8(%rbp),%rsi
mov    -0x1018(%rbp),%edx
lea    0xd4d(%rip),%rdi
call   1070 <cctools_fatal@plt>
jmp    13c4 <pfs_resolve_file_config+0x234>
cmpl   $0x2,-0x1014(%rbp)
jne    1371 <pfs_resolve_file_config+0x1e1>
lea    -0xc10(%rbp),%rdi
call   1090 <pfs_resolve_parse_mode@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
jge    1353 <pfs_resolve_file_config+0x1c3>
mov    0x2ca5(%rip),%rax
mov    (%rax),%eax
mov    0x2cc4(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb3(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x101c(%rbp)
lea    -0x810(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
mov    -0x101c(%rbp),%edx
call   1040 <pfs_resolve_add_entry@plt>
jmp    136c <pfs_resolve_file_config+0x1dc>
lea    -0x810(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x101c(%rbp),%edx
call   1040 <pfs_resolve_add_entry@plt>
jmp    13bf <pfs_resolve_file_config+0x22f>
lea    -0x1010(%rbp),%rdi
call   1090 <pfs_resolve_parse_mode@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
jge    13a6 <pfs_resolve_file_config+0x216>
mov    -0x8(%rbp),%rsi
mov    -0x1018(%rbp),%edx
lea    0xca6(%rip),%rdi
call   1070 <cctools_fatal@plt>
lea    -0x810(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
mov    -0x101c(%rbp),%edx
call   1040 <pfs_resolve_add_entry@plt>
jmp    13c4 <pfs_resolve_file_config+0x234>
jmp    13c9 <pfs_resolve_file_config+0x239>
jmp    11fc <pfs_resolve_file_config+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfs_resolve_file_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rdi,%r14
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d8 <pfs_resolve_file_config+0x48>
mov    0x2e11(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <cctools_fatal@plt>
xor    %r15d,%r15d
lea    0x810(%rsp),%rbp
mov    0x2de6(%rip),%r12
mov    0x2dd7(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
jne    1223 <pfs_resolve_file_config+0x93>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1200 <pfs_resolve_file_config+0x70>
jmp    131d <pfs_resolve_file_config+0x18d>
add    $0x1,%r15d
cmpb   $0x23,0x810(%rsp)
23
je     1200 <pfs_resolve_file_config+0x70>
mov    %rbp,%rdi
call   1050 <string_chomp@plt>
cmpb   $0x0,0x810(%rsp)
je     1200 <pfs_resolve_file_config+0x70>
mov    %rbp,%rdi
lea    0xdd5(%rip),%rsi
lea    0x410(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc10(%rsp),%r8
call   1080 <sscanf@plt>
test   %eax,%eax
je     1200 <pfs_resolve_file_config+0x70>
cmp    $0x1,%eax
jg     1287 <pfs_resolve_file_config+0xf7>
lea    0xdb4(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1070 <cctools_fatal@plt>
jmp    1200 <pfs_resolve_file_config+0x70>
cmp    $0x2,%eax
jne    12a7 <pfs_resolve_file_config+0x117>
lea    0x10(%rsp),%rdi
call   1090 <pfs_resolve_parse_mode@plt>
test   %eax,%eax
js     12eb <pfs_resolve_file_config+0x15b>
lea    0x410(%rsp),%rdi
mov    %rdi,%rsi
jmp    12df <pfs_resolve_file_config+0x14f>
lea    0xc10(%rsp),%rdi
call   1090 <pfs_resolve_parse_mode@plt>
test   %eax,%eax
jns    12d2 <pfs_resolve_file_config+0x142>
lea    0xd88(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %eax,0xc(%rsp)
call   1070 <cctools_fatal@plt>
mov    0xc(%rsp),%eax
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
call   1040 <pfs_resolve_add_entry@plt>
jmp    1200 <pfs_resolve_file_config+0x70>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
mov    0x2cc5(%rip),%rax
or     (%rax),%edx
mov    0x2cdc(%rip),%rax
or     (%rax),%edx
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <pfs_resolve_add_entry@plt>
jmp    1200 <pfs_resolve_file_config+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1018,%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 = [32 x i8] c"couldn't open mountfile %s: %s\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [9 x i8] c"%s %s %s\00"
@.str.3 = [28 x i8] c"%s has an error on line %d\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@.str.4 = [35 x i8] c"%s has invalid options on line %d\0A\00"
define void @pfs_resolve_file_config(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %9
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %20, label %15
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = load i64, i64* @errno
%18 = call i32 @strerror(i64 %17)
%19 = call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %1
br label %21
21: ; preds = %20, %30, %39, %46, %55, %103
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = load i32*, i32** %3
%24 = call i32 @fgets(i8* %22, i32 1024, i32* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
br label %21
31: ; preds = %26
br label %104
32: ; preds = %21
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 35
br i1 %38, label %39, label %40
39: ; preds = %32
br label %21
40: ; preds = %32
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = call i32 @string_chomp(i8* %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %40
br label %21
47: ; preds = %40
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%52 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %49, i8* %50, i8* %51)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %47
br label %21
56: ; preds = %47
%57 = load i32, i32* %8
%58 = icmp slt i32 %57, 2
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i8*, i8** %2
%61 = load i32, i32* %9
%62 = call i32 @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %60, i32 %61)
br label %102
63: ; preds = %56
%64 = load i32, i32* %8
%65 = icmp eq i32 %64, 2
br i1 %65, label %66, label %87
66: ; preds = %63
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%68 = call i32 @pfs_resolve_parse_mode(i8* %67)
store i32 %68, i32* %10
%69 = load i32, i32* %10
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %66
%72 = load i32, i32* @R_OK
%73 = load i32, i32* @W_OK
%74 = or i32 %72, %73
%75 = load i32, i32* @X_OK
%76 = or i32 %74, %75
store i32 %76, i32* %10
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%79 = load i32, i32* %10
%80 = call i32 @pfs_resolve_add_entry(i8* %77, i8* %78, i32 %79)
br label %86
81: ; preds = %66
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%84 = load i32, i32* %10
%85 = call i32 @pfs_resolve_add_entry(i8* %82, i8* %83, i32 %84)
br label %86
86: ; preds = %81, %71
br label %101
87: ; preds = %63
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%89 = call i32 @pfs_resolve_parse_mode(i8* %88)
store i32 %89, i32* %10
%90 = load i32, i32* %10
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %87
%93 = load i8*, i8** %2
%94 = load i32, i32* %9
%95 = call i32 @cctools_fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %93, i32 %94)
br label %96
96: ; preds = %92, %87
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%99 = load i32, i32* %10
%100 = call i32 @pfs_resolve_add_entry(i8* %97, i8* %98, i32 %99)
br label %101
101: ; preds = %96, %86
br label %102
102: ; preds = %101, %59
br label %103
103: ; preds = %102
br label %21
104: ; preds = %31
%105 = load i32*, i32** %3
%106 = call i32 @fclose(i32* %105)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"couldn't open mountfile %s: %s\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [9 x i8] c"%s %s %s\00"
@.str.3 = [28 x i8] c"%s has an error on line %d\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@.str.4 = [35 x i8] c"%s has invalid options on line %d\0A\00"
define void @pfs_resolve_file_config(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i64, i64* @errno
%14 = tail call i32 @strerror(i64 %13)
%15 = tail call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %14)
br label %16
16: ; preds = %12, %1
br label %17
17: ; preds = %62, %16
%18 = phi i32 [ 0, %16 ], [ %27, %62 ]
br label %19
19: ; preds = %17, %22
%20 = call i32 @fgets(i8* %6, i32 1024, i32* %10)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp eq i64 %23, %24
br i1 %25, label %19, label %63
26: ; preds = %19
%27 = add nuw nsw i32 %18, 1
%28 = load i8, i8* %6
%29 = icmp eq i8 %28, 35
br i1 %29, label %62, label %30
30: ; preds = %26
%31 = call i32 @string_chomp(i8* %6)
%32 = load i8, i8* %6
%33 = icmp eq i8 %32, 0
br i1 %33, label %62, label %34
34: ; preds = %30
%35 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8, i8* %9)
%36 = icmp eq i32 %35, 0
br i1 %36, label %62, label %37
37: ; preds = %34
%38 = icmp slt i32 %35, 2
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = call i32 @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %27)
br label %62
41: ; preds = %37
%42 = icmp eq i32 %35, 2
br i1 %42, label %43, label %55
43: ; preds = %41
%44 = call i32 @pfs_resolve_parse_mode(i8* %8)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* @R_OK
%48 = load i32, i32* @W_OK
%49 = or i32 %48, %47
%50 = load i32, i32* @X_OK
%51 = or i32 %49, %50
%52 = call i32 @pfs_resolve_add_entry(i8* %7, i8* %8, i32 %51)
br label %62
53: ; preds = %43
%54 = call i32 @pfs_resolve_add_entry(i8* %7, i8* %7, i32 %44)
br label %62
55: ; preds = %41
%56 = call i32 @pfs_resolve_parse_mode(i8* %9)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @cctools_fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %27)
br label %60
60: ; preds = %58, %55
%61 = call i32 @pfs_resolve_add_entry(i8* %7, i8* %8, i32 %56)
br label %62
62: ; preds = %60, %53, %46, %39, %26, %34, %30
br label %17
63: ; preds = %22
%64 = call i32 @fclose(i32* %10)
ret void
}