char *get_input_text() {
  int paragraph_count;
  scanf("%d", &paragraph_count);
  char p[5][1005], doc[1005];
  memset(doc, 0, sizeof(doc));
  memset(p, 0, sizeof(p));
  getchar();
  for (int i = 0; i < paragraph_count; i++) {
    scanf("%[^\n]%*c", p[i]);
    strcat(doc, p[i]);
    if (i != paragraph_count - 1)
      strcat(doc, "\n");
  }
  char *returnDoc = (char *)malloc((strlen(doc) + 1) * sizeof(char));
  strcpy(returnDoc, doc);
  return returnDoc;
}


x86 assembly (clang, -O0):
<get_input_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17b0,%rsp
lea    0xe7e(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0x17a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3ed,%edx
call   1050 <memset@plt>
lea    -0x13b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x13a1,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x0,-0x17a4(%rbp)
mov    -0x17a4(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    125d <get_input_text+0xed>
movslq -0x17a4(%rbp),%rax
lea    -0x13b0(%rbp),%rsi
imul   $0x3ed,%rax,%rax
add    %rax,%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0x17a0(%rbp),%rdi
movslq -0x17a4(%rbp),%rax
lea    -0x13b0(%rbp),%rsi
imul   $0x3ed,%rax,%rax
add    %rax,%rsi
call   1090 <strcat@plt>
mov    -0x17a4(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1244 <get_input_text+0xd4>
lea    -0x17a0(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1090 <strcat@plt>
jmp    1249 <get_input_text+0xd9>
mov    -0x17a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x17a4(%rbp)
jmp    11c4 <get_input_text+0x54>
lea    -0x17a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x17b0(%rbp)
mov    -0x17b0(%rbp),%rdi
lea    -0x17a0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x17b0(%rbp),%rax
add    $0x17b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_text>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x17b0,%rsp
lea    0xe79(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0x10(%rsp),%rdi
mov    $0x3ed,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x400(%rsp),%r12
mov    $0x13a1,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    1227 <get_input_text+0xb7>
lea    0xe33(%rip),%r14
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
jmp    11f0 <get_input_text+0x80>
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0x3ed,%r12
cmp    %r13,%rbx
jge    1227 <get_input_text+0xb7>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
movslq 0xc(%rsp),%r13
lea    -0x1(%r13),%eax
cmp    %rax,%rbx
je     11e0 <get_input_text+0x70>
mov    %r15,%rdi
call   1040 <strlen@plt>
movw   $0xa,0x10(%rsp,%rax,1)
jmp    11e0 <get_input_text+0x70>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x17b0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @get_input_text() {
%1 = alloca i32
%2 = alloca [5 x [1005 x i8]]
%3 = alloca [1005 x i8]
%4 = alloca i32
%5 = alloca i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [5 x [1005 x i8]], [5 x [1005 x i8]]* %2, i64 0, i64 0
%9 = bitcast [1005 x i8]* %8 to i8*
%10 = call i32 (...) @getchar()
store i32 0, i32* %4
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %1
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [5 x [1005 x i8]], [5 x [1005 x i8]]* %2, i64 0, i64 %17
%19 = getelementptr inbounds [1005 x i8], [1005 x i8]* %18, i64 0, i64 0
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x [1005 x i8]], [5 x [1005 x i8]]* %2, i64 0, i64 %23
%25 = getelementptr inbounds [1005 x i8], [1005 x i8]* %24, i64 0, i64 0
%26 = call i8* @strcat(i8* %21, i8* %25)
%27 = load i32, i32* %4
%28 = load i32, i32* %1
%29 = sub nsw i32 %28, 1
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %15
%32 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%33 = call i8* @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %31, %15
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %11
38: ; preds = %11
%39 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%40 = call i64 @strlen(i8* %39)
%41 = add i64 %40, 1
%42 = mul i64 %41, 1
%43 = call i8* @malloc(i64 %42)
store i8* %43, i8** %5
%44 = load i8*, i8** %5
%45 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%46 = call i8* @strcpy(i8* %44, i8* %45)
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
define i8* @get_input_text() {
%1 = alloca i32
%2 = alloca [5 x [1005 x i8]]
%3 = alloca [1005 x i8]
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = getelementptr inbounds [5 x [1005 x i8]], [5 x [1005 x i8]]* %2, i64 0, i64 0, i64 0
%7 = getelementptr inbounds [1005 x i8], [1005 x i8]* %3, i64 0, i64 0
%8 = call i32 (...) @getchar()
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %29, %0
%12 = call i64 @strlen(i8* %7)
%13 = add i64 %12, 1
%14 = call i8* @malloc(i64 %13)
%15 = call i8* @strcpy(i8* dereferenceable(1) %14, i8* %7)
ret i8* %14
16: ; preds = %0, %29
%17 = phi i64 [ %30, %29 ], [ 0, %0 ]
%18 = getelementptr inbounds [5 x [1005 x i8]], [5 x [1005 x i8]]* %2, i64 0, i64 %17, i64 0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i8* @strcat(i8* %7, i8* %18)
%21 = load i32, i32* %1
%22 = add nsw i32 %21, -1
%23 = zext i32 %22 to i64
%24 = icmp eq i64 %17, %23
br i1 %24, label %29, label %25
25: ; preds = %16
%26 = call i64 @strlen(i8* %7)
%27 = getelementptr [1005 x i8], [1005 x i8]* %3, i64 0, i64 %26
%28 = bitcast i8* %27 to i16*
store i16 10, i16* %28
br label %29
29: ; preds = %16, %25
%30 = add nuw nsw i64 %17, 1
%31 = sext i32 %21 to i64
%32 = icmp slt i64 %30, %31
br i1 %32, label %16, label %11
}