#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 */
scalar_t__ uart0_putc(char);
int uart0_puts(char *s) {
  int i = 0;
  while (*s != '\n' && *s != '\0') {
    if (uart0_putc(*s) < 0)
      break;
    i++;
    s++;
  }
  if (*s == '\n') {
    uart0_putc('\n');
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<uart0_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0xd(%rbp)
je     1148 <uart0_puts+0x38>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1158 <uart0_puts+0x48>
jmp    118d <uart0_puts+0x7d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <uart0_putc@plt>
cmp    $0x0,%rax
jge    1173 <uart0_puts+0x63>
jmp    118d <uart0_puts+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <uart0_puts+0x13>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b0 <uart0_puts+0xa0>
mov    $0xa,%edi
call   1030 <uart0_putc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart0_puts>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%eax
test   %al,%al
je     1144 <uart0_puts+0x34>
cmp    $0xa,%al
je     1144 <uart0_puts+0x34>
movsbl %al,%edi
call   1030 <uart0_putc@plt>
test   %rax,%rax
js     1140 <uart0_puts+0x30>
add    $0x1,%rbx
jmp    1120 <uart0_puts+0x10>
mov    (%r14,%rbx,1),%al
cmp    $0xa,%al
jne    1155 <uart0_puts+0x45>
mov    $0xa,%edi
call   1030 <uart0_putc@plt>
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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