#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*/ UartTx(char);
int PutString(char *cp) {
  int rc = 0;
  for (; *cp; cp++) {
    if (*cp == '\n') {
      UartTx('\r');
      rc++;
    }
    UartTx(*cp);
    rc++;
  }
  return rc;
}


x86 assembly (clang, -O0):
<PutString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1179 <PutString+0x69>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1153 <PutString+0x43>
mov    $0xd,%edi
call   1030 <UartTx@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <UartTx@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <PutString+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PutString>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
jmp    113f <PutString+0x2f>
nopw   0x0(%rax,%rax,1)
mov    $0xd,%edi
call   1030 <UartTx@plt>
add    $0x1,%ebp
movzbl (%rbx),%eax
movsbl %al,%edi
call   1030 <UartTx@plt>
add    $0x1,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1120 <PutString+0x10>
test   %al,%al
jne    1130 <PutString+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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