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


x86 assembly (clang, -O0):
<dbg_write_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     114c <dbg_write_str+0x3c>
cmpq   $0x10000,-0x10(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    115c <dbg_write_str+0x4c>
jmp    1172 <dbg_write_str+0x62>
jmp    1161 <dbg_write_str+0x51>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <dbg_write_str+0x14>
mov    -0x10(%rbp),%rdi
and    $0xffff,%rdi
shl    $0x10,%rdi
or     $0x1,%rdi
call   1030 <dbg_write@plt>
cmpq   $0x0,-0x10(%rbp)
jle    1261 <dbg_write_str+0x151>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x1,-0x10(%rbp)
jle    11bd <dbg_write_str+0xad>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x24(%rbp)
jmp    11c7 <dbg_write_str+0xb7>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    11c7 <dbg_write_str+0xb7>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x2,-0x10(%rbp)
jle    11f0 <dbg_write_str+0xe0>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fa <dbg_write_str+0xea>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fa <dbg_write_str+0xea>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
cmpq   $0x3,-0x10(%rbp)
jle    1223 <dbg_write_str+0x113>
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%eax
shl    $0x18,%eax
mov    %eax,-0x34(%rbp)
jmp    122d <dbg_write_str+0x11d>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    122d <dbg_write_str+0x11d>
mov    -0x30(%rbp),%eax
mov    -0x34(%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    118a <dbg_write_str+0x7a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_write_str>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xffffffffffff0000,%rdi
xor    %eax,%eax
lea    0x1(%rax),%rbx
add    $0x10000,%rdi
cmpb   $0x0,(%r14,%rax,1)
je     113d <dbg_write_str+0x2d>
cmp    $0x10000,%rax
mov    %rbx,%rax
jb     1120 <dbg_write_str+0x10>
and    $0xffff0000,%edi
or     $0x1,%rdi
call   1030 <dbg_write@plt>
cmp    $0x1,%rbx
jne    115a <dbg_write_str+0x4a>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x3,%rbx
add    $0x3,%r14
jmp    1186 <dbg_write_str+0x76>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %esi,%ecx
or     %eax,%ecx
movslq %ecx,%rdi
call   1030 <dbg_write@plt>
add    $0x4,%r14
cmp    $0x4,%rbx
jbe    1152 <dbg_write_str+0x42>
mov    %rbx,%rdx
add    $0xfffffffffffffffc,%rbx
movsbl -0x3(%r14),%ecx
xor    %eax,%eax
cmp    $0x5,%rdx
je     1172 <dbg_write_str+0x62>
movsbl -0x2(%r14),%esi
shl    $0x8,%esi
or     %ecx,%esi
cmp    $0x3,%rbx
jb     1170 <dbg_write_str+0x60>
movsbl -0x1(%r14),%ecx
shl    $0x10,%ecx
or     %esi,%ecx
cmp    $0x7,%rdx
je     1172 <dbg_write_str+0x62>
movzbl (%r14),%eax
shl    $0x18,%eax
jmp    1172 <dbg_write_str+0x62>

LLVM IR (-O0):
define void @dbg_write_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %5
5: ; preds = %18, %1
%6 = load i8*, i8** %2
%7 = load i64, i64* %3
%8 = getelementptr inbounds i8, i8* %6, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 65536
br label %15
15: ; preds = %12, %5
%16 = phi i1 [ false, %5 ], [ %14, %12 ]
br i1 %16, label %17, label %21
17: ; preds = %15
br label %18
18: ; preds = %17
%19 = load i64, i64* %3
%20 = add nsw i64 %19, 1
store i64 %20, i64* %3
br label %5
21: ; preds = %15
%22 = load i64, i64* %3
%23 = and i64 %22, 65535
%24 = shl i64 %23, 16
%25 = or i64 1, %24
%26 = call i32 @dbg_write(i64 %25)
br label %27
27: ; preds = %68, %21
%28 = load i64, i64* %3
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %78
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i64, i64* %3
%36 = icmp sgt i64 %35, 1
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = shl i32 %41, 8
br label %44
43: ; preds = %30
br label %44
44: ; preds = %43, %37
%45 = phi i32 [ %42, %37 ], [ 0, %43 ]
%46 = or i32 %34, %45
%47 = load i64, i64* %3
%48 = icmp sgt i64 %47, 2
br i1 %48, label %49, label %55
49: ; preds = %44
%50 = load i8*, i8** %2
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = shl i32 %53, 16
br label %56
55: ; preds = %44
br label %56
56: ; preds = %55, %49
%57 = phi i32 [ %54, %49 ], [ 0, %55 ]
%58 = or i32 %46, %57
%59 = load i64, i64* %3
%60 = icmp sgt i64 %59, 3
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = load i8*, i8** %2
%63 = getelementptr inbounds i8, i8* %62, i64 3
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = shl i32 %65, 24
br label %68
67: ; preds = %56
br label %68
68: ; preds = %67, %61
%69 = phi i32 [ %66, %61 ], [ 0, %67 ]
%70 = or i32 %58, %69
%71 = sext i32 %70 to i64
store i64 %71, i64* %4
%72 = load i64, i64* %4
%73 = call i32 @dbg_write(i64 %72)
%74 = load i8*, i8** %2
%75 = getelementptr inbounds i8, i8* %74, i64 4
store i8* %75, i8** %2
%76 = load i64, i64* %3
%77 = sub nsw i64 %76, 4
store i64 %77, i64* %3
br label %27
78: ; preds = %27
ret void
}

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