#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 scalar_t__ uint8_t;
typedef unsigned int uint32_t;
typedef int /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int fread_le32(uint32_t *buf, FILE *fd) {
  size_t count;
  uint8_t tmp[4];
  unsigned int i;
  if (fread(tmp, sizeof(tmp), 1, fd) != 1)
    return -1;
  *buf = 0;
  for (i = 0; i < (sizeof(tmp) / sizeof((tmp)[0])); i++)
    *buf |= (uint32_t)(tmp[i]) << (i * 8);
  return 0;
}


x86 assembly (clang, -O0):
<fread_le32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x20,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     114c <fread_le32+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <fread_le32+0x89>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    $0x4,%rax
jae    1192 <fread_le32+0x82>
mov    -0x44(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rax
mov    -0x44(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    115d <fread_le32+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_le32>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rcx
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    1159 <fread_le32+0x49>
mov    0x8(%rsp),%eax
shl    $0x8,%eax
or     (%rsp),%eax
mov    0x10(%rsp),%ecx
shl    $0x10,%ecx
mov    0x18(%rsp),%edx
shl    $0x18,%edx
or     %ecx,%edx
or     %eax,%edx
mov    %edx,(%rbx)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

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