#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*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
char *malloc(int);
scalar_t__ memcmp(char *, char *, int);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
char *getCorrect(FILE *fp) {
  static char *data = NULL;
  static size_t capacity = 0;
  char line[1000];
  size_t chars_read = 0;
  size_t tot_chars_read = 0;
  if (!data) {
    data = malloc(1000);
    capacity = 1000;
  }
  *data = 0;
  while ((fgets(line, 1000, fp))) {
    if ((memcmp(line, "---", 3) == 0))
      break;
    chars_read = strlen(line);
    tot_chars_read += chars_read;
    if (tot_chars_read + 100 >= capacity)
      data = realloc(data, capacity += 1000);
    strcat(data, line);
  }
  return data;
}


x86 assembly (clang, -O0):
<getCorrect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x3f8(%rbp)
movq   $0x0,-0x400(%rbp)
cmpq   $0x0,0x2ecb(%rip)
jne    11af <getCorrect+0x4f>
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,0x2eb4(%rip)
movq   $0x3e8,0x2eb1(%rip)
mov    0x2ea2(%rip),%rax
movb   $0x0,(%rax)
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     127f <getCorrect+0x11f>
lea    -0x3f0(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11ff <getCorrect+0x9f>
jmp    127f <getCorrect+0x11f>
lea    -0x3f0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x3f8(%rbp)
mov    -0x3f8(%rbp),%rax
add    -0x400(%rbp),%rax
mov    %rax,-0x400(%rbp)
mov    -0x400(%rbp),%rax
add    $0x64,%rax
cmp    0x2e27(%rip),%rax
jb     1267 <getCorrect+0x107>
mov    0x2e12(%rip),%rdi
mov    0x2e13(%rip),%rsi
add    $0x3e8,%rsi
mov    %rsi,0x2e05(%rip)
call   1070 <realloc@plt>
mov    %rax,0x2df1(%rip)
mov    0x2dea(%rip),%rdi
lea    -0x3f0(%rbp),%rsi
call   1080 <strcat@plt>
jmp    11b9 <getCorrect+0x59>
mov    0x2dd2(%rip),%rax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCorrect>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r15
mov    0x2ede(%rip),%rax
test   %rax,%rax
jne    119b <getCorrect+0x3b>
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,0x2ec8(%rip)
movq   $0x3e8,0x2ec5(%rip)
movb   $0x0,(%rax)
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1249 <getCorrect+0xe9>
xor    %ebx,%ebx
lea    0xe40(%rip),%r14
mov    %rsp,%r12
jmp    11f0 <getCorrect+0x90>
cs nopw 0x0(%rax,%rax,1)
nop
add    %r13,%rbx
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1249 <getCorrect+0xe9>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1249 <getCorrect+0xe9>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
add    %rbx,%rax
add    $0x64,%rax
mov    0x2e42(%rip),%rsi
mov    0x2e33(%rip),%rdi
cmp    %rsi,%rax
jb     11d0 <getCorrect+0x70>
add    $0x3e8,%rsi
mov    %rsi,0x2e28(%rip)
call   1070 <realloc@plt>
mov    %rax,%rdi
mov    %rax,0x2e11(%rip)
jmp    11d0 <getCorrect+0x70>
mov    0x2e08(%rip),%rax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@getCorrect.data = internal global i8* null
@getCorrect.capacity = internal global i64 0
@.str = [4 x i8] c"---\00"
define i8* @getCorrect(i32* %0) {
%2 = alloca i32*
%3 = alloca [1000 x i8]
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %2
store i64 0, i64* %4
store i64 0, i64* %5
%6 = load i8*, i8** @getCorrect.data
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i8* @malloc(i32 1000)
store i8* %9, i8** @getCorrect.data
store i64 1000, i64* @getCorrect.capacity
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** @getCorrect.data
store i8 0, i8* %11
br label %12
12: ; preds = %37, %10
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i64 @fgets(i8* %13, i32 1000, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%19 = call i64 @memcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %41
22: ; preds = %17
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %4
%25 = load i64, i64* %4
%26 = load i64, i64* %5
%27 = add i64 %26, %25
store i64 %27, i64* %5
%28 = load i64, i64* %5
%29 = add i64 %28, 100
%30 = load i64, i64* @getCorrect.capacity
%31 = icmp uge i64 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %22
%33 = load i8*, i8** @getCorrect.data
%34 = load i64, i64* @getCorrect.capacity
%35 = add i64 %34, 1000
store i64 %35, i64* @getCorrect.capacity
%36 = call i8* @realloc(i8* %33, i64 %35)
store i8* %36, i8** @getCorrect.data
br label %37
37: ; preds = %32, %22
%38 = load i8*, i8** @getCorrect.data
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
br label %12
41: ; preds = %21, %12
%42 = load i8*, i8** @getCorrect.data
ret i8* %42
}

LLVM IR (-O2):
@getCorrect.data = internal unnamed_addr global i8* null
@getCorrect.capacity = internal unnamed_addr global i64 0
@.str = [4 x i8] c"---\00"
define i8* @getCorrect(i32* nocapture %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = load i8*, i8** @getCorrect.data
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
store i8* %7, i8** @getCorrect.data
store i64 1000, i64* @getCorrect.capacity
br label %8
8: ; preds = %6, %1
%9 = phi i8* [ %7, %6 ], [ %4, %1 ]
store i8 0, i8* %9
%10 = call i64 @fgets(i8* %3, i32 1000, i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %8, %26
%13 = phi i64 [ %18, %26 ], [ 0, %8 ]
%14 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %12
%17 = call i64 @strlen(i8* %3)
%18 = add i64 %17, %13
%19 = add i64 %18, 100
%20 = load i64, i64* @getCorrect.capacity
%21 = icmp ult i64 %19, %20
%22 = load i8*, i8** @getCorrect.data
br i1 %21, label %26, label %23
23: ; preds = %16
%24 = add i64 %20, 1000
store i64 %24, i64* @getCorrect.capacity
%25 = call i8* @realloc(i8* %22, i64 %24)
store i8* %25, i8** @getCorrect.data
br label %26
26: ; preds = %16, %23
%27 = phi i8* [ %25, %23 ], [ %22, %16 ]
%28 = call i32 @strcat(i8* %27, i8* %3)
%29 = call i64 @fgets(i8* %3, i32 1000, i32* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %12
31: ; preds = %26, %12, %8
%32 = load i8*, i8** @getCorrect.data
ret i8* %32
}