#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 */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ sisRead(int /*<<< orphan*/ *, void *, int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strerror(int /*<<< orphan*/);
int sisReadOffset(FILE *fp, void *ptr, int len, int off, char *err,
                  int errlen) {
  long oldpos = ftell(fp);
  if (oldpos == -1 || fseek(fp, off, SEEK_SET) == -1) {
    snprintf(err, errlen, "seeking: %s", strerror(errno));
    return 1;
  }
  if (sisRead(fp, ptr, len, err, errlen))
    return 1;
  if (fseek(fp, oldpos, SEEK_SET) == -1) {
    snprintf(err, errlen, "seeking: %s", strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sisReadOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
je     11a5 <sisReadOffset+0x55>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rsi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11e3 <sisReadOffset+0x93>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %rax,%rcx
lea    0xe2e(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1275 <sisReadOffset+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1050 <sisRead@plt>
cmp    $0x0,%rax
je     1211 <sisReadOffset+0xc1>
movl   $0x1,-0x4(%rbp)
jmp    1275 <sisReadOffset+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    126e <sisReadOffset+0x11e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %rax,%rcx
lea    0xda3(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1275 <sisReadOffset+0x125>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sisReadOffset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8,%r15
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
call   1040 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     11d1 <sisReadOffset+0x81>
mov    %rax,%rbx
movslq %r14d,%rsi
mov    0x2e51(%rip),%r14
mov    (%r14),%edx
mov    %rbp,%rdi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
je     11d1 <sisReadOffset+0x81>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
mov    0x4(%rsp),%r8d
call   1050 <sisRead@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11fa <sisReadOffset+0xaa>
mov    (%r14),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <fseek@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11fa <sisReadOffset+0xaa>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe1a(%rip),%rdx
mov    %r15,%rdi
mov    0x4(%rsp),%esi
mov    %rax,%rcx
call   1030 <snprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [12 x i8] c"seeking: %s\00"
@errno = global i32 0
define i32 @sisReadOffset(i32* %0, i8* %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i64
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%15 = load i32*, i32** %8
%16 = call i64 @ftell(i32* %15)
store i64 %16, i64* %14
%17 = load i64, i64* %14
%18 = icmp eq i64 %17, -1
br i1 %18, label %26, label %19
19: ; preds = %6
%20 = load i32*, i32** %8
%21 = load i32, i32* %11
%22 = sext i32 %21 to i64
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %20, i64 %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %19, %6
%27 = load i8*, i8** %12
%28 = load i32, i32* %13
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @snprintf(i8* %27, i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %30)
store i32 1, i32* %7
br label %54
32: ; preds = %19
%33 = load i32*, i32** %8
%34 = load i8*, i8** %9
%35 = load i32, i32* %10
%36 = load i8*, i8** %12
%37 = load i32, i32* %13
%38 = call i64 @sisRead(i32* %33, i8* %34, i32 %35, i8* %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 1, i32* %7
br label %54
41: ; preds = %32
%42 = load i32*, i32** %8
%43 = load i64, i64* %14
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @fseek(i32* %42, i64 %43, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = load i8*, i8** %12
%49 = load i32, i32* %13
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @snprintf(i8* %48, i32 %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %51)
store i32 1, i32* %7
br label %54
53: ; preds = %41
store i32 0, i32* %7
br label %54
54: ; preds = %53, %47, %40, %26
%55 = load i32, i32* %7
ret i32 %55
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [12 x i8] c"seeking: %s\00"
@errno = global i32 0
define i32 @sisReadOffset(i32* %0, i8* %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = tail call i64 @ftell(i32* %0)
%8 = icmp eq i64 %7, -1
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = sext i32 %3 to i64
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %0, i64 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %21, label %14
14: ; preds = %9
%15 = tail call i64 @sisRead(i32* %0, i8* %1, i32 %2, i8* %4, i32 %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %0, i64 %7, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %17, %6, %9
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 @snprintf(i8* %4, i32 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %17, %14
%26 = phi i32 [ 1, %14 ], [ 0, %17 ], [ 1, %21 ]
ret i32 %26
}