#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 uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int read2b(FILE *fp, uint16_t *d) {
  int c;
  *d = 0;
  c = fgetc(fp);
  if (c == EOF)
    return -1;
  *d += (uint16_t)c;
  c = fgetc(fp);
  if (c == EOF)
    return -1;
  *d += (uint16_t)c << 8;
  return 0;
}


x86 assembly (clang, -O0):
<read2b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2ea8(%rip),%rcx
cmp    (%rcx),%eax
jne    1154 <read2b+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    119e <read2b+0x8e>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
jne    1189 <read2b+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    119e <read2b+0x8e>
mov    -0x1c(%rbp),%ecx
shl    $0x8,%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read2b>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
movl   $0x0,(%rsi)
call   1030 <fgetc@plt>
mov    0x2eb9(%rip),%r15
mov    $0xffffffff,%r14d
cmp    (%r15),%eax
je     1151 <read2b+0x41>
add    %eax,(%rbx)
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
je     1151 <read2b+0x41>
shl    $0x8,%eax
add    %eax,(%rbx)
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @read2b(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
store i32 0, i32* %7
%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 -1, i32* %3
br label %31
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = add nsw i32 %17, %15
store i32 %18, i32* %16
%19 = load i32*, i32** %4
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 -1, i32* %3
br label %31
25: ; preds = %14
%26 = load i32, i32* %6
%27 = shl i32 %26, 8
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = add nsw i32 %29, %27
store i32 %30, i32* %28
store i32 0, i32* %3
br label %31
31: ; preds = %25, %24, %13
%32 = load i32, i32* %3
ret i32 %32
}

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