#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ strcmp(char *, char *);
int strconcat(char *, int, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
void test_strconcat(void) {
  char str[64], str2[64];
  int n;
  n = strconcat(str, sizeof(str), "hello", " ", "world", NULL);
  assert(n == 11);
  assert(strcmp(str, "hello world") == 0);
  n = strconcat(NULL, 0, "hello", " ", "world", NULL);
  assert(n == 0);
  n = strconcat(str, 10, "hello", " ", "world", NULL);
  assert(n == 9);
  assert(strcmp(str, "hello wor") == 0);
  n = strconcat(str, 5, "hello", " ", "world", NULL);
  assert(n == 4);
  assert(strcmp(str, "hell") == 0);
  strcpy(str2, " and ");
  n = strconcat(str, sizeof(str), "hello", str2, "world", NULL);
  assert(n == 15);
  assert(strcmp(str, "hello and world") == 0);
}


x86 assembly (clang, -O0):
<test_strconcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x40(%rbp),%rdi
mov    $0x40,%esi
lea    0xea5(%rip),%rdx
lea    0xec3(%rip),%rcx
lea    0xec8(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1040 <strconcat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xb,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
mov    %eax,%r9d
xor    %esi,%esi
lea    0xe44(%rip),%rdx
lea    0xe62(%rip),%rcx
lea    0xe67(%rip),%r8
mov    %r9,%rdi
call   1040 <strconcat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
mov    $0xa,%esi
lea    0xe04(%rip),%rdx
lea    0xe22(%rip),%rcx
lea    0xe27(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1040 <strconcat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x9,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
lea    0xda1(%rip),%rdx
lea    0xdbf(%rip),%rcx
lea    0xdc4(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1040 <strconcat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x4,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x80(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x80(%rbp),%rcx
mov    $0x40,%esi
lea    0xd2a(%rip),%rdx
lea    0xd54(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1040 <strconcat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xf,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
lea    0xd1b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strconcat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xea9(%rip),%r14
lea    0xec7(%rip),%r12
lea    0xecc(%rip),%r15
lea    0x40(%rsp),%r13
mov    %r13,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %r9d,%r9d
call   1040 <strconcat@plt>
xor    %edi,%edi
cmp    $0xb,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xe6e(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %r9d,%r9d
call   1040 <strconcat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %r13,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %r9d,%r9d
call   1040 <strconcat@plt>
xor    %edi,%edi
cmp    $0x9,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xe14(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %r13,%rdi
mov    $0x5,%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %r9d,%r9d
call   1040 <strconcat@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xdda(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xdc2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
xor    %r9d,%r9d
call   1040 <strconcat@plt>
xor    %edi,%edi
cmp    $0xf,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xd8f(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"world\00"
@.str.3 = [12 x i8] c"hello world\00"
@.str.4 = [10 x i8] c"hello wor\00"
@.str.5 = [5 x i8] c"hell\00"
@.str.6 = [6 x i8] c" and \00"
@.str.7 = [16 x i8] c"hello and world\00"
define void @test_strconcat() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%5 = call i32 @strconcat(i8* %4, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 11
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i32 @strconcat(i8* null, i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%21 = call i32 @strconcat(i8* %20, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 9
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%32 = call i32 @strconcat(i8* %31, i32 5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 4
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%46 = call i32 @strconcat(i8* %44, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %46, i32* %3
%47 = load i32, i32* %3
%48 = icmp eq i32 %47, 15
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"world\00"
@.str.3 = [12 x i8] c"hello world\00"
@.str.4 = [10 x i8] c"hello wor\00"
@.str.5 = [5 x i8] c"hell\00"
@.str.6 = [6 x i8] c" and \00"
@.str.7 = [16 x i8] c"hello and world\00"
define void @test_strconcat() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i32 @strconcat(i8* %3, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%6 = icmp eq i32 %5, 11
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @strconcat(i8* null, i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @strconcat(i8* %3, i32 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%18 = icmp eq i32 %17, 9
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @strconcat(i8* %3, i32 5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%26 = icmp eq i32 %25, 4
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @strconcat(i8* %3, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%35 = icmp eq i32 %34, 15
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
ret void
}