#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 atoi(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char const *, char *);
char *myadd(char *des, const char *pFuncStr, char *pSrc[]) {
  if (!des || !pFuncStr || !pSrc)
    return NULL;
  char funcStr[32] = {0};
  int index1 = 0;
  int index2 = 0;
  char *pIndex1 = strstr(pFuncStr, "add[");
  if (!pIndex1)
    return NULL;
  strcpy(funcStr, pIndex1 + 4);
  char *pIndex2 = strchr(funcStr, '|');
  if (!pIndex2)
    return NULL;
  char *pEnd = strchr(pIndex2 + 1, ']');
  if (!pEnd)
    return NULL;
  *pIndex2 = 0;
  index1 = atoi(funcStr);
  *pEnd = 0;
  index2 = atoi(pIndex2 + 1);
  strcpy(des, pSrc[index1]);
  strcat(des, pSrc[index2]);
  return des;
}


x86 assembly (clang, -O0):
<myadd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1195 <myadd+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1195 <myadd+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <myadd+0x42>
movq   $0x0,-0x8(%rbp)
jmp    12b1 <myadd+0x151>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11ec <myadd+0x8c>
movq   $0x0,-0x8(%rbp)
jmp    12b1 <myadd+0x151>
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    $0x4,%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1227 <myadd+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    12b1 <myadd+0x151>
mov    -0x58(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1255 <myadd+0xf5>
movq   $0x0,-0x8(%rbp)
jmp    12b1 <myadd+0x151>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myadd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     1228 <myadd+0xd8>
test   %rsi,%rsi
je     1228 <myadd+0xd8>
mov    %rdx,%r14
test   %rdx,%rdx
je     1228 <myadd+0xd8>
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe6c(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1223 <myadd+0xd3>
add    $0x4,%rax
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x7c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1223 <myadd+0xd3>
mov    %rax,%r12
lea    0x1(%rax),%r15
mov    %r15,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1223 <myadd+0xd3>
mov    %rax,%r13
movb   $0x0,(%r12)
mov    %rsp,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
movb   $0x0,0x0(%r13)
mov    %r15,%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
movslq %ebp,%rax
mov    (%r14,%rax,8),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
movslq %r15d,%rax
mov    (%r14,%rax,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
jmp    1225 <myadd+0xd5>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"add[\00"
define i8* @myadd(i8* %0, i8* %1, i8** %2) {
%4 = alloca [32 x i8]
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
%8 = icmp ne i8** %2, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %36
10: ; preds = %3
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = tail call i8* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %34, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %12, i64 4
%16 = call i32 @strcpy(i8* %11, i8* %15)
%17 = call i8* @strchr(i8* %11, i8 signext 124)
%18 = icmp eq i8* %17, null
br i1 %18, label %34, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = call i8* @strchr(i8* %20, i8 signext 93)
%22 = icmp eq i8* %21, null
br i1 %22, label %34, label %23
23: ; preds = %19
store i8 0, i8* %17
%24 = call i32 @atoi(i8* %11)
store i8 0, i8* %21
%25 = call i32 @atoi(i8* %20)
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8*, i8** %2, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strcpy(i8* %0, i8* %28)
%30 = sext i32 %25 to i64
%31 = getelementptr inbounds i8*, i8** %2, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcat(i8* %0, i8* %32)
br label %34
34: ; preds = %14, %19, %23, %10
%35 = phi i8* [ null, %10 ], [ null, %14 ], [ %0, %23 ], [ null, %19 ]
br label %36
36: ; preds = %3, %34
%37 = phi i8* [ %35, %34 ], [ null, %3 ]
ret i8* %37
}