#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*/ assert(int);
int /*<<< orphan*/ free(char *);
char *str_concat(int, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
void test_str_concat() {
  char *s;
  s = str_concat(2, "test", "test1");
  assert(strcmp(s, "testtest1") == 0);
  free(s);
  s = str_concat(3, "test", "_", "test3");
  assert(strcmp(s, "test_test3") == 0);
  free(s);
}


x86 assembly (clang, -O0):
<test_str_concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2,%edi
lea    0xeac(%rip),%rsi
lea    0xeae(%rip),%rdx
mov    $0x0,%al
call   1060 <str_concat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x3,%edi
lea    0xe64(%rip),%rsi
lea    0xe6c(%rip),%rdx
lea    0xe6c(%rip),%rcx
mov    $0x0,%al
call   1060 <str_concat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_concat>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%r14
lea    0xeb7(%rip),%rdx
mov    $0x2,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <str_concat@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe7f(%rip),%rdx
lea    0xe7f(%rip),%rcx
mov    $0x3,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <str_concat@plt>
mov    %rax,%rbx
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [6 x i8] c"test1\00"
@.str.2 = [10 x i8] c"testtest1\00"
@.str.3 = [2 x i8] c"_\00"
@.str.4 = [6 x i8] c"test3\00"
@.str.5 = [11 x i8] c"test_test3\00"
define void @test_str_concat() {
%1 = alloca i8*
%2 = call i8* (i32, i8*, i8*, ...) @str_concat(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i32 @free(i8* %8)
%10 = call i8* (i32, i8*, i8*, ...) @str_concat(i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i8* %10, i8** %1
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [6 x i8] c"test1\00"
@.str.2 = [10 x i8] c"testtest1\00"
@.str.3 = [2 x i8] c"_\00"
@.str.4 = [6 x i8] c"test3\00"
@.str.5 = [11 x i8] c"test_test3\00"
define void @test_str_concat() {
%1 = tail call i8* (i32, i8*, i8*, ...) @str_concat(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @free(i8* %1)
%7 = tail call i8* (i32, i8*, i8*, ...) @str_concat(i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @free(i8* %7)
ret void
}