#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 */
char *calloc(int, int);
int /*<<< orphan*/ fail(int, char *, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
char *get_line(FILE *fp) {
  if (2 < 2) {
    fail(-1, "get_line", "MAX_BUF is too small.");
  }
  char *line = calloc(2, sizeof(char));
  int line_size = 2;
  char buf[2];
  while (fgets(buf, 2, fp) != NULL) {
    if (strlen(buf) + strlen(line) + 1 >= line_size) {
      line_size += strlen(buf);
      line = (char *)realloc(line, line_size * sizeof(char));
    }
    strcat(line, buf);
    if (strstr(line, "\n") != NULL) {
      strtok(line, "\n");
      break;
    }
  }
  return (line);
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1241 <get_line+0xd1>
lea    -0x16(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jl     1200 <get_line+0x90>
lea    -0x16(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x16(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     123c <get_line+0xcc>
mov    -0x10(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   1070 <strtok@plt>
jmp    1241 <get_line+0xd1>
jmp    1196 <get_line+0x26>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x2,%r12d
mov    $0x2,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
lea    0xe(%rsp),%r15
jmp    11bd <get_line+0x4d>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1209 <get_line+0x99>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1218 <get_line+0xa8>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
add    $0x1,%eax
cmp    %r12d,%eax
jl     11a0 <get_line+0x30>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %eax,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1070 <realloc@plt>
mov    %rax,%rbx
jmp    11a0 <get_line+0x30>
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i8* @get_line(i32* nocapture %0) {
%2 = alloca [2 x i8]
%3 = tail call dereferenceable_or_null(2) i8* @calloc(i32 2, i32 1)
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %21, %1
%6 = phi i8* [ %3, %1 ], [ %22, %21 ]
%7 = phi i32 [ 2, %1 ], [ %23, %21 ]
%8 = call i32* @fgets(i8* %4, i32 2, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %29, label %10
10: ; preds = %5
%11 = call i32 @strlen(i8* %4)
%12 = call i32 @strlen(i8* %6)
%13 = add i32 %11, 1
%14 = add i32 %13, %12
%15 = icmp slt i32 %14, %7
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = call i32 @strlen(i8* %4)
%18 = add nsw i32 %17, %7
%19 = call i64 @realloc(i8* %6, i32 %18)
%20 = inttoptr i64 %19 to i8*
br label %21
21: ; preds = %16, %10
%22 = phi i8* [ %20, %16 ], [ %6, %10 ]
%23 = phi i32 [ %18, %16 ], [ %7, %10 ]
%24 = call i32 @strcat(i8* %22, i8* %4)
%25 = call i8* @strchr(i8* dereferenceable(1) %22, i32 10)
%26 = icmp eq i8* %25, null
br i1 %26, label %5, label %27
27: ; preds = %21
%28 = call i32 @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %5, %27
%30 = phi i8* [ %22, %27 ], [ %6, %5 ]
ret i8* %30
}