#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*/ assert(int);
int /*<<< orphan*/ fread_err(unsigned char *, int, int, int /*<<< orphan*/ *);
void ReadWORDBE(FILE *inf, unsigned short *ptr) {
  unsigned char buffer[2] = {0};
  (assert((inf != NULL) && (ptr != NULL)));
  fread_err(buffer, 2, 1, inf);
  *ptr = (unsigned short)((buffer[0] << 8) | buffer[1]);
}


x86 assembly (clang, -O0):
<ReadWORDBE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <memset@plt>
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x13(%rbp)
je     116b <ReadWORDBE+0x3b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <fread_err@plt>
movzbl -0x12(%rbp),%eax
shl    $0x8,%eax
movzbl -0x11(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadWORDBE>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movw   $0x0,0x6(%rsp)
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
movzwl 0x6(%rsp),%eax
rol    $0x8,%ax
mov    %ax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @ReadWORDBE(i32* %0, i16* %1) {
%3 = alloca i32*
%4 = alloca i16*
%5 = alloca [2 x i8]
store i32* %0, i32** %3
store i16* %1, i16** %4
%6 = bitcast [2 x i8]* %5 to i8*
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i16*, i16** %4
%11 = icmp ne i16* %10, null
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ false, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32 @fread_err(i8* %16, i32 2, i32 1, i32* %17)
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl i32 %21, 8
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = or i32 %22, %25
%27 = trunc i32 %26 to i16
%28 = load i16*, i16** %4
store i16 %27, i16* %28
ret void
}

LLVM IR (-O2):
define void @ReadWORDBE(i32* %0, i16* writeonly %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to [2 x i8]*
%5 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%6 = icmp ne i32* %0, null
%7 = icmp ne i16* %1, null
%8 = and i1 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = call i32 @fread_err(i8* %5, i32 2, i32 1, i32* %0)
%12 = load i8, i8* %5
%13 = zext i8 %12 to i16
%14 = shl nuw i16 %13, 8
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i16
%18 = or i16 %14, %17
store i16 %18, i16* %1
ret void
}