#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_OutChar(char);
int _write(int fd, char *buf, size_t count) {
  size_t CharCnt;
  (void)fd;
  for (CharCnt = 0; CharCnt < count; CharCnt++) {
    char ch = buf[CharCnt];
    if ((ch == 0x0AU) || (ch == 0x0DU) || (ch == 0x1BU))
      UART_OutChar(0x0DU);
    UART_OutChar(ch);
  }
  return CharCnt;
}


x86 assembly (clang, -O0):
<_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1192 <_write+0x82>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
je     116e <_write+0x5e>
movsbl -0x21(%rbp),%eax
cmp    $0xd,%eax
je     116e <_write+0x5e>
movsbl -0x21(%rbp),%eax
cmp    $0x1b,%eax
jne    1178 <_write+0x68>
mov    $0xd,%edi
call   1030 <UART_OutChar@plt>
movsbl -0x21(%rbp),%edi
call   1030 <UART_OutChar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <_write+0x1b>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     115f <_write+0x4f>
mov    %rdx,%r14
mov    %rsi,%r15
xor    %ebx,%ebx
mov    $0x8002400,%r12d
jmp    1142 <_write+0x32>
xchg   %ax,%ax
movsbl %r13b,%edi
call   1030 <UART_OutChar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     1162 <_write+0x52>
movzbl (%r15,%rbx,1),%r13d
cmp    $0x1b,%r13
ja     1130 <_write+0x20>
bt     %r13,%r12
jae    1130 <_write+0x20>
mov    $0xd,%edi
call   1030 <UART_OutChar@plt>
jmp    1130 <_write+0x20>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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