#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 int /*<<< orphan*/ current_line_buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ concat_strings_created_with_malloc(char *, char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
char *realloc(char *, int);
int size_of_string(char *);
char *read_line(char sequence[], FILE *pFilePtr) {
  char *pcRes = NULL;
  long lineLength = 0;
  char current_line_buffer[65536] = {0};
  while ((pcRes = fgets(current_line_buffer, sizeof(current_line_buffer),
                        pFilePtr)) != NULL) {
    if (size_of_string(sequence) > 0) {
      sequence = realloc(
          sequence, sizeof(char) * (size_of_string(sequence) +
                                    size_of_string(current_line_buffer) + 2));
    }
    concat_strings_created_with_malloc(sequence, current_line_buffer);
    current_line_buffer[0] = '\0';
    lineLength = size_of_string(sequence);
    if ((sequence)[lineLength] == '\n' || (sequence)[lineLength] == '\0') {
      break;
    }
  }
  return sequence;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x10020(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x10000,%esi
call   1050 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1260 <read_line+0x110>
mov    -0x8(%rbp),%rdi
call   1070 <size_of_string@plt>
cmp    $0x0,%eax
jle    1206 <read_line+0xb6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10030(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <size_of_string@plt>
mov    %eax,-0x10024(%rbp)
lea    -0x10020(%rbp),%rdi
call   1070 <size_of_string@plt>
mov    -0x10030(%rbp),%rdi
mov    %eax,%ecx
mov    -0x10024(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10020(%rbp),%rsi
call   1030 <concat_strings_created_with_malloc@plt>
movb   $0x0,-0x10020(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <size_of_string@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1256 <read_line+0x106>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    125b <read_line+0x10b>
jmp    1260 <read_line+0x110>
jmp    1186 <read_line+0x36>
mov    -0x8(%rbp),%rax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    $0x10000,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11eb <read_line+0x9b>
mov    %rbx,%rdi
call   1070 <size_of_string@plt>
test   %eax,%eax
jle    11c6 <read_line+0x76>
mov    %rbx,%rdi
call   1070 <size_of_string@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1070 <size_of_string@plt>
lea    (%r12,%rax,1),%esi
add    $0x2,%esi
mov    %rbx,%rdi
call   1060 <realloc@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <concat_strings_created_with_malloc@plt>
movb   $0x0,(%rsp)
mov    %rbx,%rdi
call   1070 <size_of_string@plt>
cltq
movzbl (%rbx,%rax,1),%eax
cmp    $0xa,%al
je     11eb <read_line+0x9b>
test   %al,%al
jne    1180 <read_line+0x30>
mov    %rbx,%rax
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @read_line(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [65536 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %5
store i64 0, i64* %6
%8 = bitcast [65536 x i8]* %7 to i8*
br label %9
9: ; preds = %52, %2
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i8* @fgets(i8* %10, i32 65536, i32* %11)
store i8* %12, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %53
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @size_of_string(i8* %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @size_of_string(i8* %20)
%22 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%23 = call i32 @size_of_string(i8* %22)
%24 = add nsw i32 %21, %23
%25 = add nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @realloc(i8* %19, i32 %28)
store i8* %29, i8** %3
br label %30
30: ; preds = %18, %14
%31 = load i8*, i8** %3
%32 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%33 = call i32 @concat_strings_created_with_malloc(i8* %31, i8* %32)
%34 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
store i8 0, i8* %34
%35 = load i8*, i8** %3
%36 = call i32 @size_of_string(i8* %35)
%37 = sext i32 %36 to i64
store i64 %37, i64* %6
%38 = load i8*, i8** %3
%39 = load i64, i64* %6
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %51, label %44
44: ; preds = %30
%45 = load i8*, i8** %3
%46 = load i64, i64* %6
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %44, %30
br label %53
52: ; preds = %44
br label %9
53: ; preds = %51, %9
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
define i8* @read_line(i8* %0, i32* nocapture %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %18, %2
%6 = phi i8* [ %0, %2 ], [ %19, %18 ]
%7 = call i8* @fgets(i8* %4, i32 65536, i32* %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %5
%10 = call i32 @size_of_string(i8* %6)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i32 @size_of_string(i8* %6)
%14 = call i32 @size_of_string(i8* %4)
%15 = add i32 %13, 2
%16 = add i32 %15, %14
%17 = call i8* @realloc(i8* %6, i32 %16)
br label %18
18: ; preds = %12, %9
%19 = phi i8* [ %17, %12 ], [ %6, %9 ]
%20 = call i32 @concat_strings_created_with_malloc(i8* %19, i8* %4)
store i8 0, i8* %4
%21 = call i32 @size_of_string(i8* %19)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
switch i8 %24, label %5 [
i8 10, label %25
i8 0, label %25
]
25: ; preds = %18, %18, %5
%26 = phi i8* [ %19, %18 ], [ %6, %5 ], [ %19, %18 ]
ret i8* %26
}