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

/* Variables and functions */
int /*<<< orphan*/ EIO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void ReadValueFromFp(FILE *fp, unsigned int *value) {
  int retVal;
  char buf[33];
  fseek(fp, 0, 0);
  retVal = fread(buf, 1, sizeof(buf), fp);
  if (retVal == -1) {
    printf("ERROR: failed to read value from file pointer\n");
    exit(EIO);
  }
  *value = strtoul(buf, NULL, 0);
  return;
}


x86 assembly (clang, -O0):
<ReadValueFromFp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <fseek@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x21,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ab <ReadValueFromFp+0x5b>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadValueFromFp>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x21,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0xffffffff,%eax
je     1197 <ReadValueFromFp+0x47>
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"ERROR: failed to read value from file pointer\0A\00"
@EIO = global i32 0
define void @ReadValueFromFp(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [33 x i8]
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %3
%8 = call i32 @fseek(i32* %7, i32 0, i32 0)
%9 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32 @fread(i8* %9, i32 1, i32 33, i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EIO
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%20 = call i32 @strtoul(i8* %19, i32* null, i32 0)
%21 = load i32*, i32** %4
store i32 %20, i32* %21
ret void
}

LLVM IR (-O2):
@EIO = global i32 0
@str = [46 x i8] c"ERROR: failed to read value from file pointer\00"
define void @ReadValueFromFp(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [33 x i8]
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @fseek(i32* %0, i32 0, i32 0)
%6 = call i32 @fread(i8* %4, i32 1, i32 33, i32* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EIO
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 0)
store i32 %13, i32* %1
ret void
}