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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int show_gpio_base(void) {
  FILE *fp = NULL;
  unsigned char buf[4];
  memset(buf, 0x00, sizeof(buf));
  fp = fopen("/proc/device-tree/soc/ranges", "rb");
  if (fp != NULL) {
    fseek(fp, 4, SEEK_SET);
    if (fread(buf, 1, sizeof(buf), fp) == sizeof(buf)) {
      printf("Base Address    : %02x%02x%02x%02x\n", buf[0], buf[1], buf[2],
             buf[3]);
    }
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<show_gpio_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0xe79(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1208 <show_gpio_base+0xa8>
mov    -0x8(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <fseek@plt>
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cltq
cmp    $0x4,%rax
jne    11ff <show_gpio_base+0x9f>
mov    -0xc(%rbp),%dl
mov    -0xb(%rbp),%cl
mov    -0xa(%rbp),%al
lea    0xe34(%rip),%rdi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
movzbl -0x9(%rbp),%r8d
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_gpio_base>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0xe83(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ec <show_gpio_base+0x8c>
mov    %rax,%rbx
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    11e4 <show_gpio_base+0x84>
movzbl 0xc(%rsp),%esi
movzbl 0xd(%rsp),%edx
movzbl 0xe(%rsp),%ecx
movzbl 0xf(%rsp),%r8d
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/proc/device-tree/soc/ranges\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.2 = [36 x i8] c"Base Address : %02x%02x%02x%02x\0A\00"
define i32 @show_gpio_base() {
%1 = alloca i32*
%2 = alloca [4 x i8]
store i32* null, i32** %1
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 4)
%5 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %30
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %9, i32 4, i32 %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i32 @fread(i8* %12, i32 1, i32 4, i32* %13)
%15 = sext i32 %14 to i64
%16 = icmp eq i64 %15, 4
br i1 %16, label %17, label %27
17: ; preds = %8
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%19 = load i8, i8* %18
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%23 = load i8, i8* %22
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%25 = load i8, i8* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %19, i8 zeroext %21, i8 zeroext %23, i8 zeroext %25)
br label %27
27: ; preds = %17, %8
%28 = load i32*, i32** %1
%29 = call i32 @fclose(i32* %28)
br label %30
30: ; preds = %27, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"/proc/device-tree/soc/ranges\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@.str.2 = [36 x i8] c"Base Address : %02x%02x%02x%02x\0A\00"
define i32 @show_gpio_base() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 4)
%4 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @fseek(i32* %4, i32 4, i32 %7)
%9 = call i32 @fread(i8* %2, i32 1, i32 4, i32* %4)
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i8, i8* %2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%14 = load i8, i8* %13
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
%16 = load i8, i8* %15
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %12, i8 zeroext %14, i8 zeroext %16, i8 zeroext %18)
br label %20
20: ; preds = %11, %6
%21 = call i32 @fclose(i32* %4)
br label %22
22: ; preds = %20, %0
ret i32 0
}