#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*/ uart_putchar_raw(int, unsigned char);
unsigned long crb_puts(long unit, const char *buf, unsigned long length) {
  unsigned int orig_length = length;
  if (unit != 0)
    return 0x8000000000000000ul;
  for (; length != 0; --length, ++buf)
    uart_putchar_raw((0x3f8 - 0x2f8), (unsigned char)*buf);
  return orig_length;
}


x86 assembly (clang, -O0):
<crb_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1149 <crb_puts+0x39>
movabs $0x8000000000000000,%rax
mov    %rax,-0x8(%rbp)
jmp    118e <crb_puts+0x7e>
jmp    114e <crb_puts+0x3e>
cmpq   $0x0,-0x20(%rbp)
je     1187 <crb_puts+0x77>
mov    -0x18(%rbp),%rax
mov    $0x100,%edi
movzbl (%rax),%esi
call   1030 <uart_putchar_raw@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114e <crb_puts+0x3e>
mov    -0x24(%rbp),%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crb_puts>:
test   %rdi,%rdi
je     1120 <crb_puts+0x10>
movabs $0x8000000000000000,%rax
ret
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
test   %rdx,%rdx
je     1158 <crb_puts+0x48>
mov    %rsi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%esi
mov    $0x100,%edi
call   1030 <uart_putchar_raw@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <crb_puts+0x30>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @crb_puts(i64 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = trunc i64 %9 to i32
store i32 %10, i32* %8
%11 = load i64, i64* %5
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i64 -9223372036854775808, i64* %4
br label %30
14: ; preds = %3
br label %15
15: ; preds = %22, %14
%16 = load i64, i64* %7
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = call i32 @uart_putchar_raw(i32 256, i8 zeroext %20)
br label %22
22: ; preds = %18
%23 = load i64, i64* %7
%24 = add i64 %23, -1
store i64 %24, i64* %7
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %15
27: ; preds = %15
%28 = load i32, i32* %8
%29 = zext i32 %28 to i64
store i64 %29, i64* %4
br label %30
30: ; preds = %27, %13
%31 = load i64, i64* %4
ret i64 %31
}

LLVM IR (-O2):
define i64 @crb_puts(i64 %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = icmp eq i64 %2, 0
br i1 %6, label %15, label %7
7: ; preds = %5, %7
%8 = phi i64 [ %12, %7 ], [ %2, %5 ]
%9 = phi i8* [ %13, %7 ], [ %1, %5 ]
%10 = load i8, i8* %9
%11 = tail call i32 @uart_putchar_raw(i32 256, i8 zeroext %10)
%12 = add i64 %8, -1
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %5
%16 = and i64 %2, 4294967295
br label %17
17: ; preds = %3, %15
%18 = phi i64 [ %16, %15 ], [ -9223372036854775808, %3 ]
ret i64 %18
}