#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 */
void **h2o_mem_realloc(void **, size_t);
void h2o_append_to_null_terminated_list(void ***list, void *element) {
  size_t cnt;
  for (cnt = 0; (*list)[cnt] != NULL; ++cnt)
    ;
  *list = h2o_mem_realloc(*list, (cnt + 2) * sizeof(void *));
  (*list)[cnt++] = element;
  (*list)[cnt] = NULL;
}


x86 assembly (clang, -O0):
<h2o_append_to_null_terminated_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1154 <h2o_append_to_null_terminated_list+0x44>
jmp    1143 <h2o_append_to_null_terminated_list+0x33>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <h2o_append_to_null_terminated_list+0x18>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
add    $0x2,%rsi
shl    $0x3,%rsi
call   1030 <h2o_mem_realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h2o_append_to_null_terminated_list>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpq   $0x0,-0x8(%rdi,%rbx,1)
lea    0x8(%rbx),%rbx
jne    1130 <h2o_append_to_null_terminated_list+0x20>
mov    %rbx,%rsi
call   1030 <h2o_mem_realloc@plt>
mov    %rax,(%r15)
mov    %r14,-0x10(%rax,%rbx,1)
mov    (%r15),%rax
movq   $0x0,-0x8(%rax,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @h2o_append_to_null_terminated_list(i8*** %0, i8* %1) {
%3 = alloca i8***
%4 = alloca i8*
%5 = alloca i64
store i8*** %0, i8**** %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %6
6: ; preds = %14, %2
%7 = load i8***, i8**** %3
%8 = load i8**, i8*** %7
%9 = load i64, i64* %5
%10 = getelementptr inbounds i8*, i8** %8, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %6
br label %14
14: ; preds = %13
%15 = load i64, i64* %5
%16 = add i64 %15, 1
store i64 %16, i64* %5
br label %6
17: ; preds = %6
%18 = load i8***, i8**** %3
%19 = load i8**, i8*** %18
%20 = load i64, i64* %5
%21 = add i64 %20, 2
%22 = mul i64 %21, 8
%23 = call i8** @h2o_mem_realloc(i8** %19, i64 %22)
%24 = load i8***, i8**** %3
store i8** %23, i8*** %24
%25 = load i8*, i8** %4
%26 = load i8***, i8**** %3
%27 = load i8**, i8*** %26
%28 = load i64, i64* %5
%29 = add i64 %28, 1
store i64 %29, i64* %5
%30 = getelementptr inbounds i8*, i8** %27, i64 %28
store i8* %25, i8** %30
%31 = load i8***, i8**** %3
%32 = load i8**, i8*** %31
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8*, i8** %32, i64 %33
store i8* null, i8** %34
ret void
}

LLVM IR (-O2):
define void @h2o_append_to_null_terminated_list(i8*** nocapture %0, i8* %1) {
%3 = load i8**, i8*** %0
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ 0, %2 ], [ %9, %4 ]
%6 = getelementptr inbounds i8*, i8** %3, i64 %5
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = add i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = shl i64 %5, 3
%12 = add i64 %11, 16
%13 = tail call i8** @h2o_mem_realloc(i8** %3, i64 %12)
store i8** %13, i8*** %0
%14 = getelementptr inbounds i8*, i8** %13, i64 %5
store i8* %1, i8** %14
%15 = load i8**, i8*** %0
%16 = getelementptr inbounds i8*, i8** %15, i64 %9
store i8* null, i8** %16
ret void
}