#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 short *, int, int, int /*<<< orphan*/ *);
int ReadUShort(FILE *fptr, short unsigned *n, int swap) {
  unsigned char *cptr, tmp;
  if (fread(n, 2, 1, fptr) != 1)
    return (0);
  if (swap) {
    cptr = (unsigned char *)n;
    tmp = cptr[0];
    cptr[0] = cptr[1];
    cptr[1] = tmp;
  }
  return (1);
}


x86 assembly (clang, -O0):
<ReadUShort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     114f <ReadUShort+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1188 <ReadUShort+0x78>
cmpl   $0x0,-0x1c(%rbp)
je     1181 <ReadUShort+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadUShort>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    %rsi,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1143 <ReadUShort+0x33>
test   %ebp,%ebp
je     113e <ReadUShort+0x2e>
rolw   $0x8,(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ReadUShort(i32* nocapture %0, i16* nocapture %1, i32 %2) {
%4 = tail call i32 @fread(i16* %1, i32 2, i32 1, i32* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %13, label %8
8: ; preds = %6
%9 = bitcast i16* %1 to i8*
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = load i8, i8* %11
store i8 %12, i8* %9
store i8 %10, i8* %11
br label %13
13: ; preds = %6, %8, %3
%14 = phi i32 [ 0, %3 ], [ 1, %8 ], [ 1, %6 ]
ret i32 %14
}