#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*/ uint32_t;
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ endian_to_host_32(int, int /*<<< orphan*/);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int read(int, int /*<<< orphan*/ *, int);
int read_file_u32(uint32_t *result, int fd, off_t offset, int endian) {
  uint32_t val;
  int r;
  if (lseek(fd, offset, SEEK_SET) == (off_t)-1)
    return 1;
  r = read(fd, &val, 4);
  if (r != 4)
    return 1;
  *result = endian_to_host_32(endian, val);
  return 0;
}


x86 assembly (clang, -O0):
<read_file_u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
jne    1171 <read_file_u32+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <read_file_u32+0x85>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
je     119b <read_file_u32+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <read_file_u32+0x85>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1050 <endian_to_host_32@plt>
mov    %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):
<read_file_u32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %esi,%edi
mov    %rdx,%rsi
mov    %eax,%edx
call   1030 <lseek@plt>
mov    $0x1,%ebx
cmp    $0xffffffffffffffff,%rax
je     1186 <read_file_u32+0x56>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    1186 <read_file_u32+0x56>
mov    0x4(%rsp),%esi
mov    %r15d,%edi
call   1050 <endian_to_host_32@plt>
mov    %eax,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @read_file_u32(i32* %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%12 = load i32, i32* %7
%13 = load i64, i64* %8
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @lseek(i32 %12, i64 %13, i32 %14)
%16 = icmp eq i64 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 1, i32* %5
br label %29
18: ; preds = %4
%19 = load i32, i32* %7
%20 = call i32 @read(i32 %19, i32* %10, i32 4)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %5
br label %29
24: ; preds = %18
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = call i32 @endian_to_host_32(i32 %25, i32 %26)
%28 = load i32*, i32** %6
store i32 %27, i32* %28
store i32 0, i32* %5
br label %29
29: ; preds = %24, %23, %17
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @read_file_u32(i32* nocapture writeonly %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @SEEK_SET
%8 = tail call i64 @lseek(i32 %1, i64 %2, i32 %7)
%9 = icmp eq i64 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = call i32 @read(i32 %1, i32* %5, i32 4)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %5
%15 = tail call i32 @endian_to_host_32(i32 %3, i32 %14)
store i32 %15, i32* %0
br label %16
16: ; preds = %10, %4, %13
%17 = phi i32 [ 0, %13 ], [ 1, %4 ], [ 1, %10 ]
ret i32 %17
}