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


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x228(%rbp)
movq   $0x0,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11a2 <get_line+0x52>
jmp    1289 <get_line+0x139>
lea    -0x210(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     11d2 <get_line+0x82>
mov    -0x220(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x224(%rbp),%eax
mov    %eax,-0x230(%rbp)
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x230(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x22c(%rbp)
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
cmp    -0x228(%rbp),%eax
jle    1252 <get_line+0x102>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xddc(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
movslq -0x228(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <xrealloc@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
movslq -0x224(%rbp),%rax
add    %rax,%rdi
lea    -0x210(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x22c(%rbp),%eax
mov    %eax,-0x224(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     117e <get_line+0x2e>
mov    -0x218(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdi,0x8(%rsp)
xor    %r14d,%r14d
lea    0x10(%rsp),%r15
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    1196 <get_line+0x46>
cs nopw 0x0(%rax,%rax,1)
movslq %r14d,%rdi
add    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %ebp,%r14d
test   %rbx,%rbx
jne    11fe <get_line+0xae>
mov    %r15,%rdi
mov    $0x200,%esi
mov    0x8(%rsp),%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fe <get_line+0xae>
mov    %r15,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c5 <get_line+0x75>
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    %r14d,%ebp
cmp    %r13d,%ebp
jl     1180 <get_line+0x30>
lea    0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe17(%rip),%xmm0
cvttsd2si %xmm0,%r13d
mov    %r12,%rdi
mov    %r13d,%esi
call   1050 <xrealloc@plt>
mov    %rax,%r12
jmp    1180 <get_line+0x30>
mov    %r12,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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 = %25, %1
%5 = phi i32 [ 0, %1 ], [ %16, %25 ]
%6 = phi i32 [ 0, %1 ], [ %26, %25 ]
%7 = phi i8* [ null, %1 ], [ %27, %25 ]
%8 = call i32* @fgets(i8* %3, i32 512, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %31, label %10
10: ; preds = %4
%11 = call i8* @strchr(i8* %3, i8 signext 10)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %11
br label %14
14: ; preds = %13, %10
%15 = call i32 @strlen(i8* %3)
%16 = add nsw i32 %15, %5
%17 = icmp slt i32 %16, %6
br i1 %17, label %25, label %18
18: ; preds = %14
%19 = add nsw i32 %16, 1
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 1.200000e+00
%22 = fptosi double %21 to i32
%23 = call i64 @xrealloc(i8* %7, i32 %22)
%24 = inttoptr i64 %23 to i8*
br label %25
25: ; preds = %18, %14
%26 = phi i32 [ %22, %18 ], [ %6, %14 ]
%27 = phi i8* [ %24, %18 ], [ %7, %14 ]
%28 = sext i32 %5 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = call i32 @strcat(i8* %29, i8* %3)
br i1 %12, label %4, label %31
31: ; preds = %4, %25
%32 = phi i8* [ %7, %4 ], [ %27, %25 ]
ret i8* %32
}