#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*/ _dbg(char *);
int board_flash_get_datafs_size();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
char *board_flash_read_datafs(char *buf, int buf_size) {
  int size = board_flash_get_datafs_size();
  FILE *file = NULL;
  if (buf_size > size)
    if (0)
      _dbg("warn: buf_size > size");
  file = fopen("/dev/mtdblock/4", "r");
  if (!file) {
    perror(NULL);
    return NULL;
  }
  fread(buf, size, 1, file);
  fclose(file);
  return buf;
}


x86 assembly (clang, -O0):
<board_flash_read_datafs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1070 <board_flash_get_datafs_size@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1182 <board_flash_read_datafs+0x32>
jmp    1182 <board_flash_read_datafs+0x32>
lea    0xe77(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ba <board_flash_read_datafs+0x6a>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <board_flash_read_datafs+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<board_flash_read_datafs>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <board_flash_get_datafs_size@plt>
mov    %eax,%ebp
lea    0xe99(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119d <board_flash_read_datafs+0x4d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <perror@plt>
jmp    1195 <board_flash_read_datafs+0x45>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/mtdblock/4\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @board_flash_read_datafs(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 (...) @board_flash_get_datafs_size()
store i32 %8, i32* %6
store i32* null, i32** %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = icmp sgt i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
br label %13
13: ; preds = %12, %2
%14 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @perror(i32* null)
store i8* null, i8** %3
br label %27
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = load i32*, i32** %7
%23 = call i32 @fread(i8* %20, i32 %21, i32 1, i32* %22)
%24 = load i32*, i32** %7
%25 = call i32 @fclose(i32* %24)
%26 = load i8*, i8** %4
store i8* %26, i8** %3
br label %27
27: ; preds = %19, %17
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/mtdblock/4\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @board_flash_read_datafs(i8* %0, i32 %1) {
%3 = tail call i32 (...) @board_flash_get_datafs_size()
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i32* null)
br label %11
8: ; preds = %2
%9 = tail call i32 @fread(i8* %0, i32 %3, i32 1, i32* %4)
%10 = tail call i32 @fclose(i32* %4)
br label %11
11: ; preds = %8, %6
%12 = phi i8* [ %0, %8 ], [ null, %6 ]
ret i8* %12
}