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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
size_t fread(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
scalar_t__ xmalloc(size_t);
size_t _pst_read_block(FILE *fp, int32_t offset, void **buf) {
  size_t size;
  int32_t fpos;
  {};
  {};
  fpos = ftell(fp);
  fseek(fp, offset, SEEK_SET);
  fread(&size, sizeof(int16_t), 1, fp);
  fseek(fp, offset, SEEK_SET);
  {};
  if (*buf != NULL) {
    {};
    free(*buf);
  }
  *buf = (void *)xmalloc(size);
  size = fread(*buf, 1, size, fp);
  fseek(fp, fpos, SEEK_SET);
  {};
  return size;
}


x86 assembly (clang, -O0):
<_pst_read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ca <_pst_read_block+0x7a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pst_read_block>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <ftell@plt>
mov    %eax,%r14d
mov    0x2e6d(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x1,%edx
mov    $0x4,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <fseek@plt>
mov    (%r15),%rdi
test   %rdi,%rdi
je     11b3 <_pst_read_block+0x63>
call   1030 <free@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <xmalloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%rbp
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <fseek@plt>
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @_pst_read_block(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%9 = load i32*, i32** %4
%10 = call i32 @ftell(i32* %9)
store i32 %10, i32* %8
%11 = load i32*, i32** %4
%12 = load i32, i32* %5
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %11, i32 %12, i32 %13)
%15 = bitcast i64* %7 to i8*
%16 = load i32*, i32** %4
%17 = call i64 @fread(i8* %15, i32 4, i64 1, i32* %16)
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %18, i32 %19, i32 %20)
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %3
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %25, %3
%30 = load i64, i64* %7
%31 = call i64 @xmalloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
%33 = load i8**, i8*** %6
store i8* %32, i8** %33
%34 = load i8**, i8*** %6
%35 = load i8*, i8** %34
%36 = load i64, i64* %7
%37 = load i32*, i32** %4
%38 = call i64 @fread(i8* %35, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %7
%39 = load i32*, i32** %4
%40 = load i32, i32* %8
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %39, i32 %40, i32 %41)
%43 = load i64, i64* %7
ret i64 %43
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @_pst_read_block(i32* nocapture %0, i32 %1, i8** nocapture %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = tail call i32 @ftell(i32* %0)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i32 %1, i32 %7)
%9 = call i64 @fread(i8* %5, i32 4, i64 1, i32* %0)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %0, i32 %1, i32 %10)
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = tail call i32 @free(i8* %12)
br label %16
16: ; preds = %14, %3
%17 = load i64, i64* %4
%18 = tail call i64 @xmalloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %2
%20 = tail call i64 @fread(i8* %19, i32 1, i64 %17, i32* %0)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %0, i32 %6, i32 %21)
ret i64 %20
}