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

/* Variables and functions */
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
void writeData(FILE *file, unsigned short *data, unsigned long size) {
  while (size > 0) {
    putc((int)(*data & 0xFF), file);
    putc((int)((*data >> 8) & 0xFF), file);
    ++data;
    --size;
  }
}


x86 assembly (clang, -O0):
<writeData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    117b <writeData+0x6b>
mov    -0x10(%rbp),%rax
movzwl (%rax),%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rax
movzwl (%rax),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <writeData+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1154 <writeData+0x44>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,2),%edi
mov    %r12,%rsi
call   1030 <putc@plt>
movzbl 0x1(%r15,%rbx,2),%edi
mov    %r12,%rsi
call   1030 <putc@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <writeData+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @writeData(i32* nocapture %0, i16* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %17, %5 ], [ %2, %3 ]
%7 = phi i16* [ %16, %5 ], [ %1, %3 ]
%8 = load i16, i16* %7
%9 = and i16 %8, 255
%10 = zext i16 %9 to i32
%11 = tail call i32 @putc(i32 %10, i32* %0)
%12 = load i16, i16* %7
%13 = lshr i16 %12, 8
%14 = zext i16 %13 to i32
%15 = tail call i32 @putc(i32 %14, i32* %0)
%16 = getelementptr inbounds i16, i16* %7, i64 1
%17 = add i64 %6, -1
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %5, %3
ret void
}