#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__ tx_rdy();
int /*<<< orphan*/ tx_writec(unsigned char const);
void serial_tx(const unsigned char *buf) {
  for (;;) {
    if (tx_rdy()) {
      if (*buf == '\0')
        return;
      if (*buf == '\n')
        tx_writec('\r');
      tx_writec(*buf);
      buf++;
    }
  }
}


x86 assembly (clang, -O0):
<serial_tx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <tx_rdy@plt>
cmp    $0x0,%rax
je     1185 <serial_tx+0x65>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    1153 <serial_tx+0x33>
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
jne    116d <serial_tx+0x4d>
mov    $0xd,%edi
call   1030 <tx_writec@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tx_writec@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <serial_tx+0xc>

x86 assembly (clang, -O2):
<serial_tx>:
push   %rbx
mov    %rdi,%rbx
jmp    1140 <serial_tx+0x20>
mov    $0xd,%edi
call   1030 <tx_writec@plt>
movzbl (%rbx),%eax
movzbl %al,%edi
call   1030 <tx_writec@plt>
add    $0x1,%rbx
nop
xor    %eax,%eax
call   1040 <tx_rdy@plt>
test   %rax,%rax
je     1140 <serial_tx+0x20>
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1126 <serial_tx+0x6>
test   %al,%al
jne    1133 <serial_tx+0x13>
pop    %rbx
ret

LLVM IR (-O0):
define void @serial_tx(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %25, %1
%4 = call i64 (...) @tx_rdy()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
ret void
12: ; preds = %6
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @tx_writec(i8 zeroext 13)
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = call i32 @tx_writec(i8 zeroext %21)
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %2
br label %25
25: ; preds = %19, %3
br label %3
}

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