#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 fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int ReadUSHORT(unsigned short *x, FILE *f) {
  unsigned char little[2];
  if (x == NULL || f == NULL) {
    return 0;
  }
  if (fread(little, 2, 1, f) != 1) {
    return 0;
  }
  *x = (little[1] << 8 | little[0]);
  return 1;
}


x86 assembly (clang, -O0):
<ReadUSHORT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <ReadUSHORT+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <ReadUSHORT+0x32>
movl   $0x0,-0x4(%rbp)
jmp    118c <ReadUSHORT+0x7c>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     116e <ReadUSHORT+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    118c <ReadUSHORT+0x7c>
movzbl -0x19(%rbp),%eax
shl    $0x8,%eax
movzbl -0x1a(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadUSHORT>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     114b <ReadUSHORT+0x3b>
mov    %rsi,%rcx
test   %rsi,%rsi
je     114b <ReadUSHORT+0x3b>
mov    %rdi,%rbx
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    114b <ReadUSHORT+0x3b>
movzwl 0x6(%rsp),%eax
mov    %ax,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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