#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 */
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
char *realloc(char *, int);
void getString3(char **m) {
  int a = 0;
  char *k;
  char c;
  k = (char *)malloc(sizeof(char));
  printf("Enter your characters on one line, then hit <cr>: \n");
  printf("Input: ");
  while (1) {
    c = getchar();
    if (c == '\n')
      break;
    *(k + a) = c;
    a++;
    k = realloc(k, a + 1);
  }
  *(k + a) = '\0';
  *m = k;
}


x86 assembly (clang, -O0):
<getString3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1195 <getString3+0x55>
jmp    11c4 <getString3+0x84>
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1179 <getString3+0x39>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getString3>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11b6 <getString3+0x66>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rbx,%rsi
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
add    $0x2,%esi
mov    %r15,%rdi
call   1070 <realloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1190 <getString3+0x40>
mov    %ebx,%ebx
movb   $0x0,(%r15,%rbx,1)
mov    %r15,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Enter your characters on one line, then hit <cr>: \0A\00"
@.str.1 = [8 x i8] c"Input: \00"
define void @getString3(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i8** %0, i8*** %2
store i32 0, i32* %3
%6 = call i64 @malloc(i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %4
%8 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %1, %16
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %5
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %10
br label %28
16: ; preds = %10
%17 = load i8, i8* %5
%18 = load i8*, i8** %4
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = load i8*, i8** %4
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
%27 = call i8* @realloc(i8* %24, i32 %26)
store i8* %27, i8** %4
br label %10
28: ; preds = %15
%29 = load i8*, i8** %4
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %4
%34 = load i8**, i8*** %2
store i8* %33, i8** %34
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"Input: \00"
@str = [51 x i8] c"Enter your characters on one line, then hit <cr>: \00"
define void @getString3(i8** nocapture writeonly %0) {
%2 = tail call i64 @malloc(i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
br i1 %7, label %21, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %13, %8 ], [ 0, %1 ]
%10 = phi i8 [ %17, %8 ], [ %6, %1 ]
%11 = phi i8* [ %16, %8 ], [ %3, %1 ]
%12 = getelementptr inbounds i8, i8* %11, i64 %9
store i8 %10, i8* %12
%13 = add nuw i64 %9, 1
%14 = trunc i64 %9 to i32
%15 = add i32 %14, 2
%16 = tail call i8* @realloc(i8* %11, i32 %15)
%17 = tail call signext i8 (...) @getchar()
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %8
19: ; preds = %8
%20 = and i64 %13, 4294967295
br label %21
21: ; preds = %19, %1
%22 = phi i8* [ %3, %1 ], [ %16, %19 ]
%23 = phi i64 [ 0, %1 ], [ %20, %19 ]
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 0, i8* %24
store i8* %22, i8** %0
ret void
}