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


x86 assembly (clang, -O0):
<read32>:
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    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <read32+0x84>
mov    -0x14(%rbp),%eax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <read32+0x84>
mov    -0x10(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <read32+0x84>
mov    -0xc(%rbp),%eax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%eax
jne    11e3 <read32+0xa3>
lea    0xe35(%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    $0x18,%eax
mov    -0x10(%rbp),%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x14(%rbp),%ecx
movzbl %cl,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
movzbl %cl,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e73(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%ebp
je     11ae <read32+0x6e>
cmp    %ecx,%r15d
je     11ae <read32+0x6e>
cmp    %ecx,%eax
je     11ae <read32+0x6e>
cmp    %ecx,%ebx
je     11ae <read32+0x6e>
shl    $0x18,%ebp
movzbl %r15b,%ecx
shl    $0x10,%ecx
or     %ebp,%ecx
shl    $0x8,%ebx
movzwl %bx,%edx
or     %ecx,%edx
movzbl %al,%eax
or     %edx,%eax
cltq
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [41 x i8] c"Read32 reached end of file unexpectedly\0A\00"
define i64 @read32(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %3
%10 = load i32*, i32** %2
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %4
%12 = load i32*, i32** %2
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %5
%14 = load i32*, i32** %2
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %31, label %19
19: ; preds = %1
%20 = load i32, i32* %5
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i32, i32* %3
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %27, %23, %19, %1
%32 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %27
%37 = load i32, i32* %3
%38 = trunc i32 %37 to i8
%39 = zext i8 %38 to i32
%40 = shl i32 %39, 24
%41 = load i32, i32* %4
%42 = trunc i32 %41 to i8
%43 = zext i8 %42 to i32
%44 = shl i32 %43, 16
%45 = or i32 %40, %44
%46 = load i32, i32* %5
%47 = trunc i32 %46 to i8
%48 = zext i8 %47 to i32
%49 = shl i32 %48, 8
%50 = or i32 %45, %49
%51 = load i32, i32* %6
%52 = trunc i32 %51 to i8
%53 = zext i8 %52 to i32
%54 = or i32 %50, %53
%55 = sext i32 %54 to i64
store i64 %55, i64* %7
%56 = load i64, i64* %7
ret i64 %56
}

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