#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ cgc_memcpy(int *, int *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int freaduntil(char *, int, char, int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strtol(char *, int /*<<< orphan*/ *, int);
void multiply_array(int **parray, size_t *array_size) {
  char buf[64];
  int multiplier = 0;
  int *old_array = *parray;
  int *array = NULL;
  int array_len = *array_size;
  ssize_t bytes_read;
  if (array_len > 10000) {
    printf("Array is too long. Can't multiply any more\n");
    return;
  }
  if (!old_array || !array_len)
    return;
  printf("Quick Grow! Enter a list multiplier. End number with ';'\n");
  fflush(stdout);
  if ((bytes_read = freaduntil(buf, sizeof(buf), ';', stdin)) != -1) {
    multiplier = strtol(buf, NULL, 10);
    if (multiplier && multiplier <= 10000) {
      array_len = multiplier * *array_size;
      array = malloc(sizeof(int) * array_len);
      int i = 0;
      for (i = 0; i < multiplier; i++)
        cgc_memcpy(&array[i * *array_size], old_array,
                   sizeof(int) * *array_size);
      *array_size = array_len;
    } else {
      printf("Multiplier too big, try again\n");
      while (freaduntil(buf, sizeof(buf), '\n', stdin) == -1)
        ;
      return;
    }
  }
  while (freaduntil(buf, sizeof(buf), '\n', stdin) == -1)
    ;
  free(old_array);
  *parray = array;
}


x86 assembly (clang, -O0):
<multiply_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x6c(%rbp)
cmpl   $0x2710,-0x6c(%rbp)
jle    11c5 <multiply_array+0x55>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
jmp    1357 <multiply_array+0x1e7>
cmpq   $0x0,-0x60(%rbp)
je     11da <multiply_array+0x6a>
cmpl   $0x0,-0x6c(%rbp)
jne    11df <multiply_array+0x6f>
jmp    1357 <multiply_array+0x1e7>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    -0x50(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
mov    $0x40,%esi
mov    $0x3b,%edx
call   1060 <freaduntil@plt>
mov    %eax,-0x70(%rbp)
cmp    $0xffffffff,%eax
je     1314 <multiply_array+0x1a4>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     12d4 <multiply_array+0x164>
cmpl   $0x2710,-0x54(%rbp)
jg     12d4 <multiply_array+0x164>
movslq -0x54(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   (%rcx),%rax
mov    %eax,-0x6c(%rbp)
movslq -0x6c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    12c4 <multiply_array+0x154>
mov    -0x68(%rbp),%rdi
movslq -0x74(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   (%rcx),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x60(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1090 <cgc_memcpy@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    127d <multiply_array+0x10d>
movslq -0x6c(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    130f <multiply_array+0x19f>
lea    0xd8b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%ecx
mov    $0x40,%esi
mov    $0xa,%edx
call   1060 <freaduntil@plt>
cmp    $0xffffffff,%eax
jne    130a <multiply_array+0x19a>
jmp    12e0 <multiply_array+0x170>
jmp    1357 <multiply_array+0x1e7>
jmp    1314 <multiply_array+0x1a4>
jmp    1319 <multiply_array+0x1a9>
lea    -0x50(%rbp),%rdi
mov    0x2cc4(%rip),%rax
mov    (%rax),%ecx
mov    $0x40,%esi
mov    $0xa,%edx
call   1060 <freaduntil@plt>
cmp    $0xffffffff,%eax
jne    1343 <multiply_array+0x1d3>
jmp    1319 <multiply_array+0x1a9>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    (%rsi),%eax
cmp    $0x2711,%eax
jl     11a1 <multiply_array+0x31>
lea    0xec9(%rip),%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    %rdi,%rbp
mov    (%rdi),%r15
test   %r15,%r15
je     130b <multiply_array+0x19b>
test   %eax,%eax
je     130b <multiply_array+0x19b>
mov    %rsi,%rbx
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2e0c(%rip),%r13
mov    0x0(%r13),%ecx
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
mov    $0x3b,%edx
call   1060 <freaduntil@plt>
cmp    $0xffffffff,%eax
je     12a0 <multiply_array+0x130>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %eax,%eax
je     12d9 <multiply_array+0x169>
mov    %eax,%r14d
cmp    $0x2710,%eax
jg     12d9 <multiply_array+0x169>
mov    %rbp,0x8(%rsp)
mov    (%rbx),%rbp
mov    %r14d,%eax
imul   %ebp,%eax
cltq
mov    %rax,(%rsp)
lea    0x0(,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    1292 <multiply_array+0x122>
shl    $0x2,%ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1090 <cgc_memcpy@plt>
cmp    $0x1,%r14d
je     1292 <multiply_array+0x122>
mov    %r14d,%ebp
mov    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdx
mov    %rdx,%rax
imul   %r14,%rax
lea    (%r12,%rax,4),%rdi
shl    $0x2,%edx
mov    %r15,%rsi
call   1090 <cgc_memcpy@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1270 <multiply_array+0x100>
mov    (%rsp),%rax
mov    %rax,(%rbx)
mov    0x8(%rsp),%rbp
jmp    12a3 <multiply_array+0x133>
xor    %r12d,%r12d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0xa,%edx
call   1060 <freaduntil@plt>
cmp    $0xffffffff,%eax
je     12b0 <multiply_array+0x140>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,0x0(%rbp)
jmp    130b <multiply_array+0x19b>
lea    0xd59(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0xa,%edx
call   1060 <freaduntil@plt>
cmp    $0xffffffff,%eax
je     12f0 <multiply_array+0x180>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Array is too long. Can't multiply any more\0A\00"
@.str.1 = [58 x i8] c"Quick Grow! Enter a list multiplier. End number with ';'\0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [31 x i8] c"Multiplier too big, try again\0A\00"
define void @multiply_array(i32** %0, i64* %1) {
%3 = alloca i32**
%4 = alloca i64*
%5 = alloca [64 x i8]
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32** %0, i32*** %3
store i64* %1, i64** %4
store i32 0, i32* %6
%12 = load i32**, i32*** %3
%13 = load i32*, i32** %12
store i32* %13, i32** %7
store i32* null, i32** %8
%14 = load i64*, i64** %4
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp sgt i32 %17, 10000
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %103
21: ; preds = %2
%22 = load i32*, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %24, %21
br label %103
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* @stdin
%34 = call i32 @freaduntil(i8* %32, i32 64, i8 signext 59, i32 %33)
store i32 %34, i32* %10
%35 = icmp ne i32 %34, -1
br i1 %35, label %36, label %91
36: ; preds = %28
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%38 = call i32 @strtol(i8* %37, i32* null, i32 10)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %81
41: ; preds = %36
%42 = load i32, i32* %6
%43 = icmp sle i32 %42, 10000
br i1 %43, label %44, label %81
44: ; preds = %41
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = load i64*, i64** %4
%48 = load i64, i64* %47
%49 = mul i64 %46, %48
%50 = trunc i64 %49 to i32
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = mul i64 4, %52
%54 = trunc i64 %53 to i32
%55 = call i32* @malloc(i32 %54)
store i32* %55, i32** %8
store i32 0, i32* %11
store i32 0, i32* %11
br label %56
56: ; preds = %74, %44
%57 = load i32, i32* %11
%58 = load i32, i32* %6
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %77
60: ; preds = %56
%61 = load i32*, i32** %8
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = load i64*, i64** %4
%65 = load i64, i64* %64
%66 = mul i64 %63, %65
%67 = getelementptr inbounds i32, i32* %61, i64 %66
%68 = load i32*, i32** %7
%69 = load i64*, i64** %4
%70 = load i64, i64* %69
%71 = mul i64 4, %70
%72 = trunc i64 %71 to i32
%73 = call i32 @cgc_memcpy(i32* %67, i32* %68, i32 %72)
br label %74
74: ; preds = %60
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %56
77: ; preds = %56
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = load i64*, i64** %4
store i64 %79, i64* %80
br label %90
81: ; preds = %41, %36
%82 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %83
83: ; preds = %88, %81
%84 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%85 = load i32, i32* @stdin
%86 = call i32 @freaduntil(i8* %84, i32 64, i8 signext 10, i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %89
88: ; preds = %83
br label %83
89: ; preds = %83
br label %103
90: ; preds = %77
br label %91
91: ; preds = %90, %28
br label %92
92: ; preds = %97, %91
%93 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%94 = load i32, i32* @stdin
%95 = call i32 @freaduntil(i8* %93, i32 64, i8 signext 10, i32 %94)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %98
97: ; preds = %92
br label %92
98: ; preds = %92
%99 = load i32*, i32** %7
%100 = call i32 @free(i32* %99)
%101 = load i32*, i32** %8
%102 = load i32**, i32*** %3
store i32* %101, i32** %102
br label %103
103: ; preds = %98, %89, %27, %19
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@str = [57 x i8] c"Quick Grow! Enter a list multiplier. End number with ';'\00"
@str.3 = [30 x i8] c"Multiplier too big, try again\00"
@str.4 = [43 x i8] c"Array is too long. Can't multiply any more\00"
define void @multiply_array(i32** nocapture %0, i64* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = load i32*, i32** %0
%6 = load i64, i64* %1
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 10000
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
br label %66
11: ; preds = %2
%12 = icmp ne i32* %5, null
%13 = icmp ne i32 %7, 0
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %66
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call i32 @fflush(i32 %17)
%19 = load i32, i32* @stdin
%20 = call i32 @freaduntil(i8* %4, i32 64, i8 signext 59, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %58, label %22
22: ; preds = %15
%23 = call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
%24 = icmp ne i32 %23, 0
%25 = icmp slt i32 %23, 10001
%26 = and i1 %24, %25
br i1 %26, label %27, label %52
27: ; preds = %22
%28 = load i64, i64* %1
%29 = trunc i64 %28 to i32
%30 = mul i32 %23, %29
%31 = sext i32 %30 to i64
%32 = shl i32 %30, 2
%33 = call i32* @malloc(i32 %32)
%34 = icmp sgt i32 %23, 0
br i1 %34, label %35, label %51
35: ; preds = %27
%36 = zext i32 %23 to i64
%37 = trunc i64 %28 to i32
%38 = shl i32 %37, 2
%39 = call i32 @cgc_memcpy(i32* %33, i32* %5, i32 %38)
%40 = icmp eq i32 %23, 1
br i1 %40, label %51, label %41
41: ; preds = %35, %41
%42 = phi i64 [ %49, %41 ], [ 1, %35 ]
%43 = load i64, i64* %1
%44 = mul i64 %43, %42
%45 = getelementptr inbounds i32, i32* %33, i64 %44
%46 = trunc i64 %43 to i32
%47 = shl i32 %46, 2
%48 = call i32 @cgc_memcpy(i32* %45, i32* %5, i32 %47)
%49 = add nuw nsw i64 %42, 1
%50 = icmp eq i64 %49, %36
br i1 %50, label %51, label %41
51: ; preds = %41, %35, %27
store i64 %31, i64* %1
br label %58
52: ; preds = %22
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0))
br label %54
54: ; preds = %54, %52
%55 = load i32, i32* @stdin
%56 = call i32 @freaduntil(i8* %4, i32 64, i8 signext 10, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %54, label %66
58: ; preds = %51, %15
%59 = phi i32* [ %33, %51 ], [ null, %15 ]
br label %60
60: ; preds = %60, %58
%61 = load i32, i32* @stdin
%62 = call i32 @freaduntil(i8* %4, i32 64, i8 signext 10, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %60, label %64
64: ; preds = %60
%65 = call i32 @free(i32* %5)
store i32* %59, i32** %0
br label %66
66: ; preds = %54, %11, %64, %9
ret void
}