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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int read_32_be(unsigned char *);
int /*<<< orphan*/ stderr;
uint32_t get_subblock_header(FILE *infile, long offset) {
  unsigned char subhead_buf[4];
  uint32_t pseudo_size;
  if (fseek(infile, offset, SEEK_SET)) {
    fprintf(stderr, "seek to 0x%lx to read subblock header failed\n",
            (unsigned long)offset);
    exit(EXIT_FAILURE);
  }
  if (fread(subhead_buf, 1, 4, infile) != 4) {
    fprintf(stderr, "read of subblock header at 0x%lx failed\n",
            (unsigned long)offset);
    exit(EXIT_FAILURE);
  }
  pseudo_size = read_32_be(&subhead_buf[0]);
  return (pseudo_size / 4);
}


x86 assembly (clang, -O0):
<get_subblock_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
cmp    $0x0,%rax
je     11a7 <get_subblock_header+0x57>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     11ee <get_subblock_header+0x9e>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x14(%rbp),%rdi
call   1040 <read_32_be@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_subblock_header>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
test   %rax,%rax
jne    11a6 <get_subblock_header+0x56>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    11b8 <get_subblock_header+0x68>
lea    0x4(%rsp),%rdi
call   1040 <read_32_be@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    11c8 <get_subblock_header+0x78>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"seek to 0x%lx to read subblock header failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [41 x i8] c"read of subblock header at 0x%lx failed\0A\00"
define i32 @get_subblock_header(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [4 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i32*, i32** %3
%8 = load i64, i64* %4
%9 = load i32, i32* @SEEK_SET
%10 = call i64 @fseek(i32* %7, i64 %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i64, i64* %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %3
%21 = call i32 @fread(i8* %19, i32 1, i32 4, i32* %20)
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i64, i64* %4
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%31 = call i32 @read_32_be(i8* %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = sdiv i32 %32, 4
ret i32 %33
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"seek to 0x%lx to read subblock header failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [41 x i8] c"read of subblock header at 0x%lx failed\0A\00"
define i32 @get_subblock_header(i32* nocapture %0, i64 %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @fseek(i32* %0, i64 %1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %1)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = call i32 @fread(i8* %4, i32 1, i32 4, i32* %0)
%15 = icmp eq i32 %14, 4
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %1)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 @read_32_be(i8* %4)
%23 = sdiv i32 %22, 4
ret i32 %23
}