#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 */
scalar_t__ write_block(unsigned char const *, unsigned int, unsigned int);
void write_blocks(const unsigned char *data, unsigned length,
                  unsigned address) {
  for (unsigned offset = 0; offset < length;
       offset += write_block(data + offset, length - offset, address + offset))
    ;
}


x86 assembly (clang, -O0):
<write_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1166 <write_blocks+0x56>
jmp    113a <write_blocks+0x2a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
add    -0x14(%rbp),%edx
call   1030 <write_block@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1129 <write_blocks+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_blocks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     114a <write_blocks+0x3a>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
add    %r15,%rdi
mov    %ebp,%esi
sub    %ebx,%esi
lea    (%rbx,%r14,1),%edx
call   1030 <write_block@plt>
add    %ebx,%eax
mov    %eax,%ebx
cmp    %ebp,%eax
jb     1130 <write_blocks+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @write_blocks(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %13, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
br label %13
13: ; preds = %12
%14 = load i8*, i8** %4
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = sub i32 %18, %19
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = add i32 %21, %22
%24 = call i64 @write_block(i8* %17, i32 %20, i32 %23)
%25 = load i32, i32* %7
%26 = zext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
br label %8
29: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @write_blocks(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %6
5: ; preds = %6, %3
ret void
6: ; preds = %3, %6
%7 = phi i32 [ %14, %6 ], [ 0, %3 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = sub i32 %1, %7
%11 = add i32 %7, %2
%12 = tail call i64 @write_block(i8* %9, i32 %10, i32 %11)
%13 = trunc i64 %12 to i32
%14 = add i32 %7, %13
%15 = icmp ult i32 %14, %1
br i1 %15, label %6, label %5
}