#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 *);
int /*<<< orphan*/ interleave1(char const *, char const *, char *);
char *malloc(int);
int strlen(char const *);
void interleave2(const char *s1, const char *s2, char **output, int *avail) {
  if (!(*output) || (strlen(s1) + strlen(s2) + 1 > *avail)) {
    free(*output);
    *avail = strlen(s1) + strlen(s2) + 1;
    *output = malloc(*avail * sizeof(char));
  }
  interleave1(s1, s2, *output);
}


x86 assembly (clang, -O0):
<interleave2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1191 <interleave2+0x51>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jle    11dc <interleave2+0x9c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%ecx
add    %eax,%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1050 <interleave1@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interleave2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmpq   $0x0,(%rdx)
je     1179 <interleave2+0x39>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
mov    (%rbx),%rdx
cmp    (%r12),%eax
jge    117b <interleave2+0x3b>
jmp    11aa <interleave2+0x6a>
xor    %edx,%edx
mov    %rdx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x1,%edi
mov    %edi,(%r12)
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    %rax,(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <interleave1@plt>

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

LLVM IR (-O2):
define void @interleave2(i8* %0, i8* %1, i8** nocapture %2, i32* nocapture %3) {
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32 @strlen(i8* %1)
%10 = add nsw i32 %9, %8
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
%13 = load i8*, i8** %2
br i1 %12, label %22, label %14
14: ; preds = %7, %4
%15 = phi i8* [ null, %4 ], [ %13, %7 ]
%16 = tail call i32 @free(i8* %15)
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i32 @strlen(i8* %1)
%19 = add i32 %17, 1
%20 = add i32 %19, %18
store i32 %20, i32* %3
%21 = tail call i8* @malloc(i32 %20)
store i8* %21, i8** %2
br label %22
22: ; preds = %7, %14
%23 = phi i8* [ %21, %14 ], [ %13, %7 ]
%24 = tail call i32 @interleave1(i8* %0, i8* %1, i8* %23)
ret void
}