#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__ realloc(char **, int);
char *strdup(char *);
void combine_cookie_lists(char ***destc, int *n_dest, char **src, int n_src) {
  int loop = 0;
  *destc = (char **)realloc(*destc, (*n_dest + n_src) * sizeof(char *));
  for (loop = 0; loop < n_src; loop++)
    (*destc)[*n_dest + loop] = strdup(src[loop]);
  (*n_dest) += n_src;
}


x86 assembly (clang, -O0):
<combine_cookie_lists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b1 <combine_cookie_lists+0x91>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <combine_cookie_lists+0x4c>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<combine_cookie_lists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r15
mov    (%rdi),%rdi
mov    (%rsi),%esi
add    %ecx,%esi
shl    $0x3,%esi
call   1030 <realloc@plt>
mov    %rax,%r12
mov    %rax,(%r15)
mov    %rbp,0x10(%rsp)
movslq 0x0(%rbp),%rax
mov    %rax,0x8(%rsp)
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
jle    11bd <combine_cookie_lists+0x9d>
mov    (%r14),%rdi
call   1040 <strdup@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%r12,%rcx,8)
cmpl   $0x1,0x4(%rsp)
je     11bd <combine_cookie_lists+0x9d>
mov    0x4(%rsp),%r12d
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%rbp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
mov    (%r15),%r13
add    %rbp,%r13
call   1040 <strdup@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <combine_cookie_lists+0x80>
mov    0x8(%rsp),%rcx
add    0x4(%rsp),%ecx
mov    0x10(%rsp),%rax
mov    %ecx,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @combine_cookie_lists(i8*** nocapture %0, i32* nocapture %1, i8** nocapture %2, i32 %3) {
%5 = load i8**, i8*** %0
%6 = load i32, i32* %1
%7 = add nsw i32 %6, %3
%8 = shl i32 %7, 3
%9 = tail call i64 @realloc(i8** %5, i32 %8)
%10 = inttoptr i64 %9 to i8**
store i8** %10, i8*** %0
%11 = icmp sgt i32 %3, 0
%12 = load i32, i32* %1
br i1 %11, label %13, label %30
13: ; preds = %4
%14 = sext i32 %12 to i64
%15 = zext i32 %3 to i64
%16 = load i8*, i8** %2
%17 = tail call i8* @strdup(i8* %16)
%18 = getelementptr inbounds i8*, i8** %10, i64 %14
store i8* %17, i8** %18
%19 = icmp eq i32 %3, 1
br i1 %19, label %30, label %20
20: ; preds = %13, %20
%21 = phi i64 [ %28, %20 ], [ 1, %13 ]
%22 = load i8**, i8*** %0
%23 = getelementptr inbounds i8*, i8** %2, i64 %21
%24 = load i8*, i8** %23
%25 = tail call i8* @strdup(i8* %24)
%26 = add nsw i64 %21, %14
%27 = getelementptr inbounds i8*, i8** %22, i64 %26
store i8* %25, i8** %27
%28 = add nuw nsw i64 %21, 1
%29 = icmp eq i64 %28, %15
br i1 %29, label %30, label %20
30: ; preds = %20, %13, %4
%31 = add nsw i32 %12, %3
store i32 %31, i32* %1
ret void
}