#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 *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strchr(char *, char);
int get_line(char **line, FILE *fp) {
  int tam = 32;
  int start = 0;
  if ((*line = (char *)malloc(tam)) == NULL) {
    fprintf(stderr, "Erro: malloc line\n");
    exit(1);
  }
  while (fgets(*line + start, tam, fp) != NULL) {
    if (strchr(*line, '\n') != NULL)
      return 1;
    start += tam - 1;
    *line = (char *)realloc(*line, start + 1 + tam);
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x20,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11b6 <get_line+0x56>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11bb <get_line+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1236 <get_line+0xd6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1206 <get_line+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    123d <get_line+0xdd>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
add    -0x1c(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11bb <get_line+0x5b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11f0 <get_line+0x90>
mov    %rax,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11e2 <get_line+0x82>
mov    $0x1f,%ebp
nop
mov    (%rbx),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    11dc <get_line+0x7c>
mov    (%rbx),%rdi
lea    0x21(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,(%rbx)
lea    (%rax,%rbp,1),%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1f,%rbp
test   %rax,%rax
jne    11a0 <get_line+0x40>
jmp    11e2 <get_line+0x82>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Erro: malloc line\0A\00"
define i32 @get_line(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 32, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %6
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = load i8**, i8*** %4
store i8* %10, i8** %11
%12 = icmp eq i8* %10, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %34, %17
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %6
%25 = load i32*, i32** %5
%26 = call i32* @fgets(i8* %23, i32 %24, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %48
28: ; preds = %18
%29 = load i8**, i8*** %4
%30 = load i8*, i8** %29
%31 = call i32* @strchr(i8* %30, i8 signext 10)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %3
br label %49
34: ; preds = %28
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, 1
%37 = load i32, i32* %7
%38 = add nsw i32 %37, %36
store i32 %38, i32* %7
%39 = load i8**, i8*** %4
%40 = load i8*, i8** %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = load i32, i32* %6
%44 = add nsw i32 %42, %43
%45 = call i64 @realloc(i8* %40, i32 %44)
%46 = inttoptr i64 %45 to i8*
%47 = load i8**, i8*** %4
store i8* %46, i8** %47
br label %18
48: ; preds = %18
store i32 -1, i32* %3
br label %49
49: ; preds = %48, %33
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Erro: malloc line\0A\00"
define i32 @get_line(i8** nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %0
%5 = icmp eq i64 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32* @fgets(i8* %4, i32 32, i32* %1)
%8 = icmp eq i32* %7, null
br i1 %8, label %28, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %18
%14 = phi i64 [ %19, %18 ], [ 0, %6 ]
%15 = load i8*, i8** %0
%16 = tail call i32* @strchr(i8* %15, i8 signext 10)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = add nuw i64 %14, 31
%20 = load i8*, i8** %0
%21 = trunc i64 %14 to i32
%22 = add i32 %21, 64
%23 = tail call i64 @realloc(i8* %20, i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 %19
%26 = tail call i32* @fgets(i8* %25, i32 32, i32* %1)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %13
28: ; preds = %13, %18, %6
%29 = phi i32 [ -1, %6 ], [ -1, %18 ], [ 1, %13 ]
ret i32 %29
}