#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*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned short readushort(FILE *f, int bigendian) {
  unsigned char c1, c2;
  fread(&c1, 1, 1, f);
  fread(&c2, 1, 1, f);
  if (bigendian) {
    return (c1 << 8) + c2;
  } else {
    return (c2 << 8) + c1;
  }
}


x86 assembly (clang, -O0):
<readushort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x16(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmpl   $0x0,-0x14(%rbp)
je     1167 <readushort+0x57>
movzbl -0x15(%rbp),%eax
shl    $0x8,%eax
movzbl -0x16(%rbp),%ecx
add    %ecx,%eax
mov    %ax,-0x2(%rbp)
jmp    1178 <readushort+0x68>
movzbl -0x16(%rbp),%eax
shl    $0x8,%eax
movzbl -0x15(%rbp),%ecx
add    %ecx,%eax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readushort>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x6(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %ebp,%ebp
movzbl 0x6(%rsp),%eax
movzbl 0x7(%rsp),%ecx
mov    %ecx,%edx
cmove  %eax,%edx
cmove  %ecx,%eax
shl    $0x8,%edx
movzbl %al,%eax
or     %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define zeroext i16 @readushort(i32* nocapture %0, i32 %1) {
%3 = alloca i8
%4 = alloca i8
%5 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%6 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%7 = icmp eq i32 %1, 0
%8 = load i8, i8* %4
%9 = load i8, i8* %3
%10 = select i1 %7, i8 %8, i8 %9
%11 = zext i8 %10 to i16
%12 = shl nuw i16 %11, 8
%13 = select i1 %7, i8 %9, i8 %8
%14 = zext i8 %13 to i16
%15 = or i16 %12, %14
ret i16 %15
}