#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 */
typedef char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_string_with_length_fix_CRLF(char *s, size_t len) {
  char *token;
  for (token = s; token < s + len; token++) {
    if (*token == (uint8_t)13) {
      printf("\\r");
    } else if (*token == (uint8_t)10) {
      printf("\\n");
    } else {
      printf("%c", *token);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_string_with_length_fix_CRLF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    11b3 <print_string_with_length_fix_CRLF+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    1160 <print_string_with_length_fix_CRLF+0x50>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <print_string_with_length_fix_CRLF+0x8d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1183 <print_string_with_length_fix_CRLF+0x73>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1198 <print_string_with_length_fix_CRLF+0x88>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <print_string_with_length_fix_CRLF+0x8d>
jmp    11a2 <print_string_with_length_fix_CRLF+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <print_string_with_length_fix_CRLF+0x18>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string_with_length_fix_CRLF>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
jle    118c <print_string_with_length_fix_CRLF+0x6c>
mov    %rsi,%r14
mov    %rdi,%rbx
add    %rdi,%r14
lea    0xec6(%rip),%r15
lea    0xebc(%rip),%r12
jmp    115e <print_string_with_length_fix_CRLF+0x3e>
cs nopw 0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %r14,%rbx
jae    118c <print_string_with_length_fix_CRLF+0x6c>
movsbl (%rbx),%edi
cmp    $0xa,%edi
je     1180 <print_string_with_length_fix_CRLF+0x60>
cmp    $0xd,%dil
jne    1150 <print_string_with_length_fix_CRLF+0x30>
mov    %r12,%rdi
jmp    1183 <print_string_with_length_fix_CRLF+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1155 <print_string_with_length_fix_CRLF+0x35>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\r\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_string_with_length_fix_CRLF(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %34, %2
%8 = load i8*, i8** %5
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = icmp ult i8* %8, %11
br i1 %12, label %13, label %37
13: ; preds = %7
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 13
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %33
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %32
27: ; preds = %20
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %27, %25
br label %33
33: ; preds = %32, %18
br label %34
34: ; preds = %33
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
br label %7
37: ; preds = %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\r\00"
@.str.1 = [3 x i8] c"\\n\00"
define void @print_string_with_length_fix_CRLF(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = icmp sgt i64 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %2, %15
%6 = phi i8* [ %16, %15 ], [ %0, %2 ]
%7 = load i8, i8* %6
switch i8 %7, label %12 [
i8 13, label %8
i8 10, label %10
]
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %5
%13 = sext i8 %7 to i32
%14 = tail call i32 @putchar(i32 %13)
br label %15
15: ; preds = %8, %12, %10
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = icmp ult i8* %16, %3
br i1 %17, label %5, label %18
18: ; preds = %15, %2
%19 = tail call i32 @putchar(i32 10)
ret void
}