#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 */

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ _dbg(char *, ...);
int /*<<< orphan*/ close(int);
int open(char *, int);
size_t write(int, char *, int);
int board_flash_write_datafs(char *buf, int buf_size) {
  int fd = open("/dev/mtdblock/4", O_WRONLY | O_CREAT);
  if (fd == -1) {
    if (0)
      _dbg("error: file does not exist\n");
    return 0;
  }
  size_t written = write(fd, buf, buf_size);
  if (0)
    _dbg("written %d bytes\n", written);
  close(fd);
}


x86 assembly (clang, -O0):
<board_flash_write_datafs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2ea9(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1176 <board_flash_write_datafs+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1191 <board_flash_write_datafs+0x61>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<board_flash_write_datafs>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e8f(%rip),%rax
mov    0x2eb0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xead(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1173 <board_flash_write_datafs+0x43>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/mtdblock/4\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @board_flash_write_datafs(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %22
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = call i64 @write(i32 %16, i8* %17, i32 %18)
store i64 %19, i64* %7
%20 = load i32, i32* %6
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %15, %14
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/mtdblock/4\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @board_flash_write_datafs(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i64 @write(i32 %6, i8* %0, i32 %1)
%10 = tail call i32 @close(i32 %6)
br label %11
11: ; preds = %2, %8
ret i32 0
}