#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 */

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ puts(char *);
char *realloc(char *, int);
char *nome(char text[]) {
  int n3 = 0;
  int n2 = 0;
  char *n = NULL;
  while ((n2 = getchar()) != '\0' && n2 != EOF) {
    n3++;
    n = realloc(n, n3);
    if (n == NULL) {
      puts("Erro ao realocar!");
      exit(0);
    }
    *(n + (n3 - 1)) = n2;
  }
  *(n + n3) = '\0';
  return n;
}


x86 assembly (clang, -O0):
<nome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     118e <nome+0x4e>
mov    -0x10(%rbp),%eax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119e <nome+0x5e>
jmp    11ef <nome+0xaf>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d5 <nome+0x95>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1162 <nome+0x22>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nome>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r14d
mov    0x2e90(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    0x1(%rbp),%esi
mov    %rbx,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11a2 <nome+0x62>
mov    %rax,%rbx
mov    %r14b,(%rax,%rbp,1)
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%rbp
test   %eax,%eax
je     118e <nome+0x4e>
mov    %eax,%r14d
cmp    (%r15),%eax
jne    1160 <nome+0x20>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [18 x i8] c"Erro ao realocar!\00"
define i8* @nome(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i8* null, i8** %5
br label %6
6: ; preds = %26, %1
%7 = call i32 (...) @getchar()
store i32 %7, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %4
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %34
15: ; preds = %13
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load i8*, i8** %5
%19 = load i32, i32* %3
%20 = call i8* @realloc(i8* %18, i32 %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %15
%27 = load i32, i32* %4
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %5
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 %28, i8* %33
br label %6
34: ; preds = %13
%35 = load i8*, i8** %5
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %5
ret i8* %39
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [18 x i8] c"Erro ao realocar!\00"
define i8* @nome(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @getchar()
%3 = icmp ne i32 %2, 0
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %2, %4
br label %6
6: ; preds = %1, %17
%7 = phi i64 [ 0, %1 ], [ %10, %17 ]
%8 = phi i32 [ %2, %1 ], [ %20, %17 ]
%9 = phi i8* [ null, %1 ], [ %12, %17 ]
%10 = add nuw i64 %7, 1
%11 = trunc i64 %10 to i32
%12 = tail call i8* @realloc(i8* %9, i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %6
%18 = trunc i32 %8 to i8
%19 = getelementptr inbounds i8, i8* %12, i64 %7
store i8 %18, i8* %19
%20 = tail call i32 (...) @getchar()
%21 = icmp ne i32 %20, 0
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %20, %22
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %6, label %25
25: ; preds = %17
%26 = and i64 %10, 4294967295
%27 = getelementptr inbounds i8, i8* %12, i64 %26
store i8 0, i8* %27
ret i8* %12
}