#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);
char fgetc(int /*<<< orphan*/);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stdin;
char *readCli(int *bufferSize) {
  printf("Enter your name: ");
  int size_b = 30;
  char *buffer;
  buffer = (char *)malloc(size_b * sizeof(char));
  if (buffer == NULL) {
    exit(1);
  }
  char enterEater;
  enterEater = getchar();
  char c;
  int i = 0;
  while ((c = fgetc(stdin)) != '\n') {
    if (((i % 30) == 0) && i != 0) {
      buffer = (char *)realloc(buffer, (size_b * 2) * sizeof(char));
      if (buffer == NULL) {
        exit(3);
      }
    }
    buffer[i++] = c;
  }
  buffer[i] = '\0';
  buffer = (char *)realloc(buffer, (i + 1) * sizeof(char));
  if (buffer == NULL) {
    exit(4);
  }
  *bufferSize = i + 1;
  return buffer;
}


x86 assembly (clang, -O0):
<readCli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1e,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <readCli+0x47>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %al,-0x1a(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1245 <readCli+0xe5>
mov    -0x20(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1228 <readCli+0xc8>
cmpl   $0x0,-0x20(%rbp)
je     1228 <readCli+0xc8>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1223 <readCli+0xc3>
mov    $0x3,%edi
call   1080 <exit@plt>
jmp    1228 <readCli+0xc8>
mov    -0x1a(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b8 <readCli+0x58>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1281 <readCli+0x121>
mov    $0x4,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readCli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1e,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     123f <readCli+0xdf>
mov    %rax,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e48(%rip),%r12
mov    (%r12),%edi
call   1040 <fgetc@plt>
cmp    $0xa,%al
je     1214 <readCli+0xb4>
mov    %eax,%r13d
mov    %rbp,(%rsp)
xor    %ebp,%ebp
mov    $0x88888889,%r14d
xor    %ebx,%ebx
jmp    11db <readCli+0x7b>
mov    %r13b,(%r15,%rbx,1)
add    $0x1,%rbx
mov    (%r12),%edi
call   1040 <fgetc@plt>
mov    %eax,%r13d
add    $0x1,%ebp
cmp    $0xa,%al
je     1210 <readCli+0xb0>
test   %rbx,%rbx
je     11c0 <readCli+0x60>
mov    %ebp,%eax
imul   %r14,%rax
shr    $0x24,%rax
imul   $0xffffffe2,%eax,%eax
add    %ebx,%eax
jne    11c0 <readCli+0x60>
mov    %r15,%rdi
mov    $0x3c,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c0 <readCli+0x60>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    (%rsp),%rbp
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
add    $0x1,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     1249 <readCli+0xe9>
mov    %ebx,0x0(%rbp)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x4,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [18 x i8] c"Enter your name: \00"
@stdin = global i32 0
define i8* @readCli(i32* nocapture writeonly %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @malloc(i32 30)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = inttoptr i64 %3 to i8*
%9 = tail call signext i8 (...) @getchar()
%10 = load i32, i32* @stdin
%11 = tail call signext i8 @fgetc(i32 %10)
%12 = icmp eq i8 %11, 10
br i1 %12, label %37, label %13
13: ; preds = %7, %28
%14 = phi i64 [ %30, %28 ], [ 0, %7 ]
%15 = phi i8 [ %33, %28 ], [ %11, %7 ]
%16 = phi i8* [ %29, %28 ], [ %8, %7 ]
%17 = trunc i64 %14 to i32
%18 = urem i32 %17, 30
%19 = icmp eq i32 %18, 0
%20 = icmp ne i64 %14, 0
%21 = and i1 %20, %19
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = tail call i64 @realloc(i8* %16, i32 60)
%24 = inttoptr i64 %23 to i8*
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @exit(i32 3)
unreachable
28: ; preds = %22, %13
%29 = phi i8* [ %24, %22 ], [ %16, %13 ]
%30 = add nuw i64 %14, 1
%31 = getelementptr inbounds i8, i8* %29, i64 %14
store i8 %15, i8* %31
%32 = load i32, i32* @stdin
%33 = tail call signext i8 @fgetc(i32 %32)
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %13
35: ; preds = %28
%36 = trunc i64 %30 to i32
br label %37
37: ; preds = %35, %7
%38 = phi i8* [ %8, %7 ], [ %29, %35 ]
%39 = phi i32 [ 0, %7 ], [ %36, %35 ]
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
%42 = add nuw nsw i32 %39, 1
%43 = tail call i64 @realloc(i8* %38, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = tail call i32 @exit(i32 4)
unreachable
47: ; preds = %37
%48 = inttoptr i64 %43 to i8*
store i32 %42, i32* %0
ret i8* %48
}