#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*/ free(char **);
void *realloc(char **, size_t);
char **yuck_append(char **array, size_t n, char *val) {
  if (!(n % 16U)) {
    void *tmp = realloc(array, (n + 16U) * sizeof(*array));
    if (tmp == NULL) {
      free(array);
      return NULL;
    }
    array = tmp;
  }
  array[n] = val;
  return array;
}


x86 assembly (clang, -O0):
<yuck_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1188 <yuck_append+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x10,%rsi
shl    $0x3,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1180 <yuck_append+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <yuck_append+0x80>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuck_append>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
test   $0xf,%r15b
jne    114c <yuck_append+0x2c>
lea    0x80(,%r15,8),%rsi
mov    %rbx,%rdi
call   1040 <realloc@plt>
test   %rax,%rax
je     1159 <yuck_append+0x39>
mov    %rax,%rbx
mov    %r14,(%rbx,%r15,8)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    1150 <yuck_append+0x30>

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

LLVM IR (-O2):
define i8** @yuck_append(i8** %0, i64 %1, i8* %2) {
%4 = and i64 %1, 15
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = shl i64 %1, 3
%8 = add i64 %7, 128
%9 = tail call i8* @realloc(i8** %0, i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = bitcast i8* %9 to i8**
br label %15
13: ; preds = %6
%14 = tail call i32 @free(i8** %0)
br label %18
15: ; preds = %11, %3
%16 = phi i8** [ %0, %3 ], [ %12, %11 ]
%17 = getelementptr inbounds i8*, i8** %16, i64 %1
store i8* %2, i8** %17
br label %18
18: ; preds = %13, %15
%19 = phi i8** [ %16, %15 ], [ null, %13 ]
ret i8** %19
}