#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 */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, char, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ read_part(int /*<<< orphan*/ *, long);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *img;
  long int imgsize;
  char buffer[20];
  img = fopen(argv[1], "rb");
  fseek(img, 0, SEEK_END);
  imgsize = ftell(img);
  fseek(img, 0, SEEK_SET);
  if (fread(buffer, 1, 16, img) < 16) {
    fprintf(stderr, "Unable to read header of image\n");
    exit(1);
  }
  if ((memcmp(buffer, "hsqs", 4) == 0) || (memcmp(buffer, "sqsh", 4) == 0)) {
    printf("Format: squashfs\n");
    exit(0);
  }
  if (memcmp(buffer,
             "\x63\x7b\x9d\x26\xb7\xfd\x48\x30\x89\xf9\x11\xcf\x18\xfd\xff\xa1",
             16) == 0) {
    printf("Format: "
           "confluent_"
           "multisquash\nminsize\tdefsize\toffset\tsize\tfstype\torigdev\tmount"
           "\n");
    fread(buffer, 1, 1, img);
    fseek(img, buffer[0], SEEK_CUR);
    while (read_part(img, imgsize))
      ;
    exit(0);
  }
  if (memcmp(buffer,
             "\xaa\xd5\x0f\x7e\x5d\xfb\x4b\x7c\xa1\x2a\xf4\x0b\x6d\x94\xf7\xfc",
             16) == 0) {
    fread(buffer, 1, 1, img);
    fseek(img, buffer[0], SEEK_CUR);
    fread(buffer, 1, 1, img);
    if (buffer[0] == 0) {
      printf("Format: confluent_crypted\n");
      exit(0);
    }
  }
  fprintf(stderr, "Unrecognized image format\n");
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
cmp    $0x10,%eax
jge    1232 <main+0xa2>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x40(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1270 <main+0xe0>
lea    -0x40(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    1283 <main+0xf3>
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x40(%rbp),%rdi
lea    0xdb1(%rip),%rsi
mov    $0x10,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    12fd <main+0x16d>
lea    0xda7(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%al
mov    0x2d10(%rip),%rcx
mov    (%rcx),%edx
movsbl %al,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <read_part@plt>
cmp    $0x0,%rax
je     12f6 <main+0x166>
jmp    12da <main+0x14a>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x40(%rbp),%rdi
lea    0xd98(%rip),%rsi
mov    $0x10,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    1381 <main+0x1f1>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%al
mov    0x2ca2(%rip),%rcx
mov    (%rcx),%edx
movsbl %al,%esi
call   1090 <fseek@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0x40(%rbp),%eax
cmp    $0x0,%eax
jne    137c <main+0x1ec>
lea    0xd41(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1381 <main+0x1f1>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
lea    0xe5e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbx
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0xf,%eax
jg     1214 <main+0x84>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe08(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1246 <main+0xb6>
lea    0xdf4(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    1259 <main+0xc9>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdcd(%rip),%rsi
mov    %rsp,%rdi
mov    $0x10,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    12c7 <main+0x137>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movsbl (%rsp),%esi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1090 <fseek@plt>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <read_part@plt>
test   %rax,%rax
jne    12b0 <main+0x120>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd70(%rip),%rsi
mov    %rsp,%rdi
mov    $0x10,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    1334 <main+0x1a4>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movsbl (%rsp),%esi
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1090 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmpb   $0x0,(%rsp)
jne    1334 <main+0x1a4>
lea    0xd3b(%rip),%rdi
jmp    124d <main+0xbd>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xd0b(%rip),%rsi
jmp    1205 <main+0x75>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Unable to read header of image\0A\00"
@.str.2 = [5 x i8] c"hsqs\00"
@.str.3 = [5 x i8] c"sqsh\00"
@.str.4 = [18 x i8] c"Format: squashfs\0A\00"
@.str.5 = [17 x i8] c"c{\9D&\B7\FDH0\89\F9\11\CF\18\FD\FF\A1\00"
@.str.6 = [80 x i8] c"Format: confluent_multisquash\0Aminsize\09defsize\09offset\09size\09fstype\09origdev\09mount\0A\00"
@SEEK_CUR = global i32 0
@.str.7 = [17 x i8] c"\AA\D5\0F~]\FBK|\A1*\F4\0Bm\94\F7\FC\00"
@.str.8 = [27 x i8] c"Format: confluent_crypted\0A\00"
@.str.9 = [27 x i8] c"Unrecognized image format\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca [20 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseek(i32* %13, i8 signext 0, i32 %14)
%16 = load i32*, i32** %6
%17 = call i64 @ftell(i32* %16)
store i64 %17, i64* %7
%18 = load i32*, i32** %6
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %18, i8 signext 0, i32 %19)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32 @fread(i8* %21, i32 1, i32 16, i32* %22)
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%35 = call i64 @memcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33, %29
%38 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %33
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%42 = call i64 @memcmp(i8* %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 16)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.6, i64 0, i64 0))
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = call i32 @fread(i8* %46, i32 1, i32 1, i32* %47)
%49 = load i32*, i32** %6
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%51 = load i8, i8* %50
%52 = load i32, i32* @SEEK_CUR
%53 = call i32 @fseek(i32* %49, i8 signext %51, i32 %52)
br label %54
54: ; preds = %59, %44
%55 = load i32*, i32** %6
%56 = load i64, i64* %7
%57 = call i64 @read_part(i32* %55, i64 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
br label %54
60: ; preds = %54
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %40
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%64 = call i64 @memcmp(i8* %63, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %86
66: ; preds = %62
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%68 = load i32*, i32** %6
%69 = call i32 @fread(i8* %67, i32 1, i32 1, i32* %68)
%70 = load i32*, i32** %6
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%72 = load i8, i8* %71
%73 = load i32, i32* @SEEK_CUR
%74 = call i32 @fseek(i32* %70, i8 signext %72, i32 %73)
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%76 = load i32*, i32** %6
%77 = call i32 @fread(i8* %75, i32 1, i32 1, i32* %76)
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %66
%83 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %66
br label %86
86: ; preds = %85, %62
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Unable to read header of image\0A\00"
@.str.2 = [5 x i8] c"hsqs\00"
@.str.3 = [5 x i8] c"sqsh\00"
@.str.5 = [17 x i8] c"c{\9D&\B7\FDH0\89\F9\11\CF\18\FD\FF\A1\00"
@SEEK_CUR = global i32 0
@.str.7 = [17 x i8] c"\AA\D5\0F~]\FBK|\A1*\F4\0Bm\94\F7\FC\00"
@.str.9 = [27 x i8] c"Unrecognized image format\0A\00"
@str = [26 x i8] c"Format: confluent_crypted\00"
@str.10 = [79 x i8] c"Format: confluent_multisquash\0Aminsize\09defsize\09offset\09size\09fstype\09origdev\09mount\00"
@str.11 = [17 x i8] c"Format: squashfs\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %7, i8 signext 0, i32 %8)
%10 = tail call i64 @ftell(i32* %7)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %7, i8 signext 0, i32 %11)
%13 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %7)
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.11, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 16)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.10, i64 0, i64 0))
%33 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %7)
%34 = load i8, i8* %4
%35 = load i32, i32* @SEEK_CUR
%36 = call i32 @fseek(i32* %7, i8 signext %34, i32 %35)
br label %37
37: ; preds = %37, %31
%38 = call i64 @read_part(i32* %7, i64 %10)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %37
40: ; preds = %37
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %28
%43 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %7)
%47 = load i8, i8* %4
%48 = load i32, i32* @SEEK_CUR
%49 = call i32 @fseek(i32* %7, i8 signext %47, i32 %48)
%50 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %7)
%51 = load i8, i8* %4
%52 = icmp eq i8 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %45, %42
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
}