#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int pfr_disk_read(FILE *fp, void *target_struct, int target_size,
                  char **flex_value, int *flex_size, const char *err_id) {
  int read_size_a = 0, read_size_b = 0;
  read_size_a = fread(target_struct, 1, target_size, fp);
  if (read_size_a == 0)
    return 0;
  if (read_size_a != target_size) {
    fprintf(stderr, "Error reading %s structure data: %s\n", err_id,
            strerror(errno));
    return 0;
  }
  *flex_value = realloc(*flex_value, *flex_size);
  if (*flex_value == NULL) {
    fprintf(stderr, "Error allocating memory for %s flexible value: %s\n",
            err_id, strerror(errno));
    return 0;
  }
  read_size_b = fread(*flex_value, 1, *flex_size, fp);
  if (read_size_b != *flex_size) {
    fprintf(stderr, "Error reading %s flexible value: %s\n", err_id,
            strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pfr_disk_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    119b <pfr_disk_read+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <pfr_disk_read+0x191>
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11eb <pfr_disk_read+0xab>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <pfr_disk_read+0x191>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1259 <pfr_disk_read+0x119>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xddd(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <pfr_disk_read+0x191>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%eax
je     12ca <pfr_disk_read+0x18a>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <pfr_disk_read+0x191>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfr_disk_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %edx,%ebx
mov    %rdi,%r13
mov    %rsi,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1030 <fread@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11e7 <pfr_disk_read+0xa7>
cmp    %ebx,%eax
jne    11ae <pfr_disk_read+0x6e>
mov    (%r12),%rdi
mov    (%r15),%esi
call   1050 <realloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11b7 <pfr_disk_read+0x77>
mov    (%r15),%edx
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1030 <fread@plt>
cmp    (%r15),%eax
je     11e7 <pfr_disk_read+0xa7>
lea    0xeac(%rip),%rbx
jmp    11be <pfr_disk_read+0x7e>
lea    0xe4b(%rip),%rbx
jmp    11be <pfr_disk_read+0x7e>
lea    0xe67(%rip),%rbx
mov    0x2e1b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Error reading %s structure data: %s\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"Error allocating memory for %s flexible value: %s\0A\00"
@.str.2 = [37 x i8] c"Error reading %s flexible value: %s\0A\00"
define i32 @pfr_disk_read(i32* %0, i8* %1, i32 %2, i8** %3, i32* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8** %3, i8*** %11
store i32* %4, i32** %12
store i8* %5, i8** %13
store i32 0, i32* %14
store i32 0, i32* %15
%16 = load i8*, i8** %9
%17 = load i32, i32* %10
%18 = load i32*, i32** %8
%19 = call i32 @fread(i8* %16, i32 1, i32 %17, i32* %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %6
store i32 0, i32* %7
br label %67
23: ; preds = %6
%24 = load i32, i32* %14
%25 = load i32, i32* %10
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %13
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %31)
store i32 0, i32* %7
br label %67
33: ; preds = %23
%34 = load i8**, i8*** %11
%35 = load i8*, i8** %34
%36 = load i32*, i32** %12
%37 = load i32, i32* %36
%38 = call i8* @realloc(i8* %35, i32 %37)
%39 = load i8**, i8*** %11
store i8* %38, i8** %39
%40 = load i8**, i8*** %11
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %49
43: ; preds = %33
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %13
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %45, i8* %47)
store i32 0, i32* %7
br label %67
49: ; preds = %33
%50 = load i8**, i8*** %11
%51 = load i8*, i8** %50
%52 = load i32*, i32** %12
%53 = load i32, i32* %52
%54 = load i32*, i32** %8
%55 = call i32 @fread(i8* %51, i32 1, i32 %53, i32* %54)
store i32 %55, i32* %15
%56 = load i32, i32* %15
%57 = load i32*, i32** %12
%58 = load i32, i32* %57
%59 = icmp ne i32 %56, %58
br i1 %59, label %60, label %66
60: ; preds = %49
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %13
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %64)
store i32 0, i32* %7
br label %67
66: ; preds = %49
store i32 1, i32* %7
br label %67
67: ; preds = %66, %60, %43, %27, %22
%68 = load i32, i32* %7
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Error reading %s structure data: %s\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"Error allocating memory for %s flexible value: %s\0A\00"
@.str.2 = [37 x i8] c"Error reading %s flexible value: %s\0A\00"
define i32 @pfr_disk_read(i32* nocapture %0, i8* nocapture %1, i32 %2, i8** nocapture %3, i32* nocapture %4, i8* %5) {
%7 = tail call i32 @fread(i8* %1, i32 1, i32 %2, i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %6
%10 = icmp eq i32 %7, %2
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = tail call i8* @realloc(i8* %12, i32 %13)
store i8* %14, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i32, i32* %4
%18 = tail call i32 @fread(i8* %14, i32 1, i32 %17, i32* %0)
%19 = load i32, i32* %4
%20 = icmp eq i32 %18, %19
br i1 %20, label %27, label %21
21: ; preds = %16, %11, %9
%22 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), %16 ]
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 @fprintf(i32 %23, i8* %22, i8* %5, i8* %25)
br label %27
27: ; preds = %21, %16, %6
%28 = phi i32 [ 0, %6 ], [ 1, %16 ], [ 0, %21 ]
ret i32 %28
}