#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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char getchar();
char *malloc(int);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, size_t);
char tolower(char);
void get_input(char **response_ptr, size_t *buff_size, FILE *stream) {
  char c;
  if (*response_ptr == NULL) {
    *response_ptr = malloc(128 * sizeof(char));
    *buff_size = 128;
  }
  size_t i = 0;
  while (1) {
    c = getchar();
    if (c == '\n') {
      (*response_ptr)[i] = '\0';
      break;
    }
    (*response_ptr)[i] = tolower(c);
    if (i == *buff_size - 1) {
      char *temp_ptr = NULL;
      temp_ptr = realloc(*response_ptr, *buff_size * 2);
      if (temp_ptr == NULL) {
        free(*response_ptr);
        perror("Realloc: ");
        exit(errno);
      }
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b1 <get_input+0x41>
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x80,(%rax)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11e4 <get_input+0x74>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    127f <get_input+0x10f>
movsbl -0x19(%rbp),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    126e <get_input+0xfe>
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
shl    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1269 <get_input+0xf9>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    126e <get_input+0xfe>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b9 <get_input+0x49>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmpq   $0x0,(%rdi)
jne    1195 <get_input+0x25>
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,(%r15)
movq   $0x80,(%r14)
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11af <get_input+0x3f>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
jmp    11cf <get_input+0x5f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     11a2 <get_input+0x32>
movsbl %al,%edi
call   1050 <tolower@plt>
mov    (%r15),%rcx
mov    %al,(%rcx,%rbx,1)
mov    (%r14),%rsi
lea    -0x1(%rsi),%rax
cmp    %rax,%rbx
jne    11c0 <get_input+0x50>
mov    (%r15),%rdi
add    %rsi,%rsi
call   1070 <realloc@plt>
test   %rax,%rax
jne    11c0 <get_input+0x50>
mov    (%r15),%rdi
call   1030 <free@plt>
lea    0xdf8(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"Realloc: \00"
@errno = global i32 0
define void @get_input(i8** %0, i64* %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i64
%9 = alloca i8*
store i8** %0, i8*** %4
store i64* %1, i64** %5
store i32* %2, i32** %6
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = call i8* @malloc(i32 128)
%15 = load i8**, i8*** %4
store i8* %14, i8** %15
%16 = load i64*, i64** %5
store i64 128, i64* %16
br label %17
17: ; preds = %13, %3
store i64 0, i64* %8
br label %18
18: ; preds = %17, %57
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %7
%20 = load i8, i8* %7
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = load i64, i64* %8
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
br label %60
28: ; preds = %18
%29 = load i8, i8* %7
%30 = call signext i8 @tolower(i8 signext %29)
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = load i64, i64* %8
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %30, i8* %34
%35 = load i64, i64* %8
%36 = load i64*, i64** %5
%37 = load i64, i64* %36
%38 = sub i64 %37, 1
%39 = icmp eq i64 %35, %38
br i1 %39, label %40, label %57
40: ; preds = %28
store i8* null, i8** %9
%41 = load i8**, i8*** %4
%42 = load i8*, i8** %41
%43 = load i64*, i64** %5
%44 = load i64, i64* %43
%45 = mul i64 %44, 2
%46 = call i8* @realloc(i8* %42, i64 %45)
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %56
49: ; preds = %40
%50 = load i8**, i8*** %4
%51 = load i8*, i8** %50
%52 = call i32 @free(i8* %51)
%53 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%54 = load i32, i32* @errno
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %40
br label %57
57: ; preds = %56, %28
%58 = load i64, i64* %8
%59 = add i64 %58, 1
store i64 %59, i64* %8
br label %18
60: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Realloc: \00"
@errno = global i32 0
define void @get_input(i8** nocapture %0, i64* nocapture %1, i32* nocapture readnone %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
store i8* %7, i8** %0
store i64 128, i64* %1
br label %8
8: ; preds = %6, %3
%9 = tail call signext i8 (...) @getchar()
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %35, %8
%12 = phi i64 [ 0, %8 ], [ %36, %35 ]
%13 = load i8*, i8** %0
%14 = getelementptr inbounds i8, i8* %13, i64 %12
store i8 0, i8* %14
ret void
15: ; preds = %8, %35
%16 = phi i8 [ %37, %35 ], [ %9, %8 ]
%17 = phi i64 [ %36, %35 ], [ 0, %8 ]
%18 = tail call signext i8 @tolower(i8 signext %16)
%19 = load i8*, i8** %0
%20 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 %18, i8* %20
%21 = load i64, i64* %1
%22 = add i64 %21, -1
%23 = icmp eq i64 %17, %22
br i1 %23, label %24, label %35
24: ; preds = %15
%25 = load i8*, i8** %0
%26 = shl i64 %21, 1
%27 = tail call i8* @realloc(i8* %25, i64 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8*, i8** %0
%31 = tail call i32 @free(i8* %30)
%32 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @errno
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %24, %15
%36 = add i64 %17, 1
%37 = tail call signext i8 (...) @getchar()
%38 = icmp eq i8 %37, 10
br i1 %38, label %11, label %15
}