#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*/ UARTConsolePutc(char const);
int uart_puts(const char *str, int len) {
  int i;
  for (i = 0; i < len; ++i) {
    UARTConsolePutc(str[i]);
    if (str[i] == '\n') {
      UARTConsolePutc('\r');
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<uart_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1175 <uart_puts+0x65>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <UARTConsolePutc@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1162 <uart_puts+0x52>
mov    $0xd,%edi
call   1030 <UARTConsolePutc@plt>
jmp    1167 <uart_puts+0x57>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <uart_puts+0x16>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_puts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %esi,%esi
jle    1154 <uart_puts+0x44>
mov    %rdi,%rbx
mov    %r14d,%r15d
xor    %ebp,%ebp
jmp    1139 <uart_puts+0x29>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1154 <uart_puts+0x44>
movsbl (%rbx,%rbp,1),%edi
call   1030 <UARTConsolePutc@plt>
cmpb   $0xa,(%rbx,%rbp,1)
jne    1130 <uart_puts+0x20>
mov    $0xd,%edi
call   1030 <UARTConsolePutc@plt>
jmp    1130 <uart_puts+0x20>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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