#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*/ bubble_sort(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ *strchr(char const *, char const);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *join_arr(const char srcA[], const char srcB[]) {
  size_t lenA = strlen(srcA);
  size_t lenB = strlen(srcB);
  size_t tempSize = lenA + lenB + 1;
  int i, index = 0;
  char temp[tempSize];
  for (i = 0; i < lenA; i++) {
    if (strchr(srcB, srcA[i]) != NULL) {
      temp[index++] = srcA[i];
      temp[index] = '\0';
    }
  }
  bubble_sort(temp, index);
  char *result = (char *)malloc(index + 1);
  strncpy(result, temp, index);
  result[index] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<join_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0x1(%rax,%rcx,1),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1228 <join_arr+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1215 <join_arr+0xc5>
mov    -0x50(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    121a <join_arr+0xca>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c0 <join_arr+0x70>
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <bubble_sort@plt>
mov    -0x30(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    -0x50(%rbp),%rsi
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x48(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_arr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r14,-0x30(%rbp)
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r13,%rax
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
test   %r13,%r13
je     11d4 <join_arr+0x84>
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11a9 <join_arr+0x59>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%r13
je     11d7 <join_arr+0x87>
movsbl (%rbx,%r14,1),%esi
mov    -0x30(%rbp),%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a0 <join_arr+0x50>
movzbl (%rbx,%r14,1),%eax
movslq %r12d,%rcx
lea    0x1(%rcx),%r12
mov    %al,(%r15,%rcx,1)
movb   $0x0,0x1(%r15,%rcx,1)
jmp    11a0 <join_arr+0x50>
xor    %r12d,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1070 <bubble_sort@plt>
lea    0x1(%r12),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @join_arr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %5
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = add i64 %17, %18
%20 = add i64 %19, 1
store i64 %20, i64* %7
store i32 0, i32* %9
%21 = load i64, i64* %7
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %10
%23 = alloca i8, i64 %21
store i64 %21, i64* %11
store i32 0, i32* %8
br label %24
24: ; preds = %52, %2
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = load i64, i64* %5
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %55
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8*, i8** %3
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i32* @strchr(i8* %30, i8 signext %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %51
38: ; preds = %29
%39 = load i8*, i8** %3
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %23, i64 %46
store i8 %43, i8* %47
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %23, i64 %49
store i8 0, i8* %50
br label %51
51: ; preds = %38, %29
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %24
55: ; preds = %24
%56 = load i32, i32* %9
%57 = call i32 @bubble_sort(i8* %23, i32 %56)
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i8*
store i8* %61, i8** %12
%62 = load i8*, i8** %12
%63 = load i32, i32* %9
%64 = call i32 @strncpy(i8* %62, i8* %23, i32 %63)
%65 = load i8*, i8** %12
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
%69 = load i8*, i8** %12
%70 = load i8*, i8** %10
ret i8* %69
}

LLVM IR (-O2):
define i8* @join_arr(i8* nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 1
%6 = add i64 %5, %4
%7 = alloca i8, i64 %6
%8 = icmp eq i64 %3, 0
br i1 %8, label %27, label %9
9: ; preds = %2, %23
%10 = phi i64 [ %25, %23 ], [ 0, %2 ]
%11 = phi i32 [ %24, %23 ], [ 0, %2 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = tail call i32* @strchr(i8* %1, i8 signext %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %23, label %16
16: ; preds = %9
%17 = load i8, i8* %12
%18 = add nsw i32 %11, 1
%19 = sext i32 %11 to i64
%20 = getelementptr inbounds i8, i8* %7, i64 %19
store i8 %17, i8* %20
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds i8, i8* %7, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %9, %16
%24 = phi i32 [ %18, %16 ], [ %11, %9 ]
%25 = add nuw i64 %10, 1
%26 = icmp eq i64 %25, %3
br i1 %26, label %27, label %9
27: ; preds = %23, %2
%28 = phi i32 [ 0, %2 ], [ %24, %23 ]
%29 = call i32 @bubble_sort(i8* %7, i32 %28)
%30 = add nsw i32 %28, 1
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
%33 = call i32 @strncpy(i8* %32, i8* %7, i32 %28)
%34 = sext i32 %28 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
ret i8* %32
}