#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*/ ug_putc(char);
void ug_console_write(const char *buf, int len) {
  char *b = (char *)buf;
  while (len--) {
    if (*b == '\n')
      ug_putc('\r');
    ug_putc(*b++);
  }
}


x86 assembly (clang, -O0):
<ug_console_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1171 <ug_console_write+0x61>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1155 <ug_console_write+0x45>
mov    $0xd,%edi
call   1030 <ug_putc@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <ug_putc@plt>
jmp    1127 <ug_console_write+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ug_console_write>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
je     115b <ug_console_write+0x4b>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
jmp    1141 <ug_console_write+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <ug_putc@plt>
add    $0x1,%rbx
cmp    %ebx,%r14d
je     115b <ug_console_write+0x4b>
movzbl (%r15,%rbx,1),%eax
cmp    $0xa,%al
jne    1130 <ug_console_write+0x20>
mov    $0xd,%edi
call   1030 <ug_putc@plt>
movzbl (%r15,%rbx,1),%eax
jmp    1130 <ug_console_write+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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