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

/* Variables and functions */
int fread(int *, int, int, int /*<<< orphan*/ *);
int fread_le_uint32(uint32_t *value, FILE *stream) {
  uint8_t buffer[4];
  if (value == NULL)
    return -1;
  if (fread(buffer, 1, 4, stream) != 4)
    return -1;
  *value = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
  return 0;
}


x86 assembly (clang, -O0):
<fread_le_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <fread_le_uint32+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <fread_le_uint32+0x7b>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     1163 <fread_le_uint32+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <fread_le_uint32+0x7b>
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x28(%rbp),%eax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x18,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_le_uint32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     115d <fread_le_uint32+0x4d>
mov    %rsi,%rcx
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    115d <fread_le_uint32+0x4d>
mov    0x4(%rsp),%eax
shl    $0x8,%eax
or     (%rsp),%eax
mov    0x8(%rsp),%ecx
shl    $0x10,%ecx
mov    0xc(%rsp),%edx
shl    $0x18,%edx
or     %ecx,%edx
or     %eax,%edx
mov    %edx,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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