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

/* Variables and functions */
scalar_t__ chunk_load(int /*<<< orphan*/ *, int);
int dispchar(char);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fs_load(int /*<<< orphan*/ *, char, char const *);
scalar_t__ fs_load_pre17(int /*<<< orphan*/ *);
scalar_t__ memcmp(char const *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int fs_loadall(const char *fname, const char section[4]) {
  FILE *fd;
  uint8_t hdr[8];
  uint8_t fver;
  fd = fopen(fname, "r");
  if (fd == NULL) {
    printf("can't open metadata file\n");
    return -1;
  }
  if (fread(hdr, 1, 8, fd) != 8) {
    printf("can't read metadata header\n");
    fclose(fd);
    return -1;
  }
  if (memcmp(section, "HEAD", 4) == 0 || section[0] == 0) {
    printf("# header: %c%c%c%c%c%c%c%c (%02X%02X%02X%02X%02X%02X%02X%02X)\n",
           dispchar(hdr[0]), dispchar(hdr[1]), dispchar(hdr[2]),
           dispchar(hdr[3]), dispchar(hdr[4]), dispchar(hdr[5]),
           dispchar(hdr[6]), dispchar(hdr[7]), hdr[0], hdr[1], hdr[2], hdr[3],
           hdr[4], hdr[5], hdr[6], hdr[7]);
  }
  if (memcmp(hdr, "MFSM NEW", 8) == 0) {
    printf("empty file\n");
  } else if (memcmp(hdr,
                    "MFS"
                    "M ",
                    5) == 0 &&
             hdr[5] >= '1' && hdr[5] <= '9' && hdr[6] == '.' && hdr[7] >= '0' &&
             hdr[7] <= '9') {
    fver = ((hdr[5] - '0') << 4) + (hdr[7] - '0');
    if (fver < 0x17) {
      if (section[0] != 0) {
        printf("old format detected - can't dump sections separatelly");
        fclose(fd);
        return -1;
      }
      if (fs_load_pre17(fd) < 0) {
        printf("error reading metadata (structure)\n");
        fclose(fd);
        return -1;
      }
      if (chunk_load(fd, 0x10) < 0) {
        printf("error reading metadata (chunks)\n");
        fclose(fd);
        return -1;
      }
    } else {
      if (fs_load(fd, fver, section) < 0) {
        fclose(fd);
        return -1;
      }
    }
  } else {
    printf("wrong metadata header (old version ?)\n");
    fclose(fd);
    return -1;
  }
  if (ferror(fd) != 0) {
    printf("error reading metadata\n");
    fclose(fd);
    return -1;
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<fs_loadall>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11f5 <fs_loadall+0x55>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
lea    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1050 <fread@plt>
cmp    $0x8,%eax
je     1238 <fs_loadall+0x98>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
mov    -0x40(%rbp),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x4,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     1267 <fs_loadall+0xc7>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    134e <fs_loadall+0x1ae>
movsbl -0x50(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x78(%rbp)
movsbl -0x4f(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x74(%rbp)
movsbl -0x4e(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x70(%rbp)
movsbl -0x4d(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x6c(%rbp)
movsbl -0x4c(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x68(%rbp)
movsbl -0x4b(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x64(%rbp)
movsbl -0x4a(%rbp),%edi
call   10a0 <dispchar@plt>
mov    %eax,-0x60(%rbp)
movsbl -0x49(%rbp),%edi
call   10a0 <dispchar@plt>
mov    -0x78(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x70(%rbp),%ecx
mov    -0x6c(%rbp),%r8d
mov    -0x68(%rbp),%r9d
mov    %eax,%edi
mov    -0x64(%rbp),%eax
mov    %edi,-0x5c(%rbp)
movsbl -0x50(%rbp),%r13d
movsbl -0x4f(%rbp),%r12d
movsbl -0x4e(%rbp),%r15d
movsbl -0x4d(%rbp),%r14d
movsbl -0x4c(%rbp),%ebx
movsbl -0x4b(%rbp),%r11d
movsbl -0x4a(%rbp),%r10d
movsbl -0x49(%rbp),%edi
mov    %edi,-0x58(%rbp)
lea    0xd30(%rip),%rdi
mov    %eax,(%rsp)
mov    -0x60(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    -0x5c(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    -0x58(%rbp),%eax
mov    %r13d,0x18(%rsp)
mov    %r12d,0x20(%rsp)
mov    %r15d,0x28(%rsp)
mov    %r14d,0x30(%rsp)
mov    %ebx,0x38(%rsp)
mov    %r11d,0x40(%rsp)
mov    %r10d,0x48(%rsp)
mov    %eax,0x50(%rsp)
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xd23(%rip),%rsi
mov    $0x8,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    1380 <fs_loadall+0x1e0>
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1510 <fs_loadall+0x370>
lea    -0x50(%rbp),%rdi
lea    0xd06(%rip),%rsi
mov    $0x5,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    14e8 <fs_loadall+0x348>
movsbl -0x4b(%rbp),%eax
cmp    $0x31,%eax
jl     14e8 <fs_loadall+0x348>
movsbl -0x4b(%rbp),%eax
cmp    $0x39,%eax
jg     14e8 <fs_loadall+0x348>
movsbl -0x4a(%rbp),%eax
cmp    $0x2e,%eax
jne    14e8 <fs_loadall+0x348>
movsbl -0x49(%rbp),%eax
cmp    $0x30,%eax
jl     14e8 <fs_loadall+0x348>
movsbl -0x49(%rbp),%eax
cmp    $0x39,%eax
jg     14e8 <fs_loadall+0x348>
movsbl -0x4b(%rbp),%eax
sub    $0x30,%eax
shl    $0x4,%eax
movsbl -0x49(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %al,-0x51(%rbp)
movsbl -0x51(%rbp),%eax
cmp    $0x17,%eax
jge    14ac <fs_loadall+0x30c>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1436 <fs_loadall+0x296>
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
mov    -0x48(%rbp),%rdi
call   1030 <fs_load_pre17@plt>
cmp    $0x0,%rax
jge    146c <fs_loadall+0x2cc>
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
mov    -0x48(%rbp),%rdi
mov    $0x10,%esi
call   10c0 <chunk_load@plt>
cmp    $0x0,%rax
jge    14a7 <fs_loadall+0x307>
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
jmp    14e3 <fs_loadall+0x343>
mov    -0x48(%rbp),%rdi
mov    -0x51(%rbp),%al
mov    -0x40(%rbp),%rdx
movsbl %al,%esi
call   1090 <fs_load@plt>
cmp    $0x0,%rax
jge    14de <fs_loadall+0x33e>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
jmp    14e3 <fs_loadall+0x343>
jmp    150b <fs_loadall+0x36b>
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
jmp    1510 <fs_loadall+0x370>
mov    -0x48(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1546 <fs_loadall+0x3a6>
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1556 <fs_loadall+0x3b6>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_loadall>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbp
lea    0xf65(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1384 <fs_loadall+0x1d4>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rax,%rcx
call   1060 <fread@plt>
cmp    $0x8,%eax
jne    1392 <fs_loadall+0x1e2>
lea    0xe00(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     121c <fs_loadall+0x6c>
cmpb   $0x0,0x0(%rbp)
jne    1308 <fs_loadall+0x158>
movsbl 0xc(%rsp),%edi
mov    %rdi,0x50(%rsp)
call   10b0 <dispchar@plt>
mov    %eax,0x24(%rsp)
movsbl 0xd(%rsp),%edi
mov    %rdi,0x48(%rsp)
call   10b0 <dispchar@plt>
mov    %eax,0x20(%rsp)
movsbl 0xe(%rsp),%edi
mov    %rdi,0x40(%rsp)
call   10b0 <dispchar@plt>
mov    %eax,0x1c(%rsp)
movsbl 0xf(%rsp),%edi
mov    %rdi,0x30(%rsp)
call   10b0 <dispchar@plt>
mov    %eax,0x18(%rsp)
movsbl 0x10(%rsp),%r15d
mov    %r15d,%edi
call   10b0 <dispchar@plt>
mov    %eax,0x14(%rsp)
movsbl 0x11(%rsp),%r12d
mov    %r12d,%edi
call   10b0 <dispchar@plt>
mov    %rax,0x38(%rsp)
movsbl 0x12(%rsp),%r14d
mov    %r14d,%edi
call   10b0 <dispchar@plt>
mov    %rax,0x28(%rsp)
movsbl 0x13(%rsp),%r13d
mov    %r13d,%edi
call   10b0 <dispchar@plt>
mov    %eax,%r10d
sub    $0x8,%rsp
lea    0xd49(%rip),%rdi
mov    0x2c(%rsp),%esi
mov    0x28(%rsp),%edx
mov    0x24(%rsp),%ecx
mov    0x20(%rsp),%r8d
mov    0x1c(%rsp),%r9d
xor    %eax,%eax
push   %r13
push   %r14
push   %r12
push   %r15
push   0x58(%rsp)
push   0x70(%rsp)
push   0x80(%rsp)
push   0x90(%rsp)
push   %r10
push   0x78(%rsp)
push   0x90(%rsp)
call   1080 <printf@plt>
add    $0x60,%rsp
lea    0xd35(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x8,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     139b <fs_loadall+0x1eb>
lea    0xd23(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x5,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
jne    13a9 <fs_loadall+0x1f9>
mov    0x11(%rsp),%al
cmp    $0x31,%al
jl     13a9 <fs_loadall+0x1f9>
cmp    $0x39,%al
jg     13a9 <fs_loadall+0x1f9>
cmpb   $0x2e,0x12(%rsp)
jne    13a9 <fs_loadall+0x1f9>
mov    0x13(%rsp),%cl
cmp    $0x30,%cl
jl     13a9 <fs_loadall+0x1f9>
cmp    $0x39,%cl
jg     13a9 <fs_loadall+0x1f9>
shl    $0x4,%al
add    %cl,%al
add    $0xd0,%al
cmp    $0x16,%al
jg     13b2 <fs_loadall+0x202>
cmpb   $0x0,0x0(%rbp)
je     1406 <fs_loadall+0x256>
lea    0xcd8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13de <fs_loadall+0x22e>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
jmp    13e6 <fs_loadall+0x236>
lea    0xd7b(%rip),%rdi
jmp    13d9 <fs_loadall+0x229>
lea    0xd67(%rip),%rdi
call   1040 <puts@plt>
jmp    13c5 <fs_loadall+0x215>
lea    0xcd9(%rip),%rdi
jmp    13d9 <fs_loadall+0x229>
movsbl %al,%esi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   10a0 <fs_load@plt>
test   %rax,%rax
js     13de <fs_loadall+0x22e>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     13fa <fs_loadall+0x24a>
lea    0xcd6(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
jmp    13eb <fs_loadall+0x23b>
mov    %rbx,%rdi
call   1030 <fs_load_pre17@plt>
test   %rax,%rax
js     142e <fs_loadall+0x27e>
mov    %rbx,%rdi
mov    $0x10,%esi
call   10d0 <chunk_load@plt>
test   %rax,%rax
jns    13c5 <fs_loadall+0x215>
lea    0xc9a(%rip),%rdi
jmp    13d9 <fs_loadall+0x229>
lea    0xcb1(%rip),%rdi
jmp    13d9 <fs_loadall+0x229>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"can't open metadata file\0A\00"
@.str.2 = [28 x i8] c"can't read metadata header\0A\00"
@.str.3 = [5 x i8] c"HEAD\00"
@.str.4 = [63 x i8] c"# header: %c%c%c%c%c%c%c%c (%02X%02X%02X%02X%02X%02X%02X%02X)\0A\00"
@.str.5 = [9 x i8] c"MFSM NEW\00"
@.str.6 = [12 x i8] c"empty file\0A\00"
@.str.7 = [6 x i8] c"MFSM \00"
@.str.8 = [54 x i8] c"old format detected - can't dump sections separatelly\00"
@.str.9 = [36 x i8] c"error reading metadata (structure)\0A\00"
@.str.10 = [33 x i8] c"error reading metadata (chunks)\0A\00"
@.str.11 = [39 x i8] c"wrong metadata header (old version ?)\0A\00"
@.str.12 = [24 x i8] c"error reading metadata\0A\00"
define i32 @fs_loadall(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [8 x i8]
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %188
15: ; preds = %2
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32 @fread(i8* %16, i32 1, i32 8, i32* %17)
%19 = icmp ne i32 %18, 8
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
store i32 -1, i32* %3
br label %188
24: ; preds = %15
%25 = load i8*, i8** %5
%26 = call i64 @memcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %84
34: ; preds = %28, %24
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%36 = load i8, i8* %35
%37 = call i32 @dispchar(i8 signext %36)
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
%39 = load i8, i8* %38
%40 = call i32 @dispchar(i8 signext %39)
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 2
%42 = load i8, i8* %41
%43 = call i32 @dispchar(i8 signext %42)
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 3
%45 = load i8, i8* %44
%46 = call i32 @dispchar(i8 signext %45)
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 4
%48 = load i8, i8* %47
%49 = call i32 @dispchar(i8 signext %48)
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%51 = load i8, i8* %50
%52 = call i32 @dispchar(i8 signext %51)
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 6
%54 = load i8, i8* %53
%55 = call i32 @dispchar(i8 signext %54)
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%57 = load i8, i8* %56
%58 = call i32 @dispchar(i8 signext %57)
%59 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 2
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 3
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 4
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 6
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %40, i32 %43, i32 %46, i32 %49, i32 %52, i32 %55, i32 %58, i32 %61, i32 %64, i32 %67, i32 %70, i32 %73, i32 %76, i32 %79, i32 %82)
br label %84
84: ; preds = %34, %28
%85 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%86 = call i64 @memcmp(i8* %85, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %177
90: ; preds = %84
%91 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%92 = call i64 @memcmp(i8* %91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %172
94: ; preds = %90
%95 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp sge i32 %97, 49
br i1 %98, label %99, label %172
99: ; preds = %94
%100 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp sle i32 %102, 57
br i1 %103, label %104, label %172
104: ; preds = %99
%105 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 6
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %107, 46
br i1 %108, label %109, label %172
109: ; preds = %104
%110 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp sge i32 %112, 48
br i1 %113, label %114, label %172
114: ; preds = %109
%115 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = icmp sle i32 %117, 57
br i1 %118, label %119, label %172
119: ; preds = %114
%120 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = sub nsw i32 %122, 48
%124 = shl i32 %123, 4
%125 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%126 = load i8, i8* %125
%127 = sext i8 %126 to i32
%128 = sub nsw i32 %127, 48
%129 = add nsw i32 %124, %128
%130 = trunc i32 %129 to i8
store i8 %130, i8* %8
%131 = load i8, i8* %8
%132 = sext i8 %131 to i32
%133 = icmp slt i32 %132, 23
br i1 %133, label %134, label %161
134: ; preds = %119
%135 = load i8*, i8** %5
%136 = getelementptr inbounds i8, i8* %135, i64 0
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %144
140: ; preds = %134
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
%142 = load i32*, i32** %6
%143 = call i32 @fclose(i32* %142)
store i32 -1, i32* %3
br label %188
144: ; preds = %134
%145 = load i32*, i32** %6
%146 = call i64 @fs_load_pre17(i32* %145)
%147 = icmp slt i64 %146, 0
br i1 %147, label %148, label %152
148: ; preds = %144
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%150 = load i32*, i32** %6
%151 = call i32 @fclose(i32* %150)
store i32 -1, i32* %3
br label %188
152: ; preds = %144
%153 = load i32*, i32** %6
%154 = call i64 @chunk_load(i32* %153, i32 16)
%155 = icmp slt i64 %154, 0
br i1 %155, label %156, label %160
156: ; preds = %152
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%158 = load i32*, i32** %6
%159 = call i32 @fclose(i32* %158)
store i32 -1, i32* %3
br label %188
160: ; preds = %152
br label %171
161: ; preds = %119
%162 = load i32*, i32** %6
%163 = load i8, i8* %8
%164 = load i8*, i8** %5
%165 = call i64 @fs_load(i32* %162, i8 signext %163, i8* %164)
%166 = icmp slt i64 %165, 0
br i1 %166, label %167, label %170
167: ; preds = %161
%168 = load i32*, i32** %6
%169 = call i32 @fclose(i32* %168)
store i32 -1, i32* %3
br label %188
170: ; preds = %161
br label %171
171: ; preds = %170, %160
br label %176
172: ; preds = %114, %109, %104, %99, %94, %90
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0))
%174 = load i32*, i32** %6
%175 = call i32 @fclose(i32* %174)
store i32 -1, i32* %3
br label %188
176: ; preds = %171
br label %177
177: ; preds = %176, %88
%178 = load i32*, i32** %6
%179 = call i64 @ferror(i32* %178)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %185
181: ; preds = %177
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%183 = load i32*, i32** %6
%184 = call i32 @fclose(i32* %183)
store i32 -1, i32* %3
br label %188
185: ; preds = %177
%186 = load i32*, i32** %6
%187 = call i32 @fclose(i32* %186)
store i32 0, i32* %3
br label %188
188: ; preds = %185, %181, %172, %167, %156, %148, %140, %20, %13
%189 = load i32, i32* %3
ret i32 %189
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"HEAD\00"
@.str.4 = [63 x i8] c"# header: %c%c%c%c%c%c%c%c (%02X%02X%02X%02X%02X%02X%02X%02X)\0A\00"
@.str.5 = [9 x i8] c"MFSM NEW\00"
@.str.7 = [6 x i8] c"MFSM \00"
@.str.8 = [54 x i8] c"old format detected - can't dump sections separatelly\00"
@str = [38 x i8] c"wrong metadata header (old version ?)\00"
@str.13 = [23 x i8] c"error reading metadata\00"
@str.14 = [32 x i8] c"error reading metadata (chunks)\00"
@str.15 = [35 x i8] c"error reading metadata (structure)\00"
@str.16 = [11 x i8] c"empty file\00"
@str.17 = [27 x i8] c"can't read metadata header\00"
@str.18 = [25 x i8] c"can't open metadata file\00"
define i32 @fs_loadall(i8* nocapture %0, i8* %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.18, i64 0, i64 0))
br label %117
9: ; preds = %2
%10 = call i32 @fread(i8* %4, i32 1, i32 8, i32* %5)
%11 = icmp eq i32 %10, 8
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.17, i64 0, i64 0))
%14 = tail call i32 @fclose(i32* %5)
br label %117
15: ; preds = %9
%16 = tail call i64 @memcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i8, i8* %1
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %54
21: ; preds = %18, %15
%22 = load i8, i8* %4
%23 = tail call i32 @dispchar(i8 signext %22)
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%25 = load i8, i8* %24
%26 = tail call i32 @dispchar(i8 signext %25)
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%28 = load i8, i8* %27
%29 = tail call i32 @dispchar(i8 signext %28)
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%31 = load i8, i8* %30
%32 = tail call i32 @dispchar(i8 signext %31)
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%34 = load i8, i8* %33
%35 = tail call i32 @dispchar(i8 signext %34)
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%37 = load i8, i8* %36
%38 = tail call i32 @dispchar(i8 signext %37)
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%40 = load i8, i8* %39
%41 = tail call i32 @dispchar(i8 signext %40)
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%43 = load i8, i8* %42
%44 = tail call i32 @dispchar(i8 signext %43)
%45 = sext i8 %22 to i32
%46 = sext i8 %25 to i32
%47 = sext i8 %28 to i32
%48 = sext i8 %31 to i32
%49 = sext i8 %34 to i32
%50 = sext i8 %37 to i32
%51 = sext i8 %40 to i32
%52 = sext i8 %43 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %26, i32 %29, i32 %32, i32 %35, i32 %38, i32 %41, i32 %44, i32 %45, i32 %46, i32 %47, i32 %48, i32 %49, i32 %50, i32 %51, i32 %52)
br label %54
54: ; preds = %21, %18
%55 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
br label %109
59: ; preds = %54
%60 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%61 = icmp eq i64 %60, 0
%62 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%63 = load i8, i8* %62
%64 = icmp sgt i8 %63, 48
%65 = select i1 %61, i1 %64, i1 false
%66 = icmp slt i8 %63, 58
%67 = select i1 %65, i1 %66, i1 false
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%69 = load i8, i8* %68
%70 = icmp eq i8 %69, 46
%71 = select i1 %67, i1 %70, i1 false
%72 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%73 = load i8, i8* %72
%74 = icmp sgt i8 %73, 47
%75 = select i1 %71, i1 %74, i1 false
%76 = icmp slt i8 %73, 58
%77 = select i1 %75, i1 %76, i1 false
br i1 %77, label %78, label %106
78: ; preds = %59
%79 = shl i8 %63, 4
%80 = add i8 %79, -48
%81 = add i8 %80, %73
%82 = icmp slt i8 %81, 23
br i1 %82, label %83, label %101
83: ; preds = %78
%84 = load i8, i8* %1
%85 = icmp eq i8 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %83
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
%88 = call i32 @fclose(i32* %5)
br label %117
89: ; preds = %83
%90 = call i64 @fs_load_pre17(i32* %5)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.15, i64 0, i64 0))
%94 = call i32 @fclose(i32* %5)
br label %117
95: ; preds = %89
%96 = call i64 @chunk_load(i32* %5, i32 16)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %109
98: ; preds = %95
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.14, i64 0, i64 0))
%100 = call i32 @fclose(i32* %5)
br label %117
101: ; preds = %78
%102 = call i64 @fs_load(i32* %5, i8 signext %81, i8* %1)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %101
%105 = call i32 @fclose(i32* %5)
br label %117
106: ; preds = %59
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%108 = call i32 @fclose(i32* %5)
br label %117
109: ; preds = %101, %95, %57
%110 = call i64 @ferror(i32* %5)
%111 = icmp eq i64 %110, 0
br i1 %111, label %115, label %112
112: ; preds = %109
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.13, i64 0, i64 0))
%114 = call i32 @fclose(i32* %5)
br label %117
115: ; preds = %109
%116 = call i32 @fclose(i32* %5)
br label %117
117: ; preds = %115, %112, %106, %104, %98, %92, %86, %12, %7
%118 = phi i32 [ -1, %7 ], [ -1, %12 ], [ -1, %112 ], [ 0, %115 ], [ -1, %86 ], [ -1, %92 ], [ -1, %98 ], [ -1, %104 ], [ -1, %106 ]
ret i32 %118
}