#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 readWord(FILE *fp, unsigned short *result) {
  unsigned char b1, b2;
  if (fread(&b1, 1, 1, fp) != 1)
    return (-1);
  if (fread(&b2, 1, 1, fp) != 1)
    return (-1);
  *result = (((unsigned short)b2) << 8) + b1;
  return (0);
}


x86 assembly (clang, -O0):
<readWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1149 <readWord+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <readWord+0x83>
mov    -0x10(%rbp),%rcx
lea    -0x1a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1172 <readWord+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <readWord+0x83>
movzbl -0x1a(%rbp),%eax
movzwl %ax,%eax
shl    $0x8,%eax
movzbl -0x19(%rbp),%ecx
add    %ecx,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWord>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%eax
jne    1170 <readWord+0x60>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1170 <readWord+0x60>
movzbl 0xe(%rsp),%eax
shl    $0x8,%eax
movzbl 0xf(%rsp),%ecx
or     %eax,%ecx
mov    %cx,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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