#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 EOF;
unsigned int UINT_MAX;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *);
char *realloc(char *, unsigned int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
char *getString(unsigned int limit) {
  char *buffer = NULL;
  unsigned int capacity = 0;
  unsigned int n = 0;
  int c;
  if (limit > UINT_MAX) {
    fprintf(stderr,
            "getString: Limit %i outside UINT boundaries? For no limit, pass "
            "the function a limit of (0).",
            limit);
    return NULL;
  }
  while ((c = fgetc(stdin)) != '\n' && c != EOF) {
    if (n + 1 > capacity) {
      if (limit > 0) {
        if (capacity == 0) {
          capacity = 32;
        } else if (capacity <= (UINT_MAX / 2) && capacity <= (limit / 2)) {
          capacity *= 2;
        } else if (capacity <= (UINT_MAX / 2) && capacity > (limit / 2)) {
          if (capacity == limit) {
            fprintf(stderr,
                    "\nCharacter limit of %i reached. About to retry...\n",
                    limit);
            sleep(1);
            printf("3...\n");
            sleep(1);
            printf("2...\n");
            sleep(1);
            printf("1...\n");
            sleep(1);
            printf("Retry: ");
            continue;
          }
          capacity = limit;
        } else {
          free(buffer);
          return NULL;
        }
      } else if (limit == 0) {
        if (capacity == 0) {
          capacity = 32;
        } else if (capacity <= (UINT_MAX / 2)) {
          capacity *= 2;
        } else if (capacity <= (UINT_MAX / 2)) {
          capacity = limit;
        } else {
          free(buffer);
          return NULL;
        }
      }
      char *temp = realloc(buffer, capacity * sizeof(char));
      if (temp == NULL) {
        free(buffer);
        return NULL;
      }
      buffer = temp;
    }
    buffer[n++] = (char)c;
  }
  if (n == 0 && c == EOF) {
    return NULL;
  }
  char *minimal = malloc((n + 1) * sizeof(char));
  strncpy(minimal, buffer, n);
  free(buffer);
  minimal[n] = '\0';
  return minimal;
}


x86 assembly (clang, -O0):
<getString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
jbe    11d8 <getString+0x58>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    14b8 <getString+0x338>
jmp    11dd <getString+0x5d>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x39(%rbp)
je     1210 <getString+0x90>
mov    -0x24(%rbp),%eax
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1220 <getString+0xa0>
jmp    144c <getString+0x2cc>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jbe    142e <getString+0x2ae>
cmpl   $0x0,-0xc(%rbp)
jbe    135e <getString+0x1de>
cmpl   $0x0,-0x1c(%rbp)
jne    124f <getString+0xcf>
movl   $0x20,-0x1c(%rbp)
jmp    1359 <getString+0x1d9>
mov    -0x1c(%rbp),%eax
mov    0x2d87(%rip),%rcx
mov    (%rcx),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     1285 <getString+0x105>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     1285 <getString+0x105>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1354 <getString+0x1d4>
mov    -0x1c(%rbp),%eax
mov    0x2d51(%rip),%rcx
mov    (%rcx),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     1339 <getString+0x1b9>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jbe    1339 <getString+0x1b9>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    132e <getString+0x1ae>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xd91(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xdae(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xd9e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xd8e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xd7e(%rip),%rdi
call   1050 <printf@plt>
jmp    11dd <getString+0x5d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    134f <getString+0x1cf>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    14b8 <getString+0x338>
jmp    1354 <getString+0x1d4>
jmp    1359 <getString+0x1d9>
jmp    13ef <getString+0x26f>
cmpl   $0x0,-0xc(%rbp)
jne    13ea <getString+0x26a>
cmpl   $0x0,-0x1c(%rbp)
jne    137e <getString+0x1fe>
movl   $0x20,-0x1c(%rbp)
jmp    13e5 <getString+0x265>
mov    -0x1c(%rbp),%eax
mov    0x2c58(%rip),%rcx
mov    (%rcx),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     13a3 <getString+0x223>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13e0 <getString+0x260>
mov    -0x1c(%rbp),%eax
mov    0x2c33(%rip),%rcx
mov    (%rcx),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
ja     13c5 <getString+0x245>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    13db <getString+0x25b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    14b8 <getString+0x338>
jmp    13e0 <getString+0x260>
jmp    13e5 <getString+0x265>
jmp    13ea <getString+0x26a>
jmp    13ef <getString+0x26f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1426 <getString+0x2a6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    14b8 <getString+0x338>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11dd <getString+0x5d>
cmpl   $0x0,-0x20(%rbp)
jne    1475 <getString+0x2f5>
mov    -0x24(%rbp),%eax
mov    0x2b78(%rip),%rcx
cmp    (%rcx),%eax
jne    1475 <getString+0x2f5>
movq   $0x0,-0x8(%rbp)
jmp    14b8 <getString+0x338>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r13d
mov    0x2e38(%rip),%rax
cmp    %edi,(%rax)
jae    11cb <getString+0x3b>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    %r13d,%edx
call   1080 <fprintf@plt>
xor    %ebp,%ebp
jmp    13fb <getString+0x26b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <fgetc@plt>
xor    %r14d,%r14d
mov    0x2df5(%rip),%rcx
mov    (%rcx),%ecx
cmp    $0xa,%eax
mov    %eax,0x4(%rsp)
je     138f <getString+0x1ff>
cmp    %ecx,%eax
je     1399 <getString+0x209>
mov    %r13d,%r12d
shr    %r12d
xor    %r15d,%r15d
xor    %ebp,%ebp
xor    %r14d,%r14d
mov    %r14d,%ebx
mov    %r15,0x8(%rsp)
mov    %rbx,%rax
mov    %rbx,0x10(%rsp)
lea    0x1(%rbx),%r14d
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
mov    0x2db7(%rip),%r15
nopl   0x0(%rax)
cmp    %ebp,%r14d
jbe    1313 <getString+0x183>
test   %r13d,%r13d
je     131a <getString+0x18a>
test   %ebp,%ebp
je     132b <getString+0x19b>
mov    (%r15),%ecx
shr    %ecx
cmp    %r12d,%ebp
ja     125c <getString+0xcc>
cmp    %ecx,%ebp
jbe    1332 <getString+0x1a2>
cmp    %r12d,%ebp
jbe    13a3 <getString+0x213>
cmp    %ecx,%ebp
ja     13a3 <getString+0x213>
cmp    %r13d,%ebp
jne    133a <getString+0x1aa>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
mov    %r13d,%edx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xdf9(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xde8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xdd7(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xdaf(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   1070 <fgetc@plt>
mov    0x2cdd(%rip),%rcx
mov    (%rcx),%ecx
cmp    $0xa,%eax
je     13b1 <getString+0x221>
cmp    %ecx,%eax
jne    1230 <getString+0xa0>
jmp    13b1 <getString+0x221>
mov    0x8(%rsp),%r15
jmp    135b <getString+0x1cb>
test   %ebp,%ebp
je     132b <getString+0x19b>
mov    (%r15),%eax
shr    %eax
cmp    %eax,%ebp
ja     13a3 <getString+0x213>
add    %ebp,%ebp
jmp    133d <getString+0x1ad>
mov    $0x20,%ebp
jmp    133d <getString+0x1ad>
add    %ebp,%ebp
mov    %eax,0x4(%rsp)
jmp    133d <getString+0x1ad>
mov    %r13d,%ebp
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   10a0 <realloc@plt>
mov    %rbx,%rdi
mov    %rax,%r15
test   %rax,%rax
mov    0x4(%rsp),%ebx
je     13a8 <getString+0x218>
mov    0x10(%rsp),%eax
mov    %bl,(%r15,%rax,1)
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   1070 <fgetc@plt>
mov    %eax,%edx
mov    0x2c5e(%rip),%rax
mov    (%rax),%ecx
cmp    $0xa,%edx
mov    %edx,0x4(%rsp)
je     139c <getString+0x20c>
cmp    %ecx,%edx
jne    1208 <getString+0x78>
jmp    139c <getString+0x20c>
xor    %r15d,%r15d
test   %r14d,%r14d
je     13c7 <getString+0x237>
jmp    13d1 <getString+0x241>
xor    %r15d,%r15d
test   %r14d,%r14d
je     13c7 <getString+0x237>
jmp    13d1 <getString+0x241>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    13fb <getString+0x26b>
mov    0x10(%rsp),%rbx
mov    %ebx,%r14d
mov    0x8(%rsp),%r15
mov    %eax,0x4(%rsp)
test   %r14d,%r14d
jne    13d1 <getString+0x241>
cmp    %ecx,0x4(%rsp)
jne    13d1 <getString+0x241>
xor    %ebp,%ebp
jmp    13fb <getString+0x26b>
lea    0x1(%r14),%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@UINT_MAX = global i32 0
@stderr = global i32 0
@.str = [93 x i8] c"getString: Limit %i outside UINT boundaries? For no limit, pass the function a limit of (0).\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [51 x i8] c"\0ACharacter limit of %i reached. About to retry...\0A\00"
@.str.2 = [6 x i8] c"3...\0A\00"
@.str.3 = [6 x i8] c"2...\0A\00"
@.str.4 = [6 x i8] c"1...\0A\00"
@.str.5 = [8 x i8] c"Retry: \00"
define i8* @getString(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %3
store i8* null, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %3
%11 = load i32, i32* @UINT_MAX
%12 = icmp ugt i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i32 %15)
store i8* null, i8** %2
br label %164
17: ; preds = %1
br label %18
18: ; preds = %130, %67, %17
%19 = load i32, i32* @stdin
%20 = call i32 @fgetc(i32 %19)
store i32 %20, i32* %7
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br label %26
26: ; preds = %22, %18
%27 = phi i1 [ false, %18 ], [ %25, %22 ]
br i1 %27, label %28, label %138
28: ; preds = %26
%29 = load i32, i32* %6
%30 = add i32 %29, 1
%31 = load i32, i32* %5
%32 = icmp ugt i32 %30, %31
br i1 %32, label %33, label %130
33: ; preds = %28
%34 = load i32, i32* %3
%35 = icmp ugt i32 %34, 0
br i1 %35, label %36, label %87
36: ; preds = %33
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 32, i32* %5
br label %86
40: ; preds = %36
%41 = load i32, i32* %5
%42 = load i32, i32* @UINT_MAX
%43 = udiv i32 %42, 2
%44 = icmp ule i32 %41, %43
br i1 %44, label %45, label %53
45: ; preds = %40
%46 = load i32, i32* %5
%47 = load i32, i32* %3
%48 = udiv i32 %47, 2
%49 = icmp ule i32 %46, %48
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32, i32* %5
%52 = mul i32 %51, 2
store i32 %52, i32* %5
br label %85
53: ; preds = %45, %40
%54 = load i32, i32* %5
%55 = load i32, i32* @UINT_MAX
%56 = udiv i32 %55, 2
%57 = icmp ule i32 %54, %56
br i1 %57, label %58, label %81
58: ; preds = %53
%59 = load i32, i32* %5
%60 = load i32, i32* %3
%61 = udiv i32 %60, 2
%62 = icmp ugt i32 %59, %61
br i1 %62, label %63, label %81
63: ; preds = %58
%64 = load i32, i32* %5
%65 = load i32, i32* %3
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %79
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i32, i32* %3
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = call i32 @sleep(i32 1)
%72 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%73 = call i32 @sleep(i32 1)
%74 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 @sleep(i32 1)
%76 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%77 = call i32 @sleep(i32 1)
%78 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %18
79: ; preds = %63
%80 = load i32, i32* %3
store i32 %80, i32* %5
br label %84
81: ; preds = %58, %53
%82 = load i8*, i8** %4
%83 = call i32 @free(i8* %82)
store i8* null, i8** %2
br label %164
84: ; preds = %79
br label %85
85: ; preds = %84, %50
br label %86
86: ; preds = %85, %39
br label %116
87: ; preds = %33
%88 = load i32, i32* %3
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %115
90: ; preds = %87
%91 = load i32, i32* %5
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %90
store i32 32, i32* %5
br label %114
94: ; preds = %90
%95 = load i32, i32* %5
%96 = load i32, i32* @UINT_MAX
%97 = udiv i32 %96, 2
%98 = icmp ule i32 %95, %97
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = load i32, i32* %5
%101 = mul i32 %100, 2
store i32 %101, i32* %5
br label %113
102: ; preds = %94
%103 = load i32, i32* %5
%104 = load i32, i32* @UINT_MAX
%105 = udiv i32 %104, 2
%106 = icmp ule i32 %103, %105
br i1 %106, label %107, label %109
107: ; preds = %102
%108 = load i32, i32* %3
store i32 %108, i32* %5
br label %112
109: ; preds = %102
%110 = load i8*, i8** %4
%111 = call i32 @free(i8* %110)
store i8* null, i8** %2
br label %164
112: ; preds = %107
br label %113
113: ; preds = %112, %99
br label %114
114: ; preds = %113, %93
br label %115
115: ; preds = %114, %87
br label %116
116: ; preds = %115, %86
%117 = load i8*, i8** %4
%118 = load i32, i32* %5
%119 = zext i32 %118 to i64
%120 = mul i64 %119, 1
%121 = trunc i64 %120 to i32
%122 = call i8* @realloc(i8* %117, i32 %121)
store i8* %122, i8** %8
%123 = load i8*, i8** %8
%124 = icmp eq i8* %123, null
br i1 %124, label %125, label %128
125: ; preds = %116
%126 = load i8*, i8** %4
%127 = call i32 @free(i8* %126)
store i8* null, i8** %2
br label %164
128: ; preds = %116
%129 = load i8*, i8** %8
store i8* %129, i8** %4
br label %130
130: ; preds = %128, %28
%131 = load i32, i32* %7
%132 = trunc i32 %131 to i8
%133 = load i8*, i8** %4
%134 = load i32, i32* %6
%135 = add i32 %134, 1
store i32 %135, i32* %6
%136 = zext i32 %134 to i64
%137 = getelementptr inbounds i8, i8* %133, i64 %136
store i8 %132, i8* %137
br label %18
138: ; preds = %26
%139 = load i32, i32* %6
%140 = icmp eq i32 %139, 0
br i1 %140, label %141, label %146
141: ; preds = %138
%142 = load i32, i32* %7
%143 = load i32, i32* @EOF
%144 = icmp eq i32 %142, %143
br i1 %144, label %145, label %146
145: ; preds = %141
store i8* null, i8** %2
br label %164
146: ; preds = %141, %138
%147 = load i32, i32* %6
%148 = add i32 %147, 1
%149 = zext i32 %148 to i64
%150 = mul i64 %149, 1
%151 = trunc i64 %150 to i32
%152 = call i8* @malloc(i32 %151)
store i8* %152, i8** %9
%153 = load i8*, i8** %9
%154 = load i8*, i8** %4
%155 = load i32, i32* %6
%156 = call i32 @strncpy(i8* %153, i8* %154, i32 %155)
%157 = load i8*, i8** %4
%158 = call i32 @free(i8* %157)
%159 = load i8*, i8** %9
%160 = load i32, i32* %6
%161 = zext i32 %160 to i64
%162 = getelementptr inbounds i8, i8* %159, i64 %161
store i8 0, i8* %162
%163 = load i8*, i8** %9
store i8* %163, i8** %2
br label %164
164: ; preds = %146, %145, %125, %109, %81, %13
%165 = load i8*, i8** %2
ret i8* %165
}

LLVM IR (-O2):
@UINT_MAX = global i32 0
@stderr = global i32 0
@.str = [93 x i8] c"getString: Limit %i outside UINT boundaries? For no limit, pass the function a limit of (0).\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [51 x i8] c"\0ACharacter limit of %i reached. About to retry...\0A\00"
@.str.5 = [8 x i8] c"Retry: \00"
@str = [5 x i8] c"3...\00"
@str.6 = [5 x i8] c"2...\00"
@str.7 = [5 x i8] c"1...\00"
define i8* @getString(i32 %0) {
%2 = load i32, i32* @UINT_MAX
%3 = icmp ult i32 %2, %0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgetc(i32 %5)
%7 = icmp ne i32 %6, 10
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %6, %8
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %90
11: ; preds = %4
%12 = icmp eq i32 %0, 0
%13 = lshr i32 %0, 1
br label %80
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %105
17: ; preds = %80, %32
%18 = phi i32 [ %81, %80 ], [ %44, %32 ]
br i1 %86, label %19, label %67
19: ; preds = %17
br i1 %12, label %51, label %20
20: ; preds = %19
br i1 %87, label %60, label %21
21: ; preds = %20
%22 = load i32, i32* @UINT_MAX
%23 = lshr i32 %22, 1
%24 = icmp ugt i32 %83, %23
%25 = or i1 %88, %24
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = shl i32 %83, 1
br label %60
28: ; preds = %21
%29 = icmp ule i32 %83, %23
%30 = and i1 %88, %29
br i1 %30, label %31, label %49
31: ; preds = %28
br i1 %89, label %32, label %60
32: ; preds = %31
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%35 = tail call i32 @sleep(i32 1)
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%37 = tail call i32 @sleep(i32 1)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%39 = tail call i32 @sleep(i32 1)
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%41 = tail call i32 @sleep(i32 1)
%42 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = tail call i32 @fgetc(i32 %43)
%45 = icmp ne i32 %44, 10
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %44, %46
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %17, label %90
49: ; preds = %28
%50 = tail call i32 @free(i8* %82)
br label %105
51: ; preds = %19
br i1 %87, label %60, label %52
52: ; preds = %51
%53 = load i32, i32* @UINT_MAX
%54 = lshr i32 %53, 1
%55 = icmp ugt i32 %83, %54
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = shl i32 %83, 1
br label %60
58: ; preds = %52
%59 = tail call i32 @free(i8* %82)
br label %105
60: ; preds = %31, %20, %51, %56, %26
%61 = phi i32 [ %18, %26 ], [ %81, %56 ], [ %81, %51 ], [ %81, %20 ], [ %81, %31 ]
%62 = phi i32 [ %27, %26 ], [ %57, %56 ], [ 32, %51 ], [ %0, %31 ], [ 32, %20 ]
%63 = tail call i8* @realloc(i8* %82, i32 %62)
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = tail call i32 @free(i8* %82)
br label %105
67: ; preds = %17, %60
%68 = phi i32 [ %61, %60 ], [ %81, %17 ]
%69 = phi i32 [ %62, %60 ], [ %83, %17 ]
%70 = phi i8* [ %63, %60 ], [ %82, %17 ]
%71 = trunc i32 %68 to i8
%72 = zext i32 %84 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
store i8 %71, i8* %73
%74 = load i32, i32* @stdin
%75 = tail call i32 @fgetc(i32 %74)
%76 = icmp ne i32 %75, 10
%77 = load i32, i32* @EOF
%78 = icmp ne i32 %75, %77
%79 = select i1 %76, i1 %78, i1 false
br i1 %79, label %80, label %90
80: ; preds = %11, %67
%81 = phi i32 [ %6, %11 ], [ %75, %67 ]
%82 = phi i8* [ null, %11 ], [ %70, %67 ]
%83 = phi i32 [ 0, %11 ], [ %69, %67 ]
%84 = phi i32 [ 0, %11 ], [ %85, %67 ]
%85 = add i32 %84, 1
%86 = icmp ugt i32 %85, %83
%87 = icmp eq i32 %83, 0
%88 = icmp ugt i32 %83, %13
%89 = icmp eq i32 %83, %0
br label %17
90: ; preds = %67, %32, %4
%91 = phi i32 [ 0, %4 ], [ %84, %32 ], [ %85, %67 ]
%92 = phi i8* [ null, %4 ], [ %82, %32 ], [ %70, %67 ]
%93 = phi i32 [ %6, %4 ], [ %44, %32 ], [ %75, %67 ]
%94 = phi i32 [ %8, %4 ], [ %46, %32 ], [ %77, %67 ]
%95 = icmp eq i32 %91, 0
%96 = icmp eq i32 %93, %94
%97 = select i1 %95, i1 %96, i1 false
br i1 %97, label %105, label %98
98: ; preds = %90
%99 = add i32 %91, 1
%100 = tail call i8* @malloc(i32 %99)
%101 = tail call i32 @strncpy(i8* %100, i8* %92, i32 %91)
%102 = tail call i32 @free(i8* %92)
%103 = zext i32 %91 to i64
%104 = getelementptr inbounds i8, i8* %100, i64 %103
store i8 0, i8* %104
br label %105
105: ; preds = %65, %90, %98, %58, %49, %14
%106 = phi i8* [ null, %14 ], [ null, %49 ], [ null, %58 ], [ %100, %98 ], [ null, %90 ], [ null, %65 ]
ret i8* %106
}