#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 */
char *calloc(int, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ stderr;
void print_current_line(const char *restrict current_char,
                        const char *restrict buffer_start,
                        const char *restrict buffer_end) {
  const char *restrict start = current_char;
  const char *restrict end = current_char;
  while (--start > buffer_start && *start != '\n' && *start != '\r')
    ;
  start++;
  while (++end < buffer_end && *end != '\n' && *end != '\r')
    ;
  end--;
  size_t line_length = end - start;
  char *printable_string = calloc(sizeof(char), line_length + 1);
  memcpy(printable_string, start, line_length);
  printable_string[line_length] = '\0';
  fprintf(stderr, "Current line: %s\n", printable_string);
  free(printable_string);
}


x86 assembly (clang, -O0):
<print_current_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x39(%rbp)
jbe    11a4 <print_current_line+0x64>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x39(%rbp)
je     11a4 <print_current_line+0x64>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11b4 <print_current_line+0x74>
jmp    11b9 <print_current_line+0x79>
jmp    1164 <print_current_line+0x24>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x3a(%rbp)
jae    1205 <print_current_line+0xc5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x3a(%rbp)
je     1205 <print_current_line+0xc5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    1215 <print_current_line+0xd5>
jmp    121a <print_current_line+0xda>
jmp    11c5 <print_current_line+0x85>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd84(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_current_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xffffffffffffffff,%rcx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdi,%rax
lea    (%r14,%rcx,1),%rdi
cmp    %rsi,%rdi
jbe    1181 <print_current_line+0x41>
movzbl (%rdi),%ebx
cmp    $0xd,%bl
je     1181 <print_current_line+0x41>
lea    0x1(%rax),%rdi
add    $0xffffffffffffffff,%rcx
cmp    $0xa,%bl
jne    1160 <print_current_line+0x20>
lea    0x1(%r14),%rcx
sub    %rax,%r14
nopl   0x0(%rax,%rax,1)
mov    %rax,%r12
cmp    %rdx,%rcx
jae    11ae <print_current_line+0x6e>
movzbl (%rcx),%ebx
cmp    $0xd,%bl
je     11ae <print_current_line+0x6e>
lea    0x1(%r12),%rax
add    $0x1,%rcx
cmp    $0xa,%bl
jne    1190 <print_current_line+0x50>
lea    0x1(%r12),%rsi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Current line: %s\0A\00"
define void @print_current_line(i8* noalias %0, i8* noalias %1, i8* noalias %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
store i8* %11, i8** %7
%12 = load i8*, i8** %4
store i8* %12, i8** %8
br label %13
13: ; preds = %30, %3
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %7
%16 = load i8*, i8** %5
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 13
br label %28
28: ; preds = %23, %18, %13
%29 = phi i1 [ false, %18 ], [ false, %13 ], [ %27, %23 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %13
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %7
br label %34
34: ; preds = %51, %31
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
%37 = load i8*, i8** %6
%38 = icmp ult i8* %36, %37
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = load i8*, i8** %8
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 10
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i8*, i8** %8
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 13
br label %49
49: ; preds = %44, %39, %34
%50 = phi i1 [ false, %39 ], [ false, %34 ], [ %48, %44 ]
br i1 %50, label %51, label %52
51: ; preds = %49
br label %34
52: ; preds = %49
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i32 -1
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = load i8*, i8** %7
%57 = ptrtoint i8* %55 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
store i64 %59, i64* %9
%60 = load i64, i64* %9
%61 = add i64 %60, 1
%62 = call i8* @calloc(i32 1, i64 %61)
store i8* %62, i8** %10
%63 = load i8*, i8** %10
%64 = load i8*, i8** %7
%65 = load i64, i64* %9
%66 = call i32 @memcpy(i8* %63, i8* %64, i64 %65)
%67 = load i8*, i8** %10
%68 = load i64, i64* %9
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %10
%72 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = load i8*, i8** %10
%74 = call i32 @free(i8* %73)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Current line: %s\0A\00"
define void @print_current_line(i8* noalias %0, i8* noalias readnone %1, i8* noalias readnone %2) {
br label %4
4: ; preds = %8, %3
%5 = phi i8* [ %0, %3 ], [ %6, %8 ]
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ugt i8* %6, %1
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = load i8, i8* %6
switch i8 %9, label %4 [
i8 10, label %10
i8 13, label %10
]
10: ; preds = %8, %8, %4
br label %11
11: ; preds = %10, %15
%12 = phi i8* [ %13, %15 ], [ %0, %10 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = icmp ult i8* %13, %2
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i8, i8* %13
switch i8 %16, label %11 [
i8 10, label %17
i8 13, label %17
]
17: ; preds = %15, %15, %11
%18 = ptrtoint i8* %12 to i64
%19 = ptrtoint i8* %5 to i64
%20 = sub i64 %18, %19
%21 = add i64 %20, 1
%22 = tail call i8* @calloc(i32 1, i64 %21)
%23 = tail call i32 @memcpy(i8* %22, i8* %5, i64 %20)
%24 = getelementptr inbounds i8, i8* %22, i64 %20
store i8 0, i8* %24
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
%27 = tail call i32 @free(i8* %22)
ret void
}