#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 EOF;
scalar_t__ IO_ConvertSigned(int);
int /*<<< orphan*/ assert(int);
int fgetc(int /*<<< orphan*/ *);
int IO_Read_BE_WORD(short *buffer, FILE *fp) {
  int c1, c2;
  assert(buffer && fp);
  if (((c1 = fgetc(fp)) == EOF) || ((c2 = fgetc(fp)) == EOF)) {
    return 0;
  } else {
    short b1 = (short)(IO_ConvertSigned(c1));
    short b2 = ((short)(c2)) & 0xFF;
    *buffer = (b1 << 8) | b2;
    return 1;
  }
}


x86 assembly (clang, -O0):
<IO_Read_BE_WORD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x25(%rbp)
je     115b <IO_Read_BE_WORD+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     119e <IO_Read_BE_WORD+0x6e>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
jne    11aa <IO_Read_BE_WORD+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11e1 <IO_Read_BE_WORD+0xb1>
mov    -0x1c(%rbp),%edi
call   1050 <IO_ConvertSigned@plt>
mov    %ax,-0x22(%rbp)
mov    -0x20(%rbp),%eax
cwtl
and    $0xff,%eax
mov    %ax,-0x24(%rbp)
movswl -0x22(%rbp),%eax
shl    $0x8,%eax
movswl -0x24(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IO_Read_BE_WORD>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2e85(%rip),%r12
xor    %r15d,%r15d
cmp    (%r12),%eax
je     1197 <IO_Read_BE_WORD+0x67>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1197 <IO_Read_BE_WORD+0x67>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <IO_ConvertSigned@plt>
movzbl %bl,%ecx
shl    $0x8,%eax
or     %ecx,%eax
mov    %ax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @IO_Read_BE_WORD(i16* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i16
store i16* %0, i16** %4
store i32* %1, i32** %5
%10 = load i16*, i16** %4
%11 = icmp ne i16* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br label %15
15: ; preds = %12, %2
%16 = phi i1 [ false, %2 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %5
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %6
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %28, label %23
23: ; preds = %15
%24 = load i32*, i32** %5
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %7
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23, %15
store i32 0, i32* %3
br label %46
29: ; preds = %23
%30 = load i32, i32* %6
%31 = call i64 @IO_ConvertSigned(i32 %30)
%32 = trunc i64 %31 to i16
store i16 %32, i16* %8
%33 = load i32, i32* %7
%34 = trunc i32 %33 to i16
%35 = sext i16 %34 to i32
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i16
store i16 %37, i16* %9
%38 = load i16, i16* %8
%39 = sext i16 %38 to i32
%40 = shl i32 %39, 8
%41 = load i16, i16* %9
%42 = sext i16 %41 to i32
%43 = or i32 %40, %42
%44 = trunc i32 %43 to i16
%45 = load i16*, i16** %4
store i16 %44, i16* %45
store i32 1, i32* %3
br label %46
46: ; preds = %29, %28
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @IO_Read_BE_WORD(i16* writeonly %0, i32* %1) {
%3 = icmp ne i16* %0, null
%4 = icmp ne i32* %1, null
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @fgetc(i32* %1)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = tail call i32 @fgetc(i32* %1)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = tail call i64 @IO_ConvertSigned(i32 %8)
%17 = trunc i64 %16 to i32
%18 = and i32 %12, 255
%19 = shl i32 %17, 8
%20 = or i32 %19, %18
%21 = trunc i32 %20 to i16
store i16 %21, i16* %0
br label %22
22: ; preds = %2, %11, %15
%23 = phi i32 [ 1, %15 ], [ 0, %11 ], [ 0, %2 ]
ret i32 %23
}