#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__ LZ4IO_isSkippableMagicNumber(unsigned int const);
unsigned int LZ4IO_readLE32(unsigned char **);
int /*<<< orphan*/ SEEK_CUR;
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, unsigned int const, int /*<<< orphan*/);
unsigned long long LZ4IO_skipLegacyBlocksData(FILE *finput) {
  unsigned char blockInfo[4];
  unsigned long long totalBlocksSize = 0;
  {
    enum { LZ4IO_static_assert = 1 / (int)(!!(4 == 4)) };
  };
  for (;;) {
    if (!fread(blockInfo, 1, 4, finput)) {
      if (feof(finput))
        return totalBlocksSize;
      return 0;
    }
    {
      const unsigned int nextCBlockSize = LZ4IO_readLE32(&blockInfo);
      if (nextCBlockSize == 0x184C2102 || nextCBlockSize == 0x184D2204 ||
          LZ4IO_isSkippableMagicNumber(nextCBlockSize)) {
        if (fseek(finput, -4, SEEK_CUR) != 0) {
          return 0;
        }
        break;
      }
      totalBlocksSize += 4 + nextCBlockSize;
      if (fseek(finput, nextCBlockSize, SEEK_CUR) != 0) {
        return 0;
      }
    }
  }
  return totalBlocksSize;
}


x86 assembly (clang, -O0):
<LZ4IO_skipLegacyBlocksData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    11b1 <LZ4IO_skipLegacyBlocksData+0x61>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11a4 <LZ4IO_skipLegacyBlocksData+0x54>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1265 <LZ4IO_skipLegacyBlocksData+0x115>
movq   $0x0,-0x8(%rbp)
jmp    1265 <LZ4IO_skipLegacyBlocksData+0x115>
lea    -0x14(%rbp),%rdi
call   1040 <LZ4IO_readLE32@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x184c2102,-0x24(%rbp)
je     11e9 <LZ4IO_skipLegacyBlocksData+0x99>
cmpl   $0x184d2204,-0x24(%rbp)
je     11e9 <LZ4IO_skipLegacyBlocksData+0x99>
mov    -0x24(%rbp),%edi
call   1050 <LZ4IO_isSkippableMagicNumber@plt>
cmp    $0x0,%rax
je     121c <LZ4IO_skipLegacyBlocksData+0xcc>
mov    -0x10(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     1217 <LZ4IO_skipLegacyBlocksData+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    1265 <LZ4IO_skipLegacyBlocksData+0x115>
jmp    125d <LZ4IO_skipLegacyBlocksData+0x10d>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     1258 <LZ4IO_skipLegacyBlocksData+0x108>
movq   $0x0,-0x8(%rbp)
jmp    1265 <LZ4IO_skipLegacyBlocksData+0x115>
jmp    1164 <LZ4IO_skipLegacyBlocksData+0x14>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LZ4IO_skipLegacyBlocksData>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
mov    0x2e7b(%rip),%r12
nopl   (%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     11e4 <LZ4IO_skipLegacyBlocksData+0x94>
mov    %r15,%rdi
call   1040 <LZ4IO_readLE32@plt>
cmp    $0x184c2102,%eax
je     11ca <LZ4IO_skipLegacyBlocksData+0x7a>
mov    %eax,%ebp
cmp    $0x184d2204,%eax
je     11ca <LZ4IO_skipLegacyBlocksData+0x7a>
mov    %ebp,%edi
call   1050 <LZ4IO_isSkippableMagicNumber@plt>
test   %rax,%rax
jne    11ca <LZ4IO_skipLegacyBlocksData+0x7a>
mov    %ebp,%eax
add    $0x4,%eax
add    %rax,%rbx
mov    (%r12),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <fseek@plt>
test   %rax,%rax
je     1170 <LZ4IO_skipLegacyBlocksData+0x20>
jmp    11e0 <LZ4IO_skipLegacyBlocksData+0x90>
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0xfffffffc,%esi
call   1070 <fseek@plt>
test   %rax,%rax
je     11f3 <LZ4IO_skipLegacyBlocksData+0xa3>
xor    %ebx,%ebx
jmp    11f3 <LZ4IO_skipLegacyBlocksData+0xa3>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i64 @LZ4IO_skipLegacyBlocksData(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
store i64 0, i64* %5
br label %7
7: ; preds = %50, %1
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32 @fread(i8* %8, i32 1, i32 4, i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i64, i64* %5
store i64 %17, i64* %2
br label %53
18: ; preds = %12
store i64 0, i64* %2
br label %53
19: ; preds = %7
%20 = bitcast [4 x i8]* %4 to i8**
%21 = call i32 @LZ4IO_readLE32(i8** %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 407642370
br i1 %23, label %31, label %24
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 407708164
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load i32, i32* %6
%29 = call i64 @LZ4IO_isSkippableMagicNumber(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %27, %24, %19
%32 = load i32*, i32** %3
%33 = load i32, i32* @SEEK_CUR
%34 = call i64 @fseek(i32* %32, i32 -4, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
store i64 0, i64* %2
br label %53
37: ; preds = %31
br label %51
38: ; preds = %27
%39 = load i32, i32* %6
%40 = add i32 4, %39
%41 = zext i32 %40 to i64
%42 = load i64, i64* %5
%43 = add i64 %42, %41
store i64 %43, i64* %5
%44 = load i32*, i32** %3
%45 = load i32, i32* %6
%46 = load i32, i32* @SEEK_CUR
%47 = call i64 @fseek(i32* %44, i32 %45, i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %38
store i64 0, i64* %2
br label %53
50: ; preds = %38
br label %7
51: ; preds = %37
%52 = load i64, i64* %5
store i64 %52, i64* %2
br label %53
53: ; preds = %51, %49, %36, %18, %16
%54 = load i64, i64* %2
ret i64 %54
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i64 @LZ4IO_skipLegacyBlocksData(i32* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = bitcast [4 x i8]* %2 to i8**
br label %5
5: ; preds = %22, %1
%6 = phi i64 [ 0, %1 ], [ %25, %22 ]
%7 = call i32 @fread(i8* %3, i32 1, i32 4, i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = call i64 @feof(i32* %0)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 0, i64 %6
br label %30
13: ; preds = %5
%14 = call i32 @LZ4IO_readLE32(i8** %4)
switch i32 %14, label %15 [
i32 407708164, label %18
i32 407642370, label %18
]
15: ; preds = %13
%16 = call i64 @LZ4IO_isSkippableMagicNumber(i32 %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13, %13, %15
%19 = load i32, i32* @SEEK_CUR
%20 = call i64 @fseek(i32* %0, i32 -4, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %29
22: ; preds = %15
%23 = add i32 %14, 4
%24 = zext i32 %23 to i64
%25 = add i64 %6, %24
%26 = load i32, i32* @SEEK_CUR
%27 = call i64 @fseek(i32* %0, i32 %14, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %5, label %29
29: ; preds = %22, %18
br label %30
30: ; preds = %18, %29, %9
%31 = phi i64 [ %12, %9 ], [ 0, %29 ], [ %6, %18 ]
ret i64 %31
}