int readlines(char *lineptr[], int maxlines, char *array) {
  int len = 0;
  int nlines = 0;
  char *p = 0;
  char line[1000];
  int pos = 0;
  while ((len = getline_my(line, 1000)) > 0) {
    printf("in readlines.\n");
    if (nlines >= maxlines || (pos + len) >= 4000 * 1000) {
      printf("Error in readlines. nlines = %d; p + len = %d;\n", nlines,
             p + len);
      return -1;
    } else {
      p = &array[pos];
      pos += len;
      line[len - 1] = '\0';
      strcpy(p, line);
      lineptr[nlines++] = p;
    }
  }
  printf("function readlines ended its work with rezult line = %s; and its "
         "lenght = %d;\n",
         lineptr, nlines);
  return nlines;
}


x86 assembly (clang, -O0):
<readlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1050 <getline_my@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    123b <readlines+0x10b>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <readlines+0x83>
mov    -0x424(%rbp),%eax
add    -0x24(%rbp),%eax
cmp    $0x3d0900,%eax
jl     11db <readlines+0xab>
mov    -0x28(%rbp),%esi
mov    -0x30(%rbp),%rdx
movslq -0x24(%rbp),%rax
add    %rax,%rdx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <readlines+0x126>
mov    -0x20(%rbp),%rax
movslq -0x424(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    -0x424(%rbp),%eax
mov    %eax,-0x424(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x30(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1166 <readlines+0x36>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rdx,0x8(%rsp)
mov    %esi,%r15d
mov    %rdi,(%rsp)
xor    %r13d,%r13d
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1060 <getline_my@plt>
test   %eax,%eax
jle    11f2 <readlines+0xb2>
mov    %eax,%ebp
xor    %eax,%eax
test   %r15d,%r15d
cmovle %eax,%r15d
xor    %r13d,%r13d
xor    %r12d,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
cmp    %r13,%r15
je     120c <readlines+0xcc>
lea    (%r12,%rbp,1),%r14d
cmp    $0x3d0900,%r14d
jge    1209 <readlines+0xc9>
movslq %r12d,%rbx
add    0x8(%rsp),%rbx
add    $0xffffffff,%ebp
movb   $0x0,0x10(%rsp,%rbp,1)
mov    %rbx,%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    (%rsp),%rax
mov    %rbx,(%rax,%r13,8)
add    $0x1,%r13
mov    %rbp,%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1060 <getline_my@plt>
mov    %eax,%ebp
mov    %r14d,%r12d
test   %eax,%eax
jg     1190 <readlines+0x50>
lea    0xe37(%rip),%rdi
mov    (%rsp),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    122b <readlines+0xeb>
mov    %r13d,%r15d
mov    %ebp,%eax
add    %rax,%rbx
lea    0xde8(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"in readlines.\0A\00"
@.str.1 = [48 x i8] c"Error in readlines. nlines = %d; p + len = %d;\0A\00"
@.str.2 = [79 x i8] c"function readlines ended its work with rezult line = %s; and its lenght = %d;\0A\00"
define i32 @readlines(i8** %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [1000 x i8]
%12 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i32 0, i32* %12
br label %13
13: ; preds = %55, %3
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%15 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getline_my to i32 (i8*, i32, ...)*)(i8* %14, i32 1000)
store i32 %15, i32* %8
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %56
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = icmp sge i32 %19, %20
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i32, i32* %12
%24 = load i32, i32* %8
%25 = add nsw i32 %23, %24
%26 = icmp sge i32 %25, 4000000
br i1 %26, label %27, label %34
27: ; preds = %22, %17
%28 = load i32, i32* %9
%29 = load i8*, i8** %10
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %32)
store i32 -1, i32* %4
br label %61
34: ; preds = %22
%35 = load i8*, i8** %7
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8* %38, i8** %10
%39 = load i32, i32* %8
%40 = load i32, i32* %12
%41 = add nsw i32 %40, %39
store i32 %41, i32* %12
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %10
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%48 = call i8* @strcpy(i8* %46, i8* %47)
%49 = load i8*, i8** %10
%50 = load i8**, i8*** %5
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8*, i8** %50, i64 %53
store i8* %49, i8** %54
br label %55
55: ; preds = %34
br label %13
56: ; preds = %13
%57 = load i8**, i8*** %5
%58 = load i32, i32* %9
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i8** %57, i32 %58)
%60 = load i32, i32* %9
store i32 %60, i32* %4
br label %61
61: ; preds = %56, %27
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str.1 = [48 x i8] c"Error in readlines. nlines = %d; p + len = %d;\0A\00"
@.str.2 = [79 x i8] c"function readlines ended its work with rezult line = %s; and its lenght = %d;\0A\00"
@str = [14 x i8] c"in readlines.\00"
define i32 @readlines(i8** %0, i32 %1, i8* %2) {
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%6 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getline_my to i32 (i8*, i32, ...)*)(i8* %5, i32 1000)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %41
8: ; preds = %3
%9 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %28
%12 = phi i64 [ 0, %8 ], [ %35, %28 ]
%13 = phi i32 [ %6, %8 ], [ %37, %28 ]
%14 = phi i32 [ 0, %8 ], [ %19, %28 ]
%15 = phi i8* [ null, %8 ], [ %30, %28 ]
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%17 = icmp eq i64 %12, %10
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = add nsw i32 %13, %14
%20 = icmp sgt i32 %19, 3999999
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = trunc i64 %12 to i32
br label %23
23: ; preds = %11, %21
%24 = phi i32 [ %22, %21 ], [ %9, %11 ]
%25 = zext i32 %13 to i64
%26 = getelementptr inbounds i8, i8* %15, i64 %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %26)
br label %44
28: ; preds = %18
%29 = sext i32 %14 to i64
%30 = getelementptr inbounds i8, i8* %2, i64 %29
%31 = add nsw i32 %13, -1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i8* @strcpy(i8* dereferenceable(1) %30, i8* %5)
%35 = add nuw nsw i64 %12, 1
%36 = getelementptr inbounds i8*, i8** %0, i64 %12
store i8* %30, i8** %36
%37 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getline_my to i32 (i8*, i32, ...)*)(i8* %5, i32 1000)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %11, label %39
39: ; preds = %28
%40 = trunc i64 %35 to i32
br label %41
41: ; preds = %39, %3
%42 = phi i32 [ 0, %3 ], [ %40, %39 ]
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i8** %0, i32 %42)
br label %44
44: ; preds = %41, %23
%45 = phi i32 [ -1, %23 ], [ %42, %41 ]
ret i32 %45
}