#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 *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char const *, char *);
int /*<<< orphan*/ substr(char *, char *, int, int);
char *mysub(char *des, const char *pFuncStr, char *pSrc[]) {
  if (!des || !pFuncStr || !pSrc)
    return NULL;
  char funcStr[32] = {0};
  int index = 0;
  int begin = 0;
  int len = 0;
  char *pAdd = strstr(pFuncStr, "sub[");
  strcpy(funcStr, pAdd + 4);
  char *pIndex = strchr(funcStr, '|');
  if (!pIndex)
    return NULL;
  char *pBegin = strchr(pIndex + 1, '|');
  if (!pBegin)
    return NULL;
  char *pLen = strchr(pBegin + 1, ']');
  if (!pLen)
    return NULL;
  *pIndex = 0;
  index = atoi(funcStr);
  *pBegin = 0;
  begin = atoi(pIndex + 1);
  *pLen = 0;
  len = atoi(pBegin + 1);
  substr(des, pSrc[index], begin, len);
  return des;
}


x86 assembly (clang, -O0):
<mysub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1195 <mysub+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1195 <mysub+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <mysub+0x42>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <mysub+0x176>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rsi
add    $0x4,%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1216 <mysub+0xb6>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <mysub+0x176>
mov    -0x60(%rbp),%rdi
add    $0x1,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1244 <mysub+0xe4>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <mysub+0x176>
mov    -0x68(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1272 <mysub+0x112>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <mysub+0x176>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x60(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x48(%rbp)
mov    -0x70(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x48(%rbp),%edx
mov    -0x4c(%rbp),%ecx
call   1040 <substr@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysub>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     1241 <mysub+0xf1>
test   %rsi,%rsi
je     1241 <mysub+0xf1>
mov    %rdx,%r14
test   %rdx,%rdx
je     1241 <mysub+0xf1>
mov    %rdi,%r13
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xe6b(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <strstr@plt>
lea    0x4(%rax),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123b <mysub+0xeb>
mov    %rax,%rbx
lea    0x1(%rax),%r15
mov    %r15,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123b <mysub+0xeb>
mov    %rax,%rbp
lea    0x1(%rax),%rdi
mov    %rdi,0x8(%rsp)
mov    $0x5d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123b <mysub+0xeb>
mov    %rax,%r12
movb   $0x0,(%rbx)
lea    0x10(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
movb   $0x0,0x0(%rbp)
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
movb   $0x0,(%r12)
mov    0x8(%rsp),%rdi
call   1060 <atoi@plt>
movslq %ebx,%rcx
mov    (%r14,%rcx,8),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <substr@plt>
jmp    123e <mysub+0xee>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"sub[\00"
define i8* @mysub(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 %35
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 = getelementptr inbounds i8, i8* %12, i64 4
%14 = call i32 @strcpy(i8* %11, i8* %13)
%15 = call i8* @strchr(i8* %11, i8 signext 124)
%16 = icmp eq i8* %15, null
br i1 %16, label %33, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = call i8* @strchr(i8* %18, i8 signext 124)
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %19, i64 1
%23 = call i8* @strchr(i8* %22, i8 signext 93)
%24 = icmp eq i8* %23, null
br i1 %24, label %33, label %25
25: ; preds = %21
store i8 0, i8* %15
%26 = call i32 @atoi(i8* %11)
store i8 0, i8* %19
%27 = call i32 @atoi(i8* %18)
store i8 0, i8* %23
%28 = call i32 @atoi(i8* %22)
%29 = sext i32 %26 to i64
%30 = getelementptr inbounds i8*, i8** %2, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @substr(i8* %0, i8* %31, i32 %27, i32 %28)
br label %33
33: ; preds = %17, %21, %25, %10
%34 = phi i8* [ null, %10 ], [ null, %17 ], [ %0, %25 ], [ null, %21 ]
br label %35
35: ; preds = %3, %33
%36 = phi i8* [ %34, %33 ], [ null, %3 ]
ret i8* %36
}