#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*/ exit(int);
int /*<<< orphan*/ free(char *);
char getchar();
int /*<<< orphan*/ isgraph(int);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, size_t);
int strlen(char *);
void getString(char **wordPtr) {
  int length = strlen(*wordPtr) + 1;
  char *temp = NULL;
  int c = '\n';
  size_t max_size = length;
  int i = 0;
  while (!isgraph(c = getchar()))
    ;
  do {
    (*wordPtr)[i++] = (char)c;
    if (i == max_size) {
      max_size *= 2;
      temp = (char *)realloc(*wordPtr, max_size);
      if (!temp) {
        free(*wordPtr);
        printf("Not enough space to reallocate the character buffer. "
               "Exiting...\n");
        exit(1);
      }
      *wordPtr = temp;
    }
  } while (!isspace(c = getchar()));
  (*wordPtr)[i] = 0;
  if (c != '\n') {
    while (getchar() != '\n')
      ;
  }
}


x86 assembly (clang, -O0):
<getString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xa,-0x1c(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%edi
mov    %edi,-0x1c(%rbp)
call   10a0 <isgraph@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e3 <getString+0x63>
jmp    11e8 <getString+0x68>
jmp    11bc <getString+0x3c>
jmp    11ed <getString+0x6d>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1270 <getString+0xf0>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1265 <getString+0xe5>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    0xdaa(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1275 <getString+0xf5>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%edi
mov    %edi,-0x1c(%rbp)
call   1060 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ed <getString+0x6d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0xa,-0x1c(%rbp)
je     12d2 <getString+0x152>
jmp    12b5 <getString+0x135>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12cd <getString+0x14d>
jmp    12b5 <getString+0x135>
jmp    12d2 <getString+0x152>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   10a0 <isgraph@plt>
test   %eax,%eax
je     11a0 <getString+0x20>
movslq %ebp,%r15
xor    %ebp,%ebp
jmp    11d5 <getString+0x55>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1060 <isspace@plt>
test   %eax,%eax
jne    11fc <getString+0x7c>
mov    (%r14),%rax
mov    %bl,(%rax,%rbp,1)
add    $0x1,%rbp
cmp    %r15,%rbp
jne    11c0 <getString+0x40>
add    %r15,%r15
mov    (%r14),%rdi
mov    %r15,%rsi
call   1080 <realloc@plt>
test   %rax,%rax
je     1226 <getString+0xa6>
mov    %rax,(%r14)
jmp    11c0 <getString+0x40>
mov    %ebp,%eax
mov    (%r14),%rcx
movb   $0x0,(%rcx,%rax,1)
cmp    $0xa,%bl
je     121b <getString+0x9b>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1210 <getString+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rdi
call   1030 <free@plt>
lea    0xdcb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [65 x i8] c"Not enough space to reallocate the character buffer. Exiting...\0A\00"
define void @getString(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i8** %0, i8*** %2
%8 = load i8**, i8*** %2
%9 = load i8*, i8** %8
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
store i8* null, i8** %4
store i32 10, i32* %5
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
store i64 %13, i64* %6
store i32 0, i32* %7
br label %14
14: ; preds = %20, %1
%15 = call signext i8 (...) @getchar()
%16 = sext i8 %15 to i32
store i32 %16, i32* %5
%17 = call i32 @isgraph(i32 %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %21
20: ; preds = %14
br label %14
21: ; preds = %14
br label %22
22: ; preds = %55, %21
%23 = load i32, i32* %5
%24 = trunc i32 %23 to i8
%25 = load i8**, i8*** %2
%26 = load i8*, i8** %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %24, i8* %30
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = load i64, i64* %6
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %54
35: ; preds = %22
%36 = load i64, i64* %6
%37 = mul i64 %36, 2
store i64 %37, i64* %6
%38 = load i8**, i8*** %2
%39 = load i8*, i8** %38
%40 = load i64, i64* %6
%41 = call i64 @realloc(i8* %39, i64 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = icmp ne i8* %43, null
br i1 %44, label %51, label %45
45: ; preds = %35
%46 = load i8**, i8*** %2
%47 = load i8*, i8** %46
%48 = call i32 @free(i8* %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %35
%52 = load i8*, i8** %4
%53 = load i8**, i8*** %2
store i8* %52, i8** %53
br label %54
54: ; preds = %51, %22
br label %55
55: ; preds = %54
%56 = call signext i8 (...) @getchar()
%57 = sext i8 %56 to i32
store i32 %57, i32* %5
%58 = call i32 @isspace(i32 %57)
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br i1 %60, label %22, label %61
61: ; preds = %55
%62 = load i8**, i8*** %2
%63 = load i8*, i8** %62
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i32, i32* %5
%68 = icmp ne i32 %67, 10
br i1 %68, label %69, label %76
69: ; preds = %61
br label %70
70: ; preds = %74, %69
%71 = call signext i8 (...) @getchar()
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 10
br i1 %73, label %74, label %75
74: ; preds = %70
br label %70
75: ; preds = %70
br label %76
76: ; preds = %75, %61
ret void
}

LLVM IR (-O2):
@str = [64 x i8] c"Not enough space to reallocate the character buffer. Exiting...\00"
define void @getString(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @strlen(i8* %2)
%4 = add nsw i32 %3, 1
br label %5
5: ; preds = %5, %1
%6 = tail call signext i8 (...) @getchar()
%7 = sext i8 %6 to i32
%8 = tail call i32 @isgraph(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = sext i32 %4 to i64
br label %12
12: ; preds = %10, %32
%13 = phi i64 [ 0, %10 ], [ %17, %32 ]
%14 = phi i8 [ %6, %10 ], [ %34, %32 ]
%15 = phi i64 [ %11, %10 ], [ %33, %32 ]
%16 = load i8*, i8** %0
%17 = add nuw i64 %13, 1
%18 = getelementptr inbounds i8, i8* %16, i64 %13
store i8 %14, i8* %18
%19 = icmp eq i64 %15, %17
br i1 %19, label %20, label %32
20: ; preds = %12
%21 = shl i64 %15, 1
%22 = load i8*, i8** %0
%23 = tail call i64 @realloc(i8* %22, i64 %21)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %0
%27 = tail call i32 @free(i8* %26)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = inttoptr i64 %23 to i8*
store i8* %31, i8** %0
br label %32
32: ; preds = %12, %30
%33 = phi i64 [ %21, %30 ], [ %15, %12 ]
%34 = tail call signext i8 (...) @getchar()
%35 = sext i8 %34 to i32
%36 = tail call i32 @isspace(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %12, label %38
38: ; preds = %32
%39 = and i64 %17, 4294967295
%40 = load i8*, i8** %0
%41 = getelementptr inbounds i8, i8* %40, i64 %39
store i8 0, i8* %41
%42 = icmp eq i8 %34, 10
br i1 %42, label %46, label %43
43: ; preds = %38, %43
%44 = tail call signext i8 (...) @getchar()
%45 = icmp eq i8 %44, 10
br i1 %45, label %46, label %43
46: ; preds = %43, %38
ret void
}