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

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int read_value(FILE *f, uint32_t *value) {
  uint16_t sample[2];
  size_t rd = fread(sample, sizeof(uint16_t), 2, f);
  if (rd < 2) {
    if (feof(f))
      return 0;
    return -1;
  }
  *value = (sample[1] << 16) | sample[0];
  return rd;
}


x86 assembly (clang, -O0):
<read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x2,-0x28(%rbp)
jae    1181 <read_value+0x61>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1175 <read_value+0x55>
movl   $0x0,-0x4(%rbp)
jmp    1197 <read_value+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <read_value+0x77>
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_value>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%rax
ja     1155 <read_value+0x35>
mov    %rbx,%rdi
call   1040 <feof@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
jmp    1162 <read_value+0x42>
mov    0x4(%rsp),%ecx
shl    $0x10,%ecx
or     (%rsp),%ecx
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @read_value(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [2 x i32]
%7 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i64 @fread(i32* %8, i32 4, i32 2, i32* %9)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp ult i64 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32*, i32** %4
%15 = call i64 @feof(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %3
br label %29
18: ; preds = %13
store i32 -1, i32* %3
br label %29
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%21 = load i32, i32* %20
%22 = shl i32 %21, 16
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %23
%25 = or i32 %22, %24
%26 = load i32*, i32** %5
store i32 %25, i32* %26
%27 = load i64, i64* %7
%28 = trunc i64 %27 to i32
store i32 %28, i32* %3
br label %29
29: ; preds = %19, %18, %17
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @read_value(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i64 @fread(i32* %5, i32 4, i32 2, i32* %0)
%7 = icmp ult i64 %6, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i64 @feof(i32* %0)
%10 = icmp eq i64 %9, 0
%11 = sext i1 %10 to i32
br label %19
12: ; preds = %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%14 = load i32, i32* %13
%15 = shl i32 %14, 16
%16 = load i32, i32* %5
%17 = or i32 %15, %16
store i32 %17, i32* %1
%18 = trunc i64 %6 to i32
br label %19
19: ; preds = %8, %12
%20 = phi i32 [ %18, %12 ], [ %11, %8 ]
ret i32 %20
}