#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, int);
int scanf(char *, char *);
int main(void) {
  int size = 0;
  char *nome = malloc(2);
  while (1) {
    if ((scanf("%c", &nome[size])) == 1) {
      nome[size + 1] = '\0';
      if (nome[size] == '\n') {
        break;
      }
      nome = realloc(nome, ++size);
      if (nome == NULL) {
        printf("Ocorreu ualgum problema");
        break;
      }
    } else {
      printf("Ocorreu ualgum problema");
      break;
    }
  }
  printf("%s", nome);
  free(nome);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
add    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11f8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11bf <main+0x6f>
jmp    1210 <main+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f3 <main+0xa3>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1210 <main+0xc0>
jmp    120b <main+0xbb>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1210 <main+0xc0>
jmp    1174 <main+0x24>
mov    -0x10(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x1,%ebx
lea    0xe92(%rip),%r15
xchg   %ax,%ax
lea    (%r14,%rbx,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r15,%rdi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11ab <main+0x5b>
movb   $0x0,(%r14,%rbx,1)
cmpb   $0xa,-0x1(%r14,%rbx,1)
je     11b9 <main+0x69>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <main+0x20>
xor    %r14d,%r14d
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [24 x i8] c"Ocorreu ualgum problema\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i8* @malloc(i32 2)
store i8* %4, i8** %3
br label %5
5: ; preds = %0, %38
%6 = load i8*, i8** %3
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %36
12: ; preds = %5
%13 = load i8*, i8** %3
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %12
br label %39
26: ; preds = %12
%27 = load i8*, i8** %3
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
%30 = call i8* @realloc(i8* %27, i32 %29)
store i8* %30, i8** %3
%31 = load i8*, i8** %3
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %39
35: ; preds = %26
br label %38
36: ; preds = %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %39
38: ; preds = %35
br label %5
39: ; preds = %36, %33, %25
%40 = load i8*, i8** %3
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %3
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [24 x i8] c"Ocorreu ualgum problema\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
br label %2
2: ; preds = %13, %0
%3 = phi i64 [ %9, %13 ], [ 0, %0 ]
%4 = phi i8* [ %15, %13 ], [ %1, %0 ]
%5 = getelementptr inbounds i8, i8* %4, i64 %3
%6 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = add nuw i64 %3, 1
%10 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 0, i8* %10
%11 = load i8, i8* %5
%12 = icmp eq i8 %11, 10
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = trunc i64 %9 to i32
%15 = tail call i8* @realloc(i8* %4, i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %2
17: ; preds = %2, %13
%18 = phi i8* [ null, %13 ], [ %4, %2 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %8, %17
%21 = phi i8* [ %18, %17 ], [ %4, %8 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = tail call i32 @free(i8* %21)
ret i32 0
}