#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 */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned int,
                         int /*<<< orphan*/);
unsigned get_dt_ranges(const char *filename, unsigned offset) {
  unsigned address = ~0;
  FILE *fp = fopen(filename, "rb");
  if (fp) {
    unsigned char buf[4];
    fseek(fp, offset, SEEK_SET);
    if (fread(buf, 1, sizeof buf, fp) == sizeof buf)
      address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
    fclose(fp);
  }
  return address;
}


x86 assembly (clang, -O0):
<get_dt_ranges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11db <get_dt_ranges+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cltq
cmp    $0x4,%rax
jne    11d2 <get_dt_ranges+0x92>
movzbl -0x1c(%rbp),%eax
shl    $0x18,%eax
movzbl -0x1b(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x1a(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x19(%rbp),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dt_ranges>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <get_dt_ranges+0x5d>
mov    %rax,%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    $0xffffffff,%ebp
cmp    $0x4,%eax
jne    1193 <get_dt_ranges+0x53>
mov    0x4(%rsp),%ebp
bswap  %ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11a2 <get_dt_ranges+0x62>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @get_dt_ranges(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [4 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %45
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = load i32, i32* %4
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %13, i32 %14, i32 %15)
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32 @fread(i8* %17, i32 1, i32 4, i32* %18)
%20 = sext i32 %19 to i64
%21 = icmp eq i64 %20, 4
br i1 %21, label %22, label %42
22: ; preds = %12
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 24
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = shl i32 %29, 16
%31 = or i32 %26, %30
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 2
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = shl i32 %34, 8
%36 = or i32 %31, %35
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = shl i32 %39, 0
%41 = or i32 %36, %40
store i32 %41, i32* %5
br label %42
42: ; preds = %22, %12
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %2
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @get_dt_ranges(i8* nocapture %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %33, label %6
6: ; preds = %2
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %4, i32 %1, i32 %8)
%10 = call i32 @fread(i8* %7, i32 1, i32 4, i32* %4)
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %30
12: ; preds = %6
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = shl nuw i32 %14, 24
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl nuw nsw i32 %18, 16
%20 = or i32 %19, %15
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = shl nuw nsw i32 %23, 8
%25 = or i32 %20, %24
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = or i32 %25, %28
br label %30
30: ; preds = %12, %6
%31 = phi i32 [ %29, %12 ], [ -1, %6 ]
%32 = tail call i32 @fclose(i32* %4)
br label %33
33: ; preds = %30, %2
%34 = phi i32 [ %31, %30 ], [ -1, %2 ]
ret i32 %34
}