#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_u8(const unsigned char *val, long len) {
  unsigned long dcc_data;
  dbg_write((0x01 | ((1 & 0xff) << 8)) | ((len & 0xffff) << 16));
  while (len > 0) {
    dcc_data = val[0] | ((len > 1) ? val[1] << 8 : 0x00) |
               ((len > 2) ? val[2] << 16 : 0x00) |
               ((len > 3) ? val[3] << 24 : 0x00);
    dbg_write(dcc_data);
    val += 4;
    len -= 4;
  }
}


x86 assembly (clang, -O0):
<dbg_write_u8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
and    $0xffff,%rdi
shl    $0x10,%rdi
or     $0x101,%rdi
call   1030 <dbg_write@plt>
cmpq   $0x0,-0x10(%rbp)
jle    1212 <dbg_write_u8+0x102>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x1,-0x10(%rbp)
jle    116e <dbg_write_u8+0x5e>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <dbg_write_u8+0x68>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <dbg_write_u8+0x68>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x2,-0x10(%rbp)
jle    11a1 <dbg_write_u8+0x91>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    11ab <dbg_write_u8+0x9b>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11ab <dbg_write_u8+0x9b>
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x3,-0x10(%rbp)
jle    11d4 <dbg_write_u8+0xc4>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
shl    $0x18,%eax
mov    %eax,-0x30(%rbp)
jmp    11de <dbg_write_u8+0xce>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    11de <dbg_write_u8+0xce>
mov    -0x2c(%rbp),%eax
mov    -0x30(%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    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    113b <dbg_write_u8+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_write_u8>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %r14d,%edi
shl    $0x10,%edi
or     $0x101,%rdi
call   1030 <dbg_write@plt>
test   %r14,%r14
jle    118f <dbg_write_u8+0x7f>
add    $0x3,%rbx
jmp    115d <dbg_write_u8+0x4d>
nopw   0x0(%rax,%rax,1)
mov    %edx,%ecx
or     %eax,%ecx
movslq %ecx,%rdi
call   1030 <dbg_write@plt>
lea    -0x4(%r14),%rax
add    $0x4,%rbx
cmp    $0x4,%r14
mov    %rax,%r14
jbe    118f <dbg_write_u8+0x7f>
movzbl -0x3(%rbx),%ecx
xor    %eax,%eax
cmp    $0x1,%r14
je     1142 <dbg_write_u8+0x32>
movzbl -0x2(%rbx),%edx
shl    $0x8,%edx
or     %ecx,%edx
cmp    $0x3,%r14
jb     1140 <dbg_write_u8+0x30>
movzbl -0x1(%rbx),%ecx
shl    $0x10,%ecx
or     %edx,%ecx
cmp    $0x3,%r14
je     1142 <dbg_write_u8+0x32>
movzbl (%rbx),%eax
shl    $0x18,%eax
jmp    1142 <dbg_write_u8+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @dbg_write_u8(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = and i64 %6, 65535
%8 = shl i64 %7, 16
%9 = or i64 257, %8
%10 = call i32 @dbg_write(i64 %9)
br label %11
11: ; preds = %52, %2
%12 = load i64, i64* %4
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %62
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %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 i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 8
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 = load i64, i64* %4
%32 = icmp sgt i64 %31, 2
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl i32 %37, 16
br label %40
39: ; preds = %28
br label %40
40: ; preds = %39, %33
%41 = phi i32 [ %38, %33 ], [ 0, %39 ]
%42 = or i32 %30, %41
%43 = load i64, i64* %4
%44 = icmp sgt i64 %43, 3
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 3
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl i32 %49, 24
br label %52
51: ; preds = %40
br label %52
52: ; preds = %51, %45
%53 = phi i32 [ %50, %45 ], [ 0, %51 ]
%54 = or i32 %42, %53
%55 = sext i32 %54 to i64
store i64 %55, i64* %5
%56 = load i64, i64* %5
%57 = call i32 @dbg_write(i64 %56)
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i64 4
store i8* %59, i8** %3
%60 = load i64, i64* %4
%61 = sub nsw i64 %60, 4
store i64 %61, i64* %4
br label %11
62: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @dbg_write_u8(i8* nocapture %0, i64 %1) {
%3 = shl i64 %1, 16
%4 = and i64 %3, 4294901760
%5 = or i64 %4, 257
%6 = tail call i32 @dbg_write(i64 %5)
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %42
8: ; preds = %2, %33
%9 = phi i8* [ %39, %33 ], [ %0, %2 ]
%10 = phi i64 [ %40, %33 ], [ %1, %2 ]
%11 = load i8, i8* %9
%12 = zext i8 %11 to i32
%13 = icmp eq i64 %10, 1
br i1 %13, label %33, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = or i32 %18, %12
%20 = icmp ugt i64 %10, 2
br i1 %20, label %21, label %33
21: ; preds = %14
%22 = getelementptr inbounds i8, i8* %9, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 16
%26 = or i32 %25, %19
%27 = icmp eq i64 %10, 3
br i1 %27, label %33, label %28
28: ; preds = %21
%29 = getelementptr inbounds i8, i8* %9, i64 3
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl nuw i32 %31, 24
br label %33
33: ; preds = %8, %14, %21, %28
%34 = phi i32 [ %26, %28 ], [ %26, %21 ], [ %19, %14 ], [ %12, %8 ]
%35 = phi i32 [ %32, %28 ], [ 0, %21 ], [ 0, %14 ], [ 0, %8 ]
%36 = or i32 %35, %34
%37 = sext i32 %36 to i64
%38 = tail call i32 @dbg_write(i64 %37)
%39 = getelementptr inbounds i8, i8* %9, i64 4
%40 = add nsw i64 %10, -4
%41 = icmp ugt i64 %10, 4
br i1 %41, label %8, label %42
42: ; preds = %33, %2
ret void
}