#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sync();
int write(int, char *, int);
int flash_write(char *buf, int offset, int len) {
  int fh;
  int ok = 1;
  fh = open(("setting.bin"), O_RDWR);
  if (fh == -1)
    return 0;
  lseek(fh, offset, SEEK_SET);
  if (write(fh, buf, len) != len)
    ok = 0;
  close(fh);
  sync();
  return ok;
}


x86 assembly (clang, -O0):
<flash_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1197 <flash_write+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11df <flash_write+0x8f>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
cmp    -0x18(%rbp),%eax
je     11ca <flash_write+0x7a>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    $0x0,%al
call   1060 <sync@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11b2 <flash_write+0x62>
mov    %eax,%ebp
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <lseek@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
cmp    %r15d,%eax
sete   %bl
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
call   1060 <sync@plt>
jmp    11b4 <flash_write+0x64>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"setting.bin\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
define i32 @flash_write(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 1, i32* %9
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %32
15: ; preds = %3
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @lseek(i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %8
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %7
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 0, i32* %9
br label %27
27: ; preds = %26, %15
%28 = load i32, i32* %8
%29 = call i32 @close(i32 %28)
%30 = call i32 (...) @sync()
%31 = load i32, i32* %9
store i32 %31, i32* %4
br label %32
32: ; preds = %27, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [12 x i8] c"setting.bin\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
define i32 @flash_write(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %5, i32 %1, i32 %8)
%10 = tail call i32 @write(i32 %5, i8* %0, i32 %2)
%11 = icmp eq i32 %10, %2
%12 = zext i1 %11 to i32
%13 = tail call i32 @close(i32 %5)
%14 = tail call i32 (...) @sync()
br label %15
15: ; preds = %3, %7
%16 = phi i32 [ %12, %7 ], [ 0, %3 ]
ret i32 %16
}