#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 *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int strlen(char *);
char *readline(char *data, int start) {
  int i, j, k;
  int end;
  int counter;
  char *buffer = malloc(128 * sizeof(char *));
  k, counter = 0;
  printf("[L]: %d\tLine: (", start + 1);
  for (i = start + 1; i < strlen(data); i++) {
    counter += 1;
    printf("%c", data[i]);
    if (data[i + 1] == '\n') {
      counter += 1;
      end = start + counter;
      printf(")\t[R]: %d\n", end);
      for (j = start + 1; j < end; j++) {
        buffer[k] = data[j];
        printf("%c\n", buffer[k]);
        k += 1;
      }
      printf("%d\n", strlen(buffer) + 1);
      printf("%c", buffer[0]);
      return buffer;
    }
  }
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
lea    0xe9f(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1295 <readline+0x165>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe6a(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1282 <readline+0x152>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
lea    0xe2e(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1247 <readline+0x117>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xdf7(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <readline+0xc6>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
lea    0xdc0(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
lea    0xda3(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1295 <readline+0x165>
jmp    1287 <readline+0x157>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1172 <readline+0x42>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r13d
mov    %rdi,%r15
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x1(%r13),%ebx
movsbl %bl,%esi
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %ebx,0x4(%rsp)
cmp    %eax,%ebx
jge    1243 <readline+0x113>
movslq %r13d,%rbp
lea    0x1(%rbp),%rax
mov    %rax,0x10(%rsp)
lea    (%r15,%rbp,1),%r14
add    $0x2,%r13d
mov    $0x1,%ebx
lea    0xe76(%rip),%r12
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
cmpb   $0xa,0x1(%r14,%rbx,1)
je     11d6 <readline+0xa6>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rbp,1),%rcx
add    $0x1,%rcx
add    $0x1,%rbx
add    $0x1,%r13d
cmp    %rax,%rcx
jl     11a0 <readline+0x70>
jmp    1243 <readline+0x113>
movsbl %r13b,%esi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
cmp    %r13d,0x4(%rsp)
mov    0x8(%rsp),%r14
jge    121a <readline+0xea>
add    0x10(%rsp),%r15
xor    %ebp,%ebp
lea    0xe1e(%rip),%r12
movsbl (%r15,%rbp,1),%esi
mov    %sil,(%r14,%rbp,1)
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
add    $0xffffffff,%ebx
jne    1200 <readline+0xd0>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%al
movsbl %al,%esi
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
movsbl (%r14),%esi
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"[L]: %d\09Line: (\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [11 x i8] c")\09[R]: %d\0A\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i8* @readline(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%12 = call i8* @malloc(i32 1024)
store i8* %12, i8** %11
%13 = load i32, i32* %8
store i32 0, i32* %10
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %16)
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %20
20: ; preds = %90, %2
%21 = load i32, i32* %6
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %93
25: ; preds = %20
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %32)
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %89
42: ; preds = %25
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
%45 = load i32, i32* %5
%46 = load i32, i32* %10
%47 = add nsw i32 %45, %46
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = trunc i32 %48 to i8
%50 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 signext %49)
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %53
53: ; preds = %75, %42
%54 = load i32, i32* %7
%55 = load i32, i32* %9
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %78
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = load i8*, i8** %11
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 %62, i8* %66
%67 = load i8*, i8** %11
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %71)
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %75
75: ; preds = %57
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %53
78: ; preds = %53
%79 = load i8*, i8** %11
%80 = call i32 @strlen(i8* %79)
%81 = add nsw i32 %80, 1
%82 = trunc i32 %81 to i8
%83 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %82)
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 0
%86 = load i8, i8* %85
%87 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %86)
%88 = load i8*, i8** %11
store i8* %88, i8** %3
br label %93
89: ; preds = %25
br label %90
90: ; preds = %89
%91 = load i32, i32* %6
%92 = add nsw i32 %91, 1
store i32 %92, i32* %6
br label %20
93: ; preds = %78, %20
%94 = load i8*, i8** %3
ret i8* %94
}

LLVM IR (-O2):
@.str = [16 x i8] c"[L]: %d\09Line: (\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [11 x i8] c")\09[R]: %d\0A\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i8* @readline(i8* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = add nsw i32 %1, 1
%5 = trunc i32 %4 to i8
%6 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp slt i32 %4, %7
br i1 %8, label %9, label %53
9: ; preds = %2
%10 = sext i32 %1 to i64
%11 = add nsw i64 %10, 1
br label %12
12: ; preds = %9, %48
%13 = phi i64 [ %11, %9 ], [ %18, %48 ]
%14 = phi i32 [ 0, %9 ], [ %49, %48 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %16)
%18 = add nsw i64 %13, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %48
22: ; preds = %12
%23 = add i32 %1, 2
%24 = add i32 %23, %14
%25 = trunc i32 %24 to i8
%26 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 signext %25)
%27 = icmp slt i32 %4, %24
br i1 %27, label %28, label %41
28: ; preds = %22
%29 = add nuw i32 %14, 1
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ %11, %28 ], [ %38, %30 ]
%32 = phi i64 [ 0, %28 ], [ %37, %30 ]
%33 = getelementptr inbounds i8, i8* %0, i64 %31
%34 = load i8, i8* %33
%35 = getelementptr inbounds i8, i8* %3, i64 %32
store i8 %34, i8* %35
%36 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %34)
%37 = add nuw nsw i64 %32, 1
%38 = add nsw i64 %31, 1
%39 = trunc i64 %37 to i32
%40 = icmp eq i32 %29, %39
br i1 %40, label %41, label %30
41: ; preds = %30, %22
%42 = tail call i32 @strlen(i8* %3)
%43 = trunc i32 %42 to i8
%44 = add i8 %43, 1
%45 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %44)
%46 = load i8, i8* %3
%47 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %46)
br label %53
48: ; preds = %12
%49 = add nuw nsw i32 %14, 1
%50 = tail call i32 @strlen(i8* %0)
%51 = sext i32 %50 to i64
%52 = icmp slt i64 %18, %51
br i1 %52, label %12, label %53
53: ; preds = %48, %2, %41
ret i8* %3
}