#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 size_t uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ c2_addr_write(int);
int /*<<< orphan*/ check_status();
int /*<<< orphan*/ fpdat_write(size_t);
void flash_block_write(uint16_t addr, const void *data, size_t size) {
  int i;
  if (!size)
    return;
  c2_addr_write(0xb4);
  fpdat_write(0x07);
  check_status();
  fpdat_write(addr >> 8);
  fpdat_write(addr);
  fpdat_write(size);
  check_status();
  for (i = 0; i != size; i++)
    fpdat_write(((uint8_t *)data)[i]);
}


x86 assembly (clang, -O0):
<flash_block_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1153 <flash_block_write+0x23>
jmp    11c9 <flash_block_write+0x99>
mov    $0xb4,%edi
call   1040 <c2_addr_write@plt>
mov    $0x7,%edi
call   1050 <fpdat_write@plt>
mov    $0x0,%al
call   1030 <check_status@plt>
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
movslq %eax,%rdi
call   1050 <fpdat_write@plt>
movslq -0x4(%rbp),%rdi
call   1050 <fpdat_write@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fpdat_write@plt>
mov    $0x0,%al
call   1030 <check_status@plt>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11c9 <flash_block_write+0x99>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <fpdat_write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <flash_block_write+0x6c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_block_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     11a2 <flash_block_write+0x72>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0xb4,%edi
call   1040 <c2_addr_write@plt>
mov    $0x7,%edi
call   1050 <fpdat_write@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <check_status@plt>
mov    %r15d,%eax
sar    $0x8,%eax
movslq %eax,%rdi
call   1050 <fpdat_write@plt>
movslq %r15d,%rdi
call   1050 <fpdat_write@plt>
mov    %rbx,%rdi
call   1050 <fpdat_write@plt>
xor    %eax,%eax
call   1030 <check_status@plt>
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rdi
call   1050 <fpdat_write@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1190 <flash_block_write+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @flash_block_write(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp ne i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %3
br label %41
11: ; preds = %3
%12 = call i32 @c2_addr_write(i32 180)
%13 = call i32 @fpdat_write(i64 7)
%14 = call i32 (...) @check_status()
%15 = load i32, i32* %4
%16 = ashr i32 %15, 8
%17 = sext i32 %16 to i64
%18 = call i32 @fpdat_write(i64 %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = call i32 @fpdat_write(i64 %20)
%22 = load i64, i64* %6
%23 = call i32 @fpdat_write(i64 %22)
%24 = call i32 (...) @check_status()
store i32 0, i32* %7
br label %25
25: ; preds = %38, %11
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = load i64, i64* %6
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %41
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = bitcast i8* %31 to i64*
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %32, i64 %34
%36 = load i64, i64* %35
%37 = call i32 @fpdat_write(i64 %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %25
41: ; preds = %10, %25
ret void
}

LLVM IR (-O2):
define void @flash_block_write(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3
%6 = tail call i32 @c2_addr_write(i32 180)
%7 = tail call i32 @fpdat_write(i64 7)
%8 = tail call i32 (...) @check_status()
%9 = ashr i32 %0, 8
%10 = sext i32 %9 to i64
%11 = tail call i32 @fpdat_write(i64 %10)
%12 = sext i32 %0 to i64
%13 = tail call i32 @fpdat_write(i64 %12)
%14 = tail call i32 @fpdat_write(i64 %2)
%15 = tail call i32 (...) @check_status()
%16 = bitcast i8* %1 to i64*
br label %17
17: ; preds = %5, %17
%18 = phi i64 [ 0, %5 ], [ %22, %17 ]
%19 = getelementptr inbounds i64, i64* %16, i64 %18
%20 = load i64, i64* %19
%21 = tail call i32 @fpdat_write(i64 %20)
%22 = add nuw i64 %18, 1
%23 = icmp eq i64 %22, %2
br i1 %23, label %24, label %17
24: ; preds = %17, %3
ret void
}