#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 */
scalar_t__ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
unsigned int read_dword(FILE *f) {
  unsigned char atom_size_b[4];
  if (fread(&atom_size_b, 4, 1, f) <= 0)
    return -1;
  return (atom_size_b[0] << 24) | (atom_size_b[1] << 16) |
         (atom_size_b[2] << 8) | atom_size_b[3];
}


x86 assembly (clang, -O0):
<read_dword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jg     1149 <read_dword+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    116b <read_dword+0x5b>
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):
<read_dword>:
push   %rax
mov    %rdi,%rcx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %rax,%rax
jle    1135 <read_dword+0x25>
mov    0x4(%rsp),%eax
bswap  %eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

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

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