#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char **, int /*<<< orphan*/, int);
scalar_t__ realloc(unsigned char **, int);
int __grow_type_table(int nextarg, unsigned char **typetable, int *tablesize) {
  unsigned char *oldtable = *typetable;
  int newsize = *tablesize * 2;
  if (*tablesize == 8) {
    *typetable = (unsigned char *)malloc(sizeof(unsigned char) * newsize);
    memmove(*typetable, oldtable, *tablesize);
  } else {
    *typetable =
        (unsigned char *)realloc(typetable, sizeof(unsigned char) * newsize);
  }
  memset(&typetable[*tablesize], 0, (newsize - *tablesize));
  *tablesize = newsize;
  return 0;
}


x86 assembly (clang, -O0):
<__grow_type_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x8,(%rax)
jne    11ab <__grow_type_table+0x6b>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <memmove@plt>
jmp    11c8 <__grow_type_table+0x88>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
sub    (%rax),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__grow_type_table>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    (%rdx),%eax
lea    (%rax,%rax,1),%r14d
cmp    $0x8,%eax
jne    1177 <__grow_type_table+0x37>
mov    0x0(%rbp),%r15
mov    %r14d,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    (%rbx),%edx
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <memmove@plt>
jmp    1186 <__grow_type_table+0x46>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <realloc@plt>
mov    %rax,0x0(%rbp)
movslq (%rbx),%rax
lea    0x0(,%rax,8),%rdi
add    %rbp,%rdi
mov    %r14d,%edx
sub    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r14d,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__grow_type_table(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
store i8* %10, i8** %7
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 2
store i32 %13, i32* %8
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 8
br i1 %16, label %17, label %31
17: ; preds = %3
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i8**, i8*** %5
store i8* %23, i8** %24
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = load i8*, i8** %7
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = call i32 @memmove(i8* %26, i8* %27, i32 %29)
br label %40
31: ; preds = %3
%32 = load i8**, i8*** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @realloc(i8** %32, i32 %36)
%38 = inttoptr i64 %37 to i8*
%39 = load i8**, i8*** %5
store i8* %38, i8** %39
br label %40
40: ; preds = %31, %17
%41 = load i8**, i8*** %5
%42 = load i32*, i32** %6
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %41, i64 %44
%46 = load i32, i32* %8
%47 = load i32*, i32** %6
%48 = load i32, i32* %47
%49 = sub nsw i32 %46, %48
%50 = call i32 @memset(i8** %45, i32 0, i32 %49)
%51 = load i32, i32* %8
%52 = load i32*, i32** %6
store i32 %51, i32* %52
ret i32 0
}

LLVM IR (-O2):
define i32 @__grow_type_table(i32 %0, i8** %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = shl nsw i32 %4, 1
%6 = icmp eq i32 %4, 8
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = load i8*, i8** %1
%9 = tail call i64 @malloc(i32 %5)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %1
%11 = load i32, i32* %2
%12 = tail call i32 @memmove(i8* %10, i8* %8, i32 %11)
br label %16
13: ; preds = %3
%14 = tail call i64 @realloc(i8** %1, i32 %5)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %1
br label %16
16: ; preds = %13, %7
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = sub nsw i32 %5, %17
%21 = tail call i32 @memset(i8** %19, i32 0, i32 %20)
store i32 %5, i32* %2
ret i32 0
}