#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 */
scalar_t__ calloc(int, int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *getInputFromUserWhatEver() {
  char buffer[100];
  int contentSize = 1;
  char *content = (char *)calloc(100, sizeof(char));
  printf("type something:>");
  while (fgets(buffer, 100, stdin)) {
    if (strncmp(buffer, "quit", strlen("quit")) == 0) {
      break;
    }
    contentSize = contentSize + strlen(buffer);
    content = (char *)realloc(content, contentSize);
    strcat(content, buffer);
    printf("Keep Typing (quit is exiting program)");
  }
  return content;
}


x86 assembly (clang, -O0):
<getInputFromUserWhatEver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x1,-0x74(%rbp)
mov    $0x64,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x80(%rbp)
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     124a <getInputFromUserWhatEver+0xda>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xe3d(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
lea    0xe28(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fd <getInputFromUserWhatEver+0x8d>
jmp    124a <getInputFromUserWhatEver+0xda>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x74(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x74(%rbp),%esi
call   1080 <realloc@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <strcat@plt>
lea    0xdd6(%rip),%rdi
call   1050 <printf@plt>
jmp    11a1 <getInputFromUserWhatEver+0x31>
mov    -0x80(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInputFromUserWhatEver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    $0x1,%ebp
mov    $0x64,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e40(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     122a <getInputFromUserWhatEver+0xba>
lea    0xe4c(%rip),%r14
mov    %rsp,%r15
lea    0xe47(%rip),%r12
nop
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     122a <getInputFromUserWhatEver+0xba>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <getInputFromUserWhatEver+0x60>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"type something:>\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [38 x i8] c"Keep Typing (quit is exiting program)\00"
define i8* @getInputFromUserWhatEver() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = alloca i8*
store i32 1, i32* %2
%4 = call i64 @calloc(i32 100, i32 1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %18, %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @fgets(i8* %8, i32 100, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %31
18: ; preds = %12
%19 = load i32, i32* %2
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
store i32 %22, i32* %2
%23 = load i8*, i8** %3
%24 = load i32, i32* %2
%25 = call i64 @realloc(i8* %23, i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %7
31: ; preds = %17, %7
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@.str = [17 x i8] c"type something:>\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [38 x i8] c"Keep Typing (quit is exiting program)\00"
define i8* @getInputFromUserWhatEver() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @calloc(i32 100, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i64 @fgets(i8* %2, i32 100, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %0, %15
%10 = phi i8* [ %19, %15 ], [ %4, %0 ]
%11 = phi i32 [ %17, %15 ], [ 1, %0 ]
%12 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %9
%16 = call i32 @strlen(i8* %2)
%17 = add nsw i32 %16, %11
%18 = call i64 @realloc(i8* %10, i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @strcat(i8* %19, i8* %2)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = call i64 @fgets(i8* %2, i32 100, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %9
25: ; preds = %15
%26 = inttoptr i64 %18 to i8*
br label %27
27: ; preds = %9, %25, %0
%28 = phi i8* [ %4, %0 ], [ %26, %25 ], [ %10, %9 ]
ret i8* %28
}