#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*/ early_serial_putc(char const);
void early_serial_write(const char *s, unsigned n) {
  while (*s && n-- > 0) {
    if (*s == '\n')
      early_serial_putc('\r');
    early_serial_putc(*s);
    s++;
  }
}


x86 assembly (clang, -O0):
<early_serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     1148 <early_serial_write+0x38>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
seta   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1158 <early_serial_write+0x48>
jmp    118f <early_serial_write+0x7f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1172 <early_serial_write+0x62>
mov    $0xd,%edi
call   1030 <early_serial_putc@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <early_serial_putc@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111f <early_serial_write+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<early_serial_write>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1160 <early_serial_write+0x50>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
jmp    1146 <early_serial_write+0x36>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1030 <early_serial_putc@plt>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     1160 <early_serial_write+0x50>
cmp    %ebx,%r14d
je     1160 <early_serial_write+0x50>
cmp    $0xa,%al
jne    1130 <early_serial_write+0x20>
mov    $0xd,%edi
call   1030 <early_serial_putc@plt>
movzbl (%r15,%rbx,1),%eax
jmp    1130 <early_serial_write+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @early_serial_write(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %5
5: ; preds = %23, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* %4
%12 = add i32 %11, -1
store i32 %12, i32* %4
%13 = icmp ugt i32 %11, 0
br label %14
14: ; preds = %10, %5
%15 = phi i1 [ false, %5 ], [ %13, %10 ]
br i1 %15, label %16, label %29
16: ; preds = %14
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @early_serial_putc(i8 signext 13)
br label %23
23: ; preds = %21, %16
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = call i32 @early_serial_putc(i8 signext %25)
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
br label %5
29: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @early_serial_write(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2, %16
%6 = phi i8 [ %20, %16 ], [ %3, %2 ]
%7 = phi i32 [ %9, %16 ], [ %1, %2 ]
%8 = phi i8* [ %19, %16 ], [ %0, %2 ]
%9 = add i32 %7, -1
%10 = icmp eq i32 %7, 0
br i1 %10, label %22, label %11
11: ; preds = %5
%12 = icmp eq i8 %6, 10
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @early_serial_putc(i8 signext 13)
%15 = load i8, i8* %8
br label %16
16: ; preds = %13, %11
%17 = phi i8 [ %15, %13 ], [ %6, %11 ]
%18 = tail call i32 @early_serial_putc(i8 signext %17)
%19 = getelementptr inbounds i8, i8* %8, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %5, %16, %2
ret void
}