#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*/ interleave(char *, char *, int, int, char *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
void main() {
  char str1[] = "ABCD";
  char str2[] = "XYZ";
  int len1 = strlen(str1);
  int len2 = strlen(str2);
  char ils[len1 + len2 + 1];
  memset(ils, 0, len1 + len2 + 1);
  interleave(str1, str2, len1, len2, ils, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movb   $0x0,-0x4(%rbp)
movl   $0x44434241,-0x8(%rbp)
movl   $0x5a5958,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edx
add    -0x14(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%r8
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
xor    %r9d,%r9d
call   1050 <interleave@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,-0x2c(%rbp)
movl   $0x44434241,-0x30(%rbp)
movl   $0x5a5958,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    -0x34(%rbp),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %rsp,%r14
lea    (%r12,%r13,1),%edx
add    $0x1,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1050 <interleave@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str1 = [5 x i8] c"ABCD\00"
@__const.main.str2 = [4 x i8] c"XYZ\00"
define void @main() {
%1 = alloca [5 x i8]
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast [5 x i8]* %1 to i8*
%8 = bitcast [4 x i8]* %2 to i8*
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %3
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %13, %14
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca i8, i64 %17
store i64 %17, i64* %6
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = add nsw i32 %20, %21
%23 = add nsw i32 %22, 1
%24 = call i32 @memset(i8* %19, i32 0, i32 %23)
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = call i32 @interleave(i8* %25, i8* %26, i32 %27, i32 %28, i8* %19, i32 0)
%30 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@__const.main.str1 = [5 x i8] c"ABCD\00"
define void @main() {
%1 = alloca [5 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 5921112, i32* %2
%5 = call i32 @strlen(i8* %3)
%6 = call i32 @strlen(i8* %4)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = call i32 @memset(i8* %11, i32 0, i32 %8)
%13 = call i32 @interleave(i8* %3, i8* %4, i32 %5, i32 %6, i8* %11, i32 0)
ret void
}