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

/* Variables and functions */
int /*<<< orphan*/ debug_instr_1(int);
int /*<<< orphan*/ debug_instr_2(int, int /*<<< orphan*/ const);
int /*<<< orphan*/ debug_instr_3(int, int, int);
void write_xdata_memory(uint16_t address, uint16_t count, const uint8_t *buf) {
  int i;
  debug_instr_3(0x90, address >> 8, address);
  for (i = 0; i < count; ++i) {
    debug_instr_2(0x74, buf[i]);
    debug_instr_1(0xF0);
    debug_instr_1(0xA3);
  }
}


x86 assembly (clang, -O0):
<write_xdata_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%esi
sar    $0x8,%esi
mov    -0x4(%rbp),%edx
mov    $0x90,%edi
call   1030 <debug_instr_3@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119f <write_xdata_memory+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    $0x74,%edi
call   1050 <debug_instr_2@plt>
mov    $0xf0,%edi
call   1040 <debug_instr_1@plt>
mov    $0xa3,%edi
call   1040 <debug_instr_1@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <write_xdata_memory+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_xdata_memory>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%edx
mov    %edi,%esi
sar    $0x8,%esi
mov    $0x90,%edi
call   1030 <debug_instr_3@plt>
test   %ebp,%ebp
jle    118b <write_xdata_memory+0x5b>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%esi
mov    $0x74,%edi
call   1050 <debug_instr_2@plt>
mov    $0xf0,%edi
call   1040 <debug_instr_1@plt>
mov    $0xa3,%edi
call   1040 <debug_instr_1@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <write_xdata_memory+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @write_xdata_memory(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32, i32* %4
%9 = ashr i32 %8, 8
%10 = load i32, i32* %4
%11 = call i32 @debug_instr_3(i32 144, i32 %9, i32 %10)
store i32 0, i32* %7
br label %12
12: ; preds = %25, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @debug_instr_2(i32 116, i32 %21)
%23 = call i32 @debug_instr_1(i32 240)
%24 = call i32 @debug_instr_1(i32 163)
br label %25
25: ; preds = %16
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %12
28: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @write_xdata_memory(i32 %0, i32 %1, i32* nocapture %2) {
%4 = ashr i32 %0, 8
%5 = tail call i32 @debug_instr_3(i32 144, i32 %4, i32 %0)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %16, %9 ]
%11 = getelementptr inbounds i32, i32* %2, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @debug_instr_2(i32 116, i32 %12)
%14 = tail call i32 @debug_instr_1(i32 240)
%15 = tail call i32 @debug_instr_1(i32 163)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %3
ret void
}