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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ byteswap(scalar_t__ *, int);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ xfread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ xfseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
uint32_t local_findBlockEnd(uint32_t b1, uint32_t b1Swapped, FILE *f) {
  uint32_t b2;
  long pos = ftell(f);
  if (b1 < b1Swapped) {
    xfseek(f, (long)b1, SEEK_CUR);
    xfread(&b2, sizeof(int), 1, f);
    if (b1 != b2) {
      xfseek(f, pos + (long)b1Swapped, SEEK_SET);
      xfread(&b2, sizeof(uint32_t), 1, f);
      byteswap(&b2, sizeof(uint32_t));
    }
  } else {
    xfseek(f, (long)b1Swapped, SEEK_CUR);
    xfread(&b2, sizeof(uint32_t), 1, f);
    byteswap(&b2, sizeof(uint32_t));
    if (b1Swapped != b2) {
      xfseek(f, pos + (long)b1, SEEK_SET);
      xfread(&b2, sizeof(uint32_t), 1, f);
    }
  }
  xfseek(f, pos, SEEK_SET);
  return b2;
}


x86 assembly (clang, -O0):
<local_findBlockEnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11ee <local_findBlockEnd+0xae>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1040 <xfseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <xfread@plt>
mov    -0x8(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11e9 <local_findBlockEnd+0xa9>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x10(%rbp),%rsi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
call   1040 <xfseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <xfread@plt>
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1060 <byteswap@plt>
jmp    126d <local_findBlockEnd+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
call   1040 <xfseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <xfread@plt>
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1060 <byteswap@plt>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1268 <local_findBlockEnd+0x128>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x8(%rbp),%rsi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
call   1040 <xfseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <xfread@plt>
jmp    126d <local_findBlockEnd+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
call   1040 <xfseek@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_findBlockEnd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
cmp    %r15,%r12
jge    11dc <local_findBlockEnd+0x9c>
mov    %r12,%rsi
call   1040 <xfseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <xfread@plt>
cmp    %r12,0x8(%rsp)
je     1240 <local_findBlockEnd+0x100>
mov    %r14,%rsi
add    %r15,%rsi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1040 <xfseek@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <xfread@plt>
mov    %r15,%rdi
mov    $0x8,%esi
call   1060 <byteswap@plt>
jmp    1240 <local_findBlockEnd+0x100>
mov    %r15,%rsi
call   1040 <xfseek@plt>
lea    0x8(%rsp),%r13
mov    %r13,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <xfread@plt>
mov    %r13,%rdi
mov    $0x8,%esi
call   1060 <byteswap@plt>
cmp    %r15,0x8(%rsp)
je     1240 <local_findBlockEnd+0x100>
mov    %r14,%rsi
add    %r12,%rsi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1040 <xfseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <xfread@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <xfseek@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i64 @local_findBlockEnd(i64 %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%9 = load i32*, i32** %6
%10 = call i64 @ftell(i32* %9)
store i64 %10, i64* %8
%11 = load i64, i64* %4
%12 = load i64, i64* %5
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %35
14: ; preds = %3
%15 = load i32*, i32** %6
%16 = load i64, i64* %4
%17 = load i32, i32* @SEEK_CUR
%18 = call i32 @xfseek(i32* %15, i64 %16, i32 %17)
%19 = load i32*, i32** %6
%20 = call i32 @xfread(i64* %7, i32 4, i32 1, i32* %19)
%21 = load i64, i64* %4
%22 = load i64, i64* %7
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %14
%25 = load i32*, i32** %6
%26 = load i64, i64* %8
%27 = load i64, i64* %5
%28 = add nsw i64 %26, %27
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @xfseek(i32* %25, i64 %28, i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @xfread(i64* %7, i32 8, i32 1, i32* %31)
%33 = call i32 @byteswap(i64* %7, i32 8)
br label %34
34: ; preds = %24, %14
br label %56
35: ; preds = %3
%36 = load i32*, i32** %6
%37 = load i64, i64* %5
%38 = load i32, i32* @SEEK_CUR
%39 = call i32 @xfseek(i32* %36, i64 %37, i32 %38)
%40 = load i32*, i32** %6
%41 = call i32 @xfread(i64* %7, i32 8, i32 1, i32* %40)
%42 = call i32 @byteswap(i64* %7, i32 8)
%43 = load i64, i64* %5
%44 = load i64, i64* %7
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %55
46: ; preds = %35
%47 = load i32*, i32** %6
%48 = load i64, i64* %8
%49 = load i64, i64* %4
%50 = add nsw i64 %48, %49
%51 = load i32, i32* @SEEK_SET
%52 = call i32 @xfseek(i32* %47, i64 %50, i32 %51)
%53 = load i32*, i32** %6
%54 = call i32 @xfread(i64* %7, i32 8, i32 1, i32* %53)
br label %55
55: ; preds = %46, %35
br label %56
56: ; preds = %55, %34
%57 = load i32*, i32** %6
%58 = load i64, i64* %8
%59 = load i32, i32* @SEEK_SET
%60 = call i32 @xfseek(i32* %57, i64 %58, i32 %59)
%61 = load i64, i64* %7
ret i64 %61
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i64 @local_findBlockEnd(i64 %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = tail call i64 @ftell(i32* %2)
%7 = icmp slt i64 %0, %1
%8 = load i32, i32* @SEEK_CUR
br i1 %7, label %9, label %20
9: ; preds = %3
%10 = tail call i32 @xfseek(i32* %2, i64 %0, i32 %8)
%11 = call i32 @xfread(i64* %4, i32 4, i32 1, i32* %2)
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, %0
br i1 %13, label %31, label %14
14: ; preds = %9
%15 = add nsw i64 %6, %1
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @xfseek(i32* %2, i64 %15, i32 %16)
%18 = call i32 @xfread(i64* %4, i32 8, i32 1, i32* %2)
%19 = call i32 @byteswap(i64* %4, i32 8)
br label %31
20: ; preds = %3
%21 = tail call i32 @xfseek(i32* %2, i64 %1, i32 %8)
%22 = call i32 @xfread(i64* %4, i32 8, i32 1, i32* %2)
%23 = call i32 @byteswap(i64* %4, i32 8)
%24 = load i64, i64* %4
%25 = icmp eq i64 %24, %1
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = add nsw i64 %6, %0
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @xfseek(i32* %2, i64 %27, i32 %28)
%30 = call i32 @xfread(i64* %4, i32 8, i32 1, i32* %2)
br label %31
31: ; preds = %20, %26, %9, %14
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @xfseek(i32* %2, i64 %6, i32 %32)
%34 = load i64, i64* %4
ret i64 %34
}