#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void print_lstr(char *str) {
  int i = 0;
  while (str[i] != '\0') {
    switch (str[i]) {
    case '\n':
      fprintf(stderr, "\\n");
      break;
    default:
      fprintf(stderr, "%c", str[i]);
      break;
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<print_lstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119d <print_lstr+0x8d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
sub    $0xa,%al
jne    116c <print_lstr+0x5c>
jmp    1150 <print_lstr+0x40>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    118f <print_lstr+0x7f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <print_lstr+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_lstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ebe(%rip),%r12
lea    0xed7(%rip),%r14
lea    0xed3(%rip),%r15
jmp    1152 <print_lstr+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
movsbl (%rbx),%edx
cmp    $0xa,%edx
je     1140 <print_lstr+0x30>
test   %dl,%dl
je     1172 <print_lstr+0x62>
mov    (%r12),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
jmp    1152 <print_lstr+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"%c\00"
define void @print_lstr(i8* nocapture %0) {
br label %2
2: ; preds = %13, %1
%3 = phi i64 [ %14, %13 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
switch i8 %5, label %9 [
i8 0, label %15
i8 10, label %6
]
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %2
%10 = sext i8 %5 to i32
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %13
13: ; preds = %9, %6
%14 = add nuw i64 %3, 1
br label %2
15: ; preds = %2
ret void
}