#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 atoi(char *);
int /*<<< orphan*/ breakpoint();
int /*<<< orphan*/ free(int *);
int *malloc(int);
int read(int /*<<< orphan*/, char **, int);
int *realloc(int *, int);
scalar_t__ strncmp(char *, char *, int);
void readInput() {
  char buf[1024];
  int rc;
  int *tab = malloc(128 * sizeof(int));
  int i = 0;
  int size = 128;
  do {
    breakpoint();
    rc = read(0, &buf, 1024);
    buf[rc] = 0;
    if (strncmp(buf, "quit\n", rc) == 0) {
      free(tab);
      return;
    }
    *(tab + i) = atoi(buf);
    i++;
    if (i == size) {
      size *= 2;
      tab = realloc(tab, size * sizeof(int));
    }
  } while (42);
}


x86 assembly (clang, -O0):
<readInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x410(%rbp)
movl   $0x0,-0x414(%rbp)
movl   $0x80,-0x418(%rbp)
mov    $0x0,%al
call   1060 <breakpoint@plt>
lea    -0x400(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x404(%rbp)
movslq -0x404(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
mov    -0x404(%rbp),%edx
lea    0xe1d(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1203 <readInput+0x93>
mov    -0x410(%rbp),%rdi
call   1030 <free@plt>
jmp    1286 <readInput+0x116>
lea    -0x400(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%edx
mov    -0x410(%rbp),%rax
movslq -0x414(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x418(%rbp),%eax
jne    1272 <readInput+0x102>
mov    -0x418(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x418(%rbp)
mov    -0x410(%rbp),%rdi
movslq -0x418(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x410(%rbp)
jmp    1277 <readInput+0x107>
mov    $0x1,%al
test   $0x1,%al
jne    11a0 <readInput+0x30>
jmp    1286 <readInput+0x116>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <breakpoint@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
movslq %eax,%rdx
movb   $0x0,(%rsp,%rdx,1)
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strncmp@plt>
test   %rax,%rax
je     1242 <readInput+0xd2>
mov    $0x80,%r13d
mov    $0x1,%ebx
mov    %rsp,%r14
lea    0xe25(%rip),%r15
jmp    1211 <readInput+0xa1>
nopl   (%rax)
xor    %eax,%eax
call   1060 <breakpoint@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
movslq %eax,%rdx
movb   $0x0,(%rsp,%rdx,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strncmp@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1242 <readInput+0xd2>
mov    %r14,%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4(%r12,%rbx,4)
mov    %r13d,%eax
cmp    %rax,%rbx
jne    11e0 <readInput+0x70>
lea    0x0(%r13,%r13,1),%ebp
shl    $0x3,%r13d
mov    %r12,%rdi
mov    %r13d,%esi
call   1080 <realloc@plt>
mov    %rax,%r12
mov    %ebp,%r13d
jmp    11e0 <readInput+0x70>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"quit\0A\00"
define void @readInput() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = call i32* @malloc(i32 512)
store i32* %6, i32** %3
store i32 0, i32* %4
store i32 128, i32* %5
br label %7
7: ; preds = %43, %0
%8 = call i32 (...) @breakpoint()
%9 = bitcast [1024 x i8]* %1 to i8**
%10 = call i32 @read(i32 0, i8** %9, i32 1024)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %12
store i8 0, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = load i32*, i32** %3
%20 = call i32 @free(i32* %19)
br label %44
21: ; preds = %7
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
%24 = load i32*, i32** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %21
%34 = load i32, i32* %5
%35 = mul nsw i32 %34, 2
store i32 %35, i32* %5
%36 = load i32*, i32** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 4
%40 = trunc i64 %39 to i32
%41 = call i32* @realloc(i32* %36, i32 %40)
store i32* %41, i32** %3
br label %42
42: ; preds = %33, %21
br label %43
43: ; preds = %42
br i1 true, label %7, label %44
44: ; preds = %18, %43
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"quit\0A\00"
define void @readInput() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @malloc(i32 512)
%4 = call i32 (...) @breakpoint()
%5 = bitcast [1024 x i8]* %1 to i8**
%6 = call i32 @read(i32 0, i8** %5, i32 1024)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %27, %0
%12 = phi i32* [ %3, %0 ], [ %29, %27 ]
%13 = call i32 @free(i32* %12)
ret void
14: ; preds = %0, %27
%15 = phi i64 [ %20, %27 ], [ 0, %0 ]
%16 = phi i32* [ %29, %27 ], [ %3, %0 ]
%17 = phi i32 [ %28, %27 ], [ 128, %0 ]
%18 = call i32 @atoi(i8* %2)
%19 = getelementptr inbounds i32, i32* %16, i64 %15
store i32 %18, i32* %19
%20 = add nuw i64 %15, 1
%21 = zext i32 %17 to i64
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = shl nsw i32 %17, 1
%25 = shl i32 %17, 3
%26 = call i32* @realloc(i32* %16, i32 %25)
br label %27
27: ; preds = %14, %23
%28 = phi i32 [ %24, %23 ], [ %17, %14 ]
%29 = phi i32* [ %26, %23 ], [ %16, %14 ]
%30 = call i32 (...) @breakpoint()
%31 = call i32 @read(i32 0, i8** %5, i32 1024)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %31)
%35 = icmp eq i64 %34, 0
br i1 %35, label %11, label %14
}