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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fread(void *, int, scalar_t__, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int32_t _pst_getAtPos(FILE *fp, int32_t pos, void *buf, u_int32_t size) {
  {};
  if (fseek(fp, pos, SEEK_SET) == -1) {
    {};
    return 1;
  }
  if (fread(buf, 1, size, fp) < size) {
    {};
    return 2;
  }
  {};
  return 0;
}


x86 assembly (clang, -O0):
<_pst_getAtPos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1161 <_pst_getAtPos+0x41>
movl   $0x1,-0x4(%rbp)
jmp    1194 <_pst_getAtPos+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x28(%rbp),%rax
jge    118d <_pst_getAtPos+0x6d>
movl   $0x2,-0x4(%rbp)
jmp    1194 <_pst_getAtPos+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pst_getAtPos>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
je     1163 <_pst_getAtPos+0x43>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %r14,%rcx
setl   %al
add    %eax,%eax
jmp    1168 <_pst_getAtPos+0x48>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @_pst_getAtPos(i32* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i32*, i32** %6
%11 = load i32, i32* %7
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %10, i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %25
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = load i64, i64* %9
%19 = load i32*, i32** %6
%20 = call i64 @fread(i8* %17, i32 1, i64 %18, i32* %19)
%21 = load i64, i64* %9
%22 = icmp slt i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 2, i32* %5
br label %25
24: ; preds = %16
store i32 0, i32* %5
br label %25
25: ; preds = %24, %23, %15
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @_pst_getAtPos(i32* nocapture %0, i32 %1, i8* nocapture %2, i64 %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 %1, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i64 @fread(i8* %2, i32 1, i64 %3, i32* %0)
%10 = icmp slt i64 %9, %3
%11 = select i1 %10, i32 2, i32 0
br label %12
12: ; preds = %8, %4
%13 = phi i32 [ 1, %4 ], [ %11, %8 ]
ret i32 %13
}