#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *readOneLine(FILE *fin) {
  char tmp[512];
  char *string;
  int tmplength;
  int length = 0;
  int buffer = 512;
  if ((string = (char *)malloc(buffer * sizeof(char))) == NULL) {
    fprintf(stderr, "Could not initialize memory on line %d\n", 218);
    exit(2);
  }
  string[0] = '\0';
  while ((fgets(tmp, 512 - 1, fin)) != NULL) {
    tmplength = strlen(tmp);
    if (tmplength + length > buffer) {
      buffer = length + tmplength + 512;
      if ((string = (char *)realloc(string, buffer * sizeof(char))) == NULL) {
        exit(2);
      }
    }
    strcat(string, tmp);
    length += tmplength;
    if (strstr(tmp, "\n") != NULL) {
      break;
    }
  }
  return string;
}


x86 assembly (clang, -O0):
<readOneLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x220(%rbp)
movl   $0x200,-0x224(%rbp)
movslq -0x224(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    11ea <readOneLine+0x6a>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0xda,%edx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x218(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1ff,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12d9 <readOneLine+0x159>
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x21c(%rbp)
mov    -0x21c(%rbp),%eax
add    -0x220(%rbp),%eax
cmp    -0x224(%rbp),%eax
jle    128d <readOneLine+0x10d>
mov    -0x220(%rbp),%eax
add    -0x21c(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x224(%rbp)
mov    -0x218(%rbp),%rdi
movslq -0x224(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    1288 <readOneLine+0x108>
mov    $0x2,%edi
call   1090 <exit@plt>
jmp    128d <readOneLine+0x10d>
mov    -0x218(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x21c(%rbp),%eax
add    -0x220(%rbp),%eax
mov    %eax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12d4 <readOneLine+0x154>
jmp    12d9 <readOneLine+0x159>
jmp    11f4 <readOneLine+0x74>
mov    -0x218(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readOneLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
mov    $0x200,%r12d
mov    $0x200,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1238 <readOneLine+0xb8>
mov    %rax,%rbx
movb   $0x0,(%rax)
xor    %ebp,%ebp
mov    %rsp,%r15
jmp    11dd <readOneLine+0x5d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1225 <readOneLine+0xa5>
mov    %r15,%rdi
mov    $0x1ff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1225 <readOneLine+0xa5>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %eax,%ebp
cmp    %r12d,%ebp
jle    11c0 <readOneLine+0x40>
lea    0x200(%rbp),%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <readOneLine+0x40>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    $0xda,%edx
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Could not initialize memory on line %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @readOneLine(i32* %0) {
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %6
store i32 512, i32* %7
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 218)
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %1
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
br label %22
22: ; preds = %62, %19
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i32* @fgets(i8* %23, i32 511, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %63
27: ; preds = %22
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %7
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %51
35: ; preds = %27
%36 = load i32, i32* %6
%37 = load i32, i32* %5
%38 = add nsw i32 %36, %37
%39 = add nsw i32 %38, 512
store i32 %39, i32* %7
%40 = load i8*, i8** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = call i64 @realloc(i8* %40, i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %4
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %35
%49 = call i32 @exit(i32 2)
unreachable
50: ; preds = %35
br label %51
51: ; preds = %50, %27
%52 = load i8*, i8** %4
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%54 = call i32 @strcat(i8* %52, i8* %53)
%55 = load i32, i32* %5
%56 = load i32, i32* %6
%57 = add nsw i32 %56, %55
store i32 %57, i32* %6
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%59 = call i32* @strstr(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %62
61: ; preds = %51
br label %63
62: ; preds = %51
br label %22
63: ; preds = %61, %22
%64 = load i8*, i8** %4
ret i8* %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Could not initialize memory on line %d\0A\00"
define i8* @readOneLine(i32* nocapture %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 512)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 218)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %1
store i8 0, i8* %5
br label %12
12: ; preds = %29, %11
%13 = phi i8* [ %5, %11 ], [ %30, %29 ]
%14 = phi i32 [ 0, %11 ], [ %20, %29 ]
%15 = phi i32 [ 512, %11 ], [ %31, %29 ]
%16 = call i32* @fgets(i8* %3, i32 511, i32* %0)
%17 = icmp eq i32* %16, null
br i1 %17, label %35, label %18
18: ; preds = %12
%19 = call i32 @strlen(i8* %3)
%20 = add nsw i32 %19, %14
%21 = icmp sgt i32 %20, %15
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = add nsw i32 %20, 512
%24 = call i64 @realloc(i8* %13, i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %22, %18
%30 = phi i8* [ %25, %22 ], [ %13, %18 ]
%31 = phi i32 [ %23, %22 ], [ %15, %18 ]
%32 = call i32 @strcat(i8* %30, i8* %3)
%33 = call i8* @strchr(i8* %3, i32 10)
%34 = icmp eq i8* %33, null
br i1 %34, label %12, label %35
35: ; preds = %29, %12
%36 = phi i8* [ %30, %29 ], [ %13, %12 ]
ret i8* %36
}