#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*/ dbg_write(unsigned long);
void dbg_write_u16(const unsigned short *val, long len) {
  unsigned long dcc_data;
  dbg_write((0x01 | ((2 & 0xff) << 8)) | ((len & 0xffff) << 16));
  while (len > 0) {
    dcc_data = val[0] | ((len > 1) ? val[1] << 16 : 0x0000);
    dbg_write(dcc_data);
    val += 2;
    len -= 2;
  }
}


x86 assembly (clang, -O0):
<dbg_write_u16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
and    $0xffff,%rdi
shl    $0x10,%rdi
or     $0x201,%rdi
call   1030 <dbg_write@plt>
cmpq   $0x0,-0x10(%rbp)
jle    11ac <dbg_write_u16+0x9c>
mov    -0x8(%rbp),%rax
movzwl (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x1,-0x10(%rbp)
jle    116e <dbg_write_u16+0x5e>
mov    -0x8(%rbp),%rax
movzwl 0x2(%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <dbg_write_u16+0x68>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <dbg_write_u16+0x68>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <dbg_write@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    113b <dbg_write_u16+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_write_u16>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %ebx,%edi
shl    $0x10,%edi
or     $0x201,%rdi
call   1030 <dbg_write@plt>
test   %rbx,%rbx
jle    116f <dbg_write_u16+0x5f>
add    $0x2,%r14
add    $0x2,%rbx
jmp    115e <dbg_write_u16+0x4e>
nopw   0x0(%rax,%rax,1)
movzwl -0x2(%r14),%ecx
movslq %eax,%rdi
or     %rcx,%rdi
call   1030 <dbg_write@plt>
add    $0x4,%r14
add    $0xfffffffffffffffe,%rbx
cmp    $0x2,%rbx
jbe    116f <dbg_write_u16+0x5f>
xor    %eax,%eax
cmp    $0x3,%rbx
je     1140 <dbg_write_u16+0x30>
movzwl (%r14),%eax
shl    $0x10,%eax
jmp    1140 <dbg_write_u16+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @dbg_write_u16(i16* %0, i64 %1) {
%3 = alloca i16*
%4 = alloca i64
%5 = alloca i64
store i16* %0, i16** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = and i64 %6, 65535
%8 = shl i64 %7, 16
%9 = or i64 513, %8
%10 = call i32 @dbg_write(i64 %9)
br label %11
11: ; preds = %28, %2
%12 = load i64, i64* %4
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = load i16*, i16** %3
%16 = getelementptr inbounds i16, i16* %15, i64 0
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
%19 = load i64, i64* %4
%20 = icmp sgt i64 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i16*, i16** %3
%23 = getelementptr inbounds i16, i16* %22, i64 1
%24 = load i16, i16* %23
%25 = zext i16 %24 to i32
%26 = shl i32 %25, 16
br label %28
27: ; preds = %14
br label %28
28: ; preds = %27, %21
%29 = phi i32 [ %26, %21 ], [ 0, %27 ]
%30 = or i32 %18, %29
%31 = sext i32 %30 to i64
store i64 %31, i64* %5
%32 = load i64, i64* %5
%33 = call i32 @dbg_write(i64 %32)
%34 = load i16*, i16** %3
%35 = getelementptr inbounds i16, i16* %34, i64 2
store i16* %35, i16** %3
%36 = load i64, i64* %4
%37 = sub nsw i64 %36, 2
store i64 %37, i64* %4
br label %11
38: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @dbg_write_u16(i16* nocapture %0, i64 %1) {
%3 = shl i64 %1, 16
%4 = and i64 %3, 4294901760
%5 = or i64 %4, 513
%6 = tail call i32 @dbg_write(i64 %5)
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %27
8: ; preds = %2, %19
%9 = phi i16* [ %24, %19 ], [ %0, %2 ]
%10 = phi i64 [ %25, %19 ], [ %1, %2 ]
%11 = load i16, i16* %9
%12 = zext i16 %11 to i32
%13 = icmp eq i64 %10, 1
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = getelementptr inbounds i16, i16* %9, i64 1
%16 = load i16, i16* %15
%17 = zext i16 %16 to i32
%18 = shl nuw i32 %17, 16
br label %19
19: ; preds = %8, %14
%20 = phi i32 [ %18, %14 ], [ 0, %8 ]
%21 = or i32 %20, %12
%22 = sext i32 %21 to i64
%23 = tail call i32 @dbg_write(i64 %22)
%24 = getelementptr inbounds i16, i16* %9, i64 2
%25 = add nsw i64 %10, -2
%26 = icmp ugt i64 %10, 2
br i1 %26, label %8, label %27
27: ; preds = %19, %2
ret void
}