#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 */
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int get_word(FILE *fp) {
  unsigned char temp[4];
  size_t r = fread(temp, 1, 4, fp);
  if (r != 4)
    return -1;
  return (int)temp[0] << 24 | temp[1] << 16 | temp[2] << 8 | temp[3];
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
je     114e <get_word+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <get_word+0x60>
movzbl -0x14(%rbp),%eax
shl    $0x18,%eax
movzbl -0x13(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x12(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x11(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %rax
mov    %rdi,%rcx
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
cmp    $0x4,%rcx
jne    113c <get_word+0x2c>
mov    0x4(%rsp),%eax
bswap  %eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @get_word(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i64
store i32* %0, i32** %3
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i64 @fread(i8* %6, i32 1, i32 4, i32* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %31
12: ; preds = %1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = shl i32 %15, 24
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = shl i32 %19, 16
%21 = or i32 %16, %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl i32 %24, 8
%26 = or i32 %21, %25
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = or i32 %26, %29
store i32 %30, i32* %2
br label %31
31: ; preds = %12, %11
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @get_word(i32* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i64 @fread(i8* %3, i32 1, i32 4, i32* %0)
%5 = icmp eq i64 %4, 4
br i1 %5, label %6, label %24
6: ; preds = %1
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = shl nuw i32 %8, 24
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl nuw nsw i32 %12, 16
%14 = or i32 %13, %9
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = or i32 %14, %18
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = or i32 %19, %22
br label %24
24: ; preds = %1, %6
%25 = phi i32 [ %23, %6 ], [ -1, %1 ]
ret i32 %25
}