#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
unsigned long read16(FILE *fp) {
  int ch1 = fgetc(fp);
  int ch0 = fgetc(fp);
  if (ch0 == EOF || ch1 == EOF) {
    printf("Read16 reached end of file unexpectedly\n");
    fclose(fp);
    exit(2);
  }
  unsigned long dat = (unsigned char)ch1 << 8 | (unsigned char)ch0;
  return dat;
}


x86 assembly (clang, -O0):
<read16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
je     1188 <read16+0x48>
mov    -0xc(%rbp),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
jne    11a7 <read16+0x67>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
movzbl %al,%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%ecx
movzbl %cl,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read16>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%eax
je     1178 <read16+0x38>
cmp    %ecx,%ebp
je     1178 <read16+0x38>
shl    $0x8,%ebp
movzwl %bp,%ecx
movzbl %al,%eax
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [41 x i8] c"Read16 reached end of file unexpectedly\0A\00"
define i64 @read16(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %3
%8 = load i32*, i32** %2
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13, %1
%18 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %13
%23 = load i32, i32* %3
%24 = trunc i32 %23 to i8
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 8
%27 = load i32, i32* %4
%28 = trunc i32 %27 to i8
%29 = zext i8 %28 to i32
%30 = or i32 %26, %29
%31 = sext i32 %30 to i64
store i64 %31, i64* %5
%32 = load i64, i64* %5
ret i64 %32
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [40 x i8] c"Read16 reached end of file unexpectedly\00"
define i64 @read16(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
%6 = icmp eq i32 %2, %4
%7 = or i1 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %0)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %1
%13 = shl i32 %2, 8
%14 = and i32 %13, 65280
%15 = and i32 %3, 255
%16 = or i32 %14, %15
%17 = zext i32 %16 to i64
ret i64 %17
}