#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;
int fgetc(int /*<<< orphan*/ *);
bool readInt16BE(FILE *file, int *value) {
  int r1 = fgetc(file);
  if (r1 == EOF)
    return false;
  int r2 = fgetc(file);
  if (r2 == EOF)
    return false;
  *value = (r1 << 8) + r2;
  return true;
}


x86 assembly (clang, -O0):
<readInt16BE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2eb2(%rip),%rcx
cmp    (%rcx),%eax
jne    114a <readInt16BE+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    118a <readInt16BE+0x7a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
jne    1174 <readInt16BE+0x64>
movl   $0x0,-0x4(%rbp)
jmp    118a <readInt16BE+0x7a>
mov    -0x1c(%rbp),%ecx
shl    $0x8,%ecx
add    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInt16BE>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
call   1030 <fgetc@plt>
mov    0x2ebe(%rip),%r12
xor    %r15d,%r15d
cmp    (%r12),%eax
je     1151 <readInt16BE+0x41>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1151 <readInt16BE+0x41>
shl    $0x8,%ebx
add    %ebx,%eax
mov    %eax,(%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 @readInt16BE(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %27
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 0, i32* %3
br label %27
21: ; preds = %14
%22 = load i32, i32* %6
%23 = shl i32 %22, 8
%24 = load i32, i32* %7
%25 = add nsw i32 %23, %24
%26 = load i32*, i32** %5
store i32 %25, i32* %26
store i32 1, i32* %3
br label %27
27: ; preds = %21, %20, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @readInt16BE(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = shl i32 %3, 8
%12 = add nsw i32 %7, %11
store i32 %12, i32* %1
br label %13
13: ; preds = %10, %6, %2
%14 = phi i32 [ 0, %2 ], [ 1, %10 ], [ 0, %6 ]
ret i32 %14
}