#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_write_char(char);
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
  while (len--) {
    if (*str == '\n') {
      uart_write_char('\r');
    }
    uart_write_char(*str++);
  }
}


x86 assembly (clang, -O0):
<mp_hal_stdout_tx_strn_cooked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     116f <mp_hal_stdout_tx_strn_cooked+0x5f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1153 <mp_hal_stdout_tx_strn_cooked+0x43>
mov    $0xd,%edi
call   1030 <uart_write_char@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <uart_write_char@plt>
jmp    1120 <mp_hal_stdout_tx_strn_cooked+0x10>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_hal_stdout_tx_strn_cooked>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     115b <mp_hal_stdout_tx_strn_cooked+0x4b>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    1141 <mp_hal_stdout_tx_strn_cooked+0x31>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <uart_write_char@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     115b <mp_hal_stdout_tx_strn_cooked+0x4b>
movzbl (%r15,%rbx,1),%eax
cmp    $0xa,%al
jne    1130 <mp_hal_stdout_tx_strn_cooked+0x20>
mov    $0xd,%edi
call   1030 <uart_write_char@plt>
movzbl (%r15,%rbx,1),%eax
jmp    1130 <mp_hal_stdout_tx_strn_cooked+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mp_hal_stdout_tx_strn_cooked(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %5
5: ; preds = %16, %2
%6 = load i64, i64* %4
%7 = add i64 %6, -1
store i64 %7, i64* %4
%8 = icmp ne i64 %6, 0
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @uart_write_char(i8 signext 13)
br label %16
16: ; preds = %14, %9
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
%20 = call i32 @uart_write_char(i8 signext %19)
br label %5
21: ; preds = %5
ret void
}

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