#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *space(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
scalar_t__ xrealloc(char *, scalar_t__);
char *get_line(FILE *fp) {
  char s[512], *line, *cp;
  line = NULL;
  do {
    if (fgets(s, 512, fp) == NULL)
      break;
    cp = strchr(s, '\n');
    if (cp != NULL)
      *cp = '\0';
    if (line == NULL)
      line = space(strlen(s) + 1);
    else
      line = (char *)xrealloc(line, strlen(s) + strlen(line) + 1);
    strcat(line, s);
  } while (cp == NULL);
  return line;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    119e <get_line+0x3e>
jmp    126f <get_line+0x10f>
lea    -0x210(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     11ce <get_line+0x6e>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x218(%rbp)
jne    1200 <get_line+0xa0>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1030 <space@plt>
mov    %rax,-0x218(%rbp)
jmp    124e <get_line+0xee>
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x230(%rbp)
mov    -0x218(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x230(%rbp),%rsi
mov    -0x228(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1060 <xrealloc@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1080 <strcat@plt>
cmpq   $0x0,-0x220(%rbp)
je     117a <get_line+0x1a>
mov    -0x218(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
xor    %r12d,%r12d
mov    %rsp,%r15
jmp    119f <get_line+0x3f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <space@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
test   %r13,%r13
jne    11f8 <get_line+0x98>
mov    %r15,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11f8 <get_line+0x98>
mov    %r15,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,%r13
test   %rax,%rax
je     11ce <get_line+0x6e>
movb   $0x0,0x0(%r13)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
test   %r12,%r12
je     1180 <get_line+0x20>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rsi
add    $0x1,%rsi
mov    %r12,%rdi
call   1060 <xrealloc@plt>
jmp    118c <get_line+0x2c>
mov    %r12,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_line(i32* %0) {
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %2
store i8* null, i8** %4
br label %6
6: ; preds = %41, %1
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i32* @fgets(i8* %7, i32 512, i32* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %6
br label %44
12: ; preds = %6
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = call i8* @strchr(i8* %13, i8 signext 10)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i8*, i8** %5
store i8 0, i8* %18
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i8* @space(i64 %25)
store i8* %26, i8** %4
br label %37
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = load i8*, i8** %4
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %30, %32
%34 = add nsw i64 %33, 1
%35 = call i64 @xrealloc(i8* %28, i64 %34)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %4
br label %37
37: ; preds = %27, %22
%38 = load i8*, i8** %4
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
br label %41
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = icmp eq i8* %42, null
br i1 %43, label %6, label %44
44: ; preds = %41, %11
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
define i8* @get_line(i32* nocapture %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %24, %1
%5 = phi i8* [ null, %1 ], [ %25, %24 ]
%6 = call i32* @fgets(i8* %3, i32 512, i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %27, label %8
8: ; preds = %4
%9 = call i8* @strchr(i8* %3, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 0, i8* %9
br label %12
12: ; preds = %11, %8
%13 = icmp eq i8* %5, null
%14 = call i64 @strlen(i8* %3)
br i1 %13, label %15, label %18
15: ; preds = %12
%16 = add nsw i64 %14, 1
%17 = call i8* @space(i64 %16)
br label %24
18: ; preds = %12
%19 = call i64 @strlen(i8* %5)
%20 = add i64 %14, 1
%21 = add i64 %20, %19
%22 = call i64 @xrealloc(i8* %5, i64 %21)
%23 = inttoptr i64 %22 to i8*
br label %24
24: ; preds = %18, %15
%25 = phi i8* [ %17, %15 ], [ %23, %18 ]
%26 = call i32 @strcat(i8* %25, i8* %3)
br i1 %10, label %4, label %27
27: ; preds = %4, %24
%28 = phi i8* [ %5, %4 ], [ %25, %24 ]
ret i8* %28
}