#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*/ exit(int);
int my_fclose(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ *my_fopen(char const *, char *);
int my_fread(unsigned char *, size_t, int /*<<< orphan*/ *, char const *,
             char const *);
int my_fseek(int /*<<< orphan*/ *, long, char const *);
unsigned char *my_malloc(size_t, char const *);
unsigned char *my_fread_from_position(const char *path, long offset,
                                      size_t size, const char *item) {
  FILE *input;
  int result;
  unsigned char *data;
  data = my_malloc(size, item);
  if (data == NULL)
    exit(1);
  input = my_fopen(path, "r");
  if (input == NULL)
    exit(1);
  result = my_fseek(input, offset, path);
  if (result == -1)
    exit(1);
  result = my_fread(data, size, input, item, path);
  if (result == -1)
    exit(1);
  result = my_fclose(input, path);
  if (result == -1)
    exit(1);
  return data;
}


x86 assembly (clang, -O0):
<my_fread_from_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <my_malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119e <my_fread_from_position+0x3e>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1030 <my_fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c7 <my_fread_from_position+0x67>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1070 <my_fseek@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11ef <my_fread_from_position+0x8f>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
call   1050 <my_fread@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    121f <my_fread_from_position+0xbf>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <my_fclose@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1243 <my_fread_from_position+0xe3>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fread_from_position>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1040 <my_malloc@plt>
test   %rax,%rax
je     11ef <my_fread_from_position+0x8f>
mov    %rax,%r14
lea    0xe6f(%rip),%rsi
mov    %r13,%rdi
call   1030 <my_fopen@plt>
test   %rax,%rax
je     11ef <my_fread_from_position+0x8f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1070 <my_fseek@plt>
cmp    $0xffffffff,%eax
je     11ef <my_fread_from_position+0x8f>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1050 <my_fread@plt>
cmp    $0xffffffff,%eax
je     11ef <my_fread_from_position+0x8f>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <my_fclose@plt>
cmp    $0xffffffff,%eax
je     11ef <my_fread_from_position+0x8f>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @my_fread_from_position(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = tail call i8* @my_malloc(i64 %2, i8* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %4
%10 = tail call i32* @my_fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %9
%15 = tail call i32 @my_fseek(i32* %10, i64 %1, i8* %0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %14
%20 = tail call i32 @my_fread(i8* %5, i64 %2, i32* %10, i8* %3, i8* %0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %19
%25 = tail call i32 @my_fclose(i32* %10, i8* %0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %24
ret i8* %5
}