#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*/ free_array(char **, int);
int /*<<< orphan*/ printf(char *, ...);
char **split_string_by_array(char *, int *, int);
scalar_t__ strcmp(char *, char *);
void test_split_string_by_array() {
  printf("Testing split_string_by_array\n\n");
  int correct, i;
  int len = 5;
  int x[5] = {1, 1, 3, 0, 1};
  char *answer1[5] = {"a", "b", "cde", "", "f"};
  char **result = split_string_by_array("abcdef", x, len);
  if (result == NULL)
    return;
  printf("split_string_by_array on \"abcdef\" with 1,1,3,0,1 returns:\n");
  for (i = 0; i < len; i++)
    printf("   \"%s\"%s", result[i], (i == len - 1 ? "" : ", "));
  correct = 1;
  for (i = 0; i < len; i++)
    correct = correct && (strcmp(answer1[i], result[i]) == 0);
  printf("     (%s)\n\n", correct ? "Correct" : "Failed");
  free_array(result, len);
  len = 3;
  int y[3] = {1, 2, 1};
  char *answer2[3] = {"a", "bc", "d"};
  result = split_string_by_array("abcdef", y, len);
  printf("split_string_by_array on \"abcdef\" with 1,2,1 returns:\n");
  for (i = 0; i < len; i++)
    printf("   \"%s\"%s", result[i], (i == len - 1 ? "" : ", "));
  correct = 1;
  for (i = 0; i < len; i++)
    correct = correct && (strcmp(answer2[i], result[i]) == 0);
  printf("     (%s)\n\n", correct ? "Correct" : "Failed");
  free_array(result, len);
  len = 3;
  int z[3] = {1, 2, 1};
  char *answer3[3] = {"a", "b", ""};
  result = split_string_by_array("ab", z, len);
  printf("split_string_by_array on \"ab\" with 1,2,1 returns:\n");
  for (i = 0; i < len; i++)
    printf("   \"%s\"%s", result[i], (i == len - 1 ? "" : ", "));
  correct = 1;
  for (i = 0; i < len; i++)
    correct = correct && (strcmp(answer3[i], result[i]) == 0);
  printf("     (%s)\n\n", correct ? "Correct" : "Failed");
  free_array(result, len);
}


x86 assembly (clang, -O0):
<test_split_string_by_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x5,-0xc(%rbp)
mov    0xf89(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf86(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xf84(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xe7a(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xf1a(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe66(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe59(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe42(%rip),%rdi
call   1070 <split_string_by_array@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11fd <test_split_string_by_array+0xad>
jmp    15cd <test_split_string_by_array+0x47d>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1263 <test_split_string_by_array+0x113>
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
lea    0xe38(%rip),%rdx
lea    0xe3f(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1212 <test_split_string_by_array+0xc2>
movl   $0x1,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d2 <test_split_string_by_array+0x182>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xb1(%rbp)
je     12b6 <test_split_string_by_array+0x166>
movslq -0x8(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rdi
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0xb1(%rbp)
mov    -0xb1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1271 <test_split_string_by_array+0x121>
mov    -0x4(%rbp),%ecx
lea    0xdad(%rip),%rsi
lea    0xd9e(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <free_array@plt>
movl   $0x3,-0xc(%rbp)
mov    0xe02(%rip),%rax
mov    %rax,-0x64(%rbp)
mov    0xe00(%rip),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2aba(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0x2ab7(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0x2ab4(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x64(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xcd8(%rip),%rdi
call   1070 <split_string_by_array@plt>
mov    %rax,-0x58(%rbp)
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13bd <test_split_string_by_array+0x26d>
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
lea    0xcde(%rip),%rdx
lea    0xce5(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    136c <test_split_string_by_array+0x21c>
movl   $0x1,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    142c <test_split_string_by_array+0x2dc>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xb2(%rbp)
je     1410 <test_split_string_by_array+0x2c0>
movslq -0x8(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0xb2(%rbp)
mov    -0xb2(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    13cb <test_split_string_by_array+0x27b>
mov    -0x4(%rbp),%ecx
lea    0xc53(%rip),%rsi
lea    0xc44(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xc2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <free_array@plt>
movl   $0x3,-0xc(%rbp)
mov    0xcb4(%rip),%rax
mov    %rax,-0x8c(%rbp)
mov    0xcaf(%rip),%eax
mov    %eax,-0x84(%rbp)
mov    0x297a(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2974(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0x296e(%rip),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x8c(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xc10(%rip),%rdi
call   1070 <split_string_by_array@plt>
mov    %rax,-0x58(%rbp)
lea    0xc03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1529 <test_split_string_by_array+0x3d9>
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
lea    0xb72(%rip),%rdx
lea    0xb79(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xb54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    14d8 <test_split_string_by_array+0x388>
movl   $0x1,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    159b <test_split_string_by_array+0x44b>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xb3(%rbp)
je     157f <test_split_string_by_array+0x42f>
movslq -0x8(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
mov    -0x58(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0xb3(%rbp)
mov    -0xb3(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1537 <test_split_string_by_array+0x3e7>
mov    -0x4(%rbp),%ecx
lea    0xae4(%rip),%rsi
lea    0xad5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xabb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <free_array@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_split_string_by_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
mov    0xea0(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xe85(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xe9f(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x5,%edx
call   1070 <split_string_by_array@plt>
test   %rax,%rax
je     1486 <test_split_string_by_array+0x336>
mov    %rax,%rbx
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe75(%rip),%r14
lea    0xe78(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%rsi
lea    0xe3b(%rip),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xe02(%rip),%rdi
call   1060 <strcmp@plt>
lea    0xe24(%rip),%r14
mov    %r14,%rsi
test   %rax,%rax
jne    129f <test_split_string_by_array+0x14f>
mov    0x8(%rbx),%rsi
lea    0xe1c(%rip),%rdi
call   1060 <strcmp@plt>
mov    %r14,%rsi
test   %rax,%rax
jne    129f <test_split_string_by_array+0x14f>
mov    0x10(%rbx),%rsi
lea    0xdcd(%rip),%rdi
call   1060 <strcmp@plt>
mov    %r14,%rsi
test   %rax,%rax
jne    129f <test_split_string_by_array+0x14f>
mov    0x18(%rbx),%rsi
lea    0xdd8(%rip),%rdi
call   1060 <strcmp@plt>
mov    %r14,%rsi
test   %rax,%rax
jne    129f <test_split_string_by_array+0x14f>
mov    0x20(%rbx),%rsi
lea    0xda6(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xdb2(%rip),%rax
lea    0xdb3(%rip),%rsi
cmove  %rax,%rsi
lea    0xd94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <free_array@plt>
mov    0xd5b(%rip),%r13d
mov    %r13d,0x18(%rsp)
mov    0xd47(%rip),%rbp
mov    %rbp,0x10(%rsp)
lea    0xd4d(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x3,%edx
call   1070 <split_string_by_array@plt>
mov    %rax,%rbx
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xd2c(%rip),%r15
lea    0xd2f(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xd14(%rip),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xcdb(%rip),%rdi
call   1060 <strcmp@plt>
mov    %r14,%rsi
test   %rax,%rax
jne    138f <test_split_string_by_array+0x23f>
mov    0x8(%rbx),%rsi
lea    0xcf8(%rip),%rdi
call   1060 <strcmp@plt>
mov    %r14,%rsi
test   %rax,%rax
jne    138f <test_split_string_by_array+0x23f>
mov    0x10(%rbx),%rsi
lea    0xcde(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xcc2(%rip),%rax
lea    0xcc3(%rip),%rsi
cmove  %rax,%rsi
lea    0xca4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <free_array@plt>
mov    %r13d,0x8(%rsp)
mov    %rbp,(%rsp)
lea    0xc9e(%rip),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1070 <split_string_by_array@plt>
mov    %rax,%rbx
lea    0xd19(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xc4d(%rip),%r15
lea    0xc50(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xc35(%rip),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xbfc(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1468 <test_split_string_by_array+0x318>
mov    0x8(%rbx),%rsi
lea    0xc20(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1468 <test_split_string_by_array+0x318>
mov    0x10(%rbx),%rsi
lea    0xbf7(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xbe9(%rip),%rax
lea    0xbea(%rip),%r14
cmove  %rax,%r14
lea    0xbcb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <free_array@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Testing split_string_by_array\0A\0A\00"
@__const.test_split_string_by_array.x = [5 x i32] [i32 1, i32 1, i32 3, i32 0, i32 1]
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"b\00"
@.str.3 = [4 x i8] c"cde\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [2 x i8] c"f\00"
@.str.6 = [7 x i8] c"abcdef\00"
@.str.7 = [59 x i8] c"split_string_by_array on \22abcdef\22 with 1,1,3,0,1 returns:\0A\00"
@.str.8 = [10 x i8] c" \22%s\22%s\00"
@.str.9 = [3 x i8] c", \00"
@.str.10 = [12 x i8] c" (%s)\0A\0A\00"
@.str.11 = [8 x i8] c"Correct\00"
@.str.12 = [7 x i8] c"Failed\00"
@__const.test_split_string_by_array.y = [3 x i32] [i32 1, i32 2, i32 1]
@.str.13 = [3 x i8] c"bc\00"
@.str.14 = [2 x i8] c"d\00"
@__const.test_split_string_by_array.answer2 = [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i32 0, i32 0)]
@.str.15 = [55 x i8] c"split_string_by_array on \22abcdef\22 with 1,2,1 returns:\0A\00"
@__const.test_split_string_by_array.z = [3 x i32] [i32 1, i32 2, i32 1]
@__const.test_split_string_by_array.answer3 = [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)]
@.str.16 = [3 x i8] c"ab\00"
@.str.17 = [51 x i8] c"split_string_by_array on \22ab\22 with 1,2,1 returns:\0A\00"
define void @test_split_string_by_array() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x i32]
%5 = alloca [5 x i8*]
%6 = alloca i8**
%7 = alloca [3 x i32]
%8 = alloca [3 x i8*]
%9 = alloca [3 x i32]
%10 = alloca [3 x i8*]
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 5, i32* %3
%12 = bitcast [5 x i32]* %4 to i8*
%13 = bitcast [5 x i8*]* %5 to i8*
%14 = bitcast i8* %13 to [5 x i8*]*
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i32 0, i32 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i32 0, i32 3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %14, i32 0, i32 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i8** @split_string_by_array(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %20, i32 %21)
store i8** %22, i8*** %6
%23 = load i8**, i8*** %6
%24 = icmp eq i8** %23, null
br i1 %24, label %25, label %26
25: ; preds = %0
br label %205
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %2
br label %28
28: ; preds = %45, %26
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %48
32: ; preds = %28
%33 = load i8**, i8*** %6
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = sub nsw i32 %39, 1
%41 = icmp eq i32 %38, %40
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %37, i8* %43)
br label %45
45: ; preds = %32
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %28
48: ; preds = %28
store i32 1, i32* %1
store i32 0, i32* %2
br label %49
49: ; preds = %71, %48
%50 = load i32, i32* %2
%51 = load i32, i32* %3
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %74
53: ; preds = %49
%54 = load i32, i32* %1
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %68
56: ; preds = %53
%57 = load i32, i32* %2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %58
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %6
%62 = load i32, i32* %2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %60, i8* %65)
%67 = icmp eq i64 %66, 0
br label %68
68: ; preds = %56, %53
%69 = phi i1 [ false, %53 ], [ %67, %56 ]
%70 = zext i1 %69 to i32
store i32 %70, i32* %1
br label %71
71: ; preds = %68
%72 = load i32, i32* %2
%73 = add nsw i32 %72, 1
store i32 %73, i32* %2
br label %49
74: ; preds = %49
%75 = load i32, i32* %1
%76 = icmp ne i32 %75, 0
%77 = zext i1 %76 to i64
%78 = select i1 %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %78)
%80 = load i8**, i8*** %6
%81 = load i32, i32* %3
%82 = call i32 @free_array(i8** %80, i32 %81)
store i32 3, i32* %3
%83 = bitcast [3 x i32]* %7 to i8*
%84 = bitcast [3 x i8*]* %8 to i8*
%85 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%86 = load i32, i32* %3
%87 = call i8** @split_string_by_array(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %85, i32 %86)
store i8** %87, i8*** %6
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %2
br label %89
89: ; preds = %106, %74
%90 = load i32, i32* %2
%91 = load i32, i32* %3
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %109
93: ; preds = %89
%94 = load i8**, i8*** %6
%95 = load i32, i32* %2
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = load i32, i32* %2
%100 = load i32, i32* %3
%101 = sub nsw i32 %100, 1
%102 = icmp eq i32 %99, %101
%103 = zext i1 %102 to i64
%104 = select i1 %102, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0)
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %98, i8* %104)
br label %106
106: ; preds = %93
%107 = load i32, i32* %2
%108 = add nsw i32 %107, 1
store i32 %108, i32* %2
br label %89
109: ; preds = %89
store i32 1, i32* %1
store i32 0, i32* %2
br label %110
110: ; preds = %132, %109
%111 = load i32, i32* %2
%112 = load i32, i32* %3
%113 = icmp slt i32 %111, %112
br i1 %113, label %114, label %135
114: ; preds = %110
%115 = load i32, i32* %1
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %129
117: ; preds = %114
%118 = load i32, i32* %2
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 %119
%121 = load i8*, i8** %120
%122 = load i8**, i8*** %6
%123 = load i32, i32* %2
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8*, i8** %122, i64 %124
%126 = load i8*, i8** %125
%127 = call i64 @strcmp(i8* %121, i8* %126)
%128 = icmp eq i64 %127, 0
br label %129
129: ; preds = %117, %114
%130 = phi i1 [ false, %114 ], [ %128, %117 ]
%131 = zext i1 %130 to i32
store i32 %131, i32* %1
br label %132
132: ; preds = %129
%133 = load i32, i32* %2
%134 = add nsw i32 %133, 1
store i32 %134, i32* %2
br label %110
135: ; preds = %110
%136 = load i32, i32* %1
%137 = icmp ne i32 %136, 0
%138 = zext i1 %137 to i64
%139 = select i1 %137, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %139)
%141 = load i8**, i8*** %6
%142 = load i32, i32* %3
%143 = call i32 @free_array(i8** %141, i32 %142)
store i32 3, i32* %3
%144 = bitcast [3 x i32]* %9 to i8*
%145 = bitcast [3 x i8*]* %10 to i8*
%146 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%147 = load i32, i32* %3
%148 = call i8** @split_string_by_array(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i32* %146, i32 %147)
store i8** %148, i8*** %6
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %2
br label %150
150: ; preds = %167, %135
%151 = load i32, i32* %2
%152 = load i32, i32* %3
%153 = icmp slt i32 %151, %152
br i1 %153, label %154, label %170
154: ; preds = %150
%155 = load i8**, i8*** %6
%156 = load i32, i32* %2
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i8*, i8** %155, i64 %157
%159 = load i8*, i8** %158
%160 = load i32, i32* %2
%161 = load i32, i32* %3
%162 = sub nsw i32 %161, 1
%163 = icmp eq i32 %160, %162
%164 = zext i1 %163 to i64
%165 = select i1 %163, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0)
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %159, i8* %165)
br label %167
167: ; preds = %154
%168 = load i32, i32* %2
%169 = add nsw i32 %168, 1
store i32 %169, i32* %2
br label %150
170: ; preds = %150
store i32 1, i32* %1
store i32 0, i32* %2
br label %171
171: ; preds = %193, %170
%172 = load i32, i32* %2
%173 = load i32, i32* %3
%174 = icmp slt i32 %172, %173
br i1 %174, label %175, label %196
175: ; preds = %171
%176 = load i32, i32* %1
%177 = icmp ne i32 %176, 0
br i1 %177, label %178, label %190
178: ; preds = %175
%179 = load i32, i32* %2
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %180
%182 = load i8*, i8** %181
%183 = load i8**, i8*** %6
%184 = load i32, i32* %2
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i8*, i8** %183, i64 %185
%187 = load i8*, i8** %186
%188 = call i64 @strcmp(i8* %182, i8* %187)
%189 = icmp eq i64 %188, 0
br label %190
190: ; preds = %178, %175
%191 = phi i1 [ false, %175 ], [ %189, %178 ]
%192 = zext i1 %191 to i32
store i32 %192, i32* %1
br label %193
193: ; preds = %190
%194 = load i32, i32* %2
%195 = add nsw i32 %194, 1
store i32 %195, i32* %2
br label %171
196: ; preds = %171
%197 = load i32, i32* %1
%198 = icmp ne i32 %197, 0
%199 = zext i1 %198 to i64
%200 = select i1 %198, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %200)
%202 = load i8**, i8*** %6
%203 = load i32, i32* %3
%204 = call i32 @free_array(i8** %202, i32 %203)
br label %205
205: ; preds = %196, %25
ret void
}

LLVM IR (-O2):
@__const.test_split_string_by_array.x = [5 x i32] [i32 1, i32 1, i32 3, i32 0, i32 1]
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"b\00"
@.str.3 = [4 x i8] c"cde\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [2 x i8] c"f\00"
@.str.6 = [7 x i8] c"abcdef\00"
@.str.8 = [10 x i8] c" \22%s\22%s\00"
@.str.9 = [3 x i8] c", \00"
@.str.10 = [12 x i8] c" (%s)\0A\0A\00"
@.str.11 = [8 x i8] c"Correct\00"
@.str.12 = [7 x i8] c"Failed\00"
@.str.13 = [3 x i8] c"bc\00"
@.str.14 = [2 x i8] c"d\00"
@__const.test_split_string_by_array.z = [3 x i32] [i32 1, i32 2, i32 1]
@.str.16 = [3 x i8] c"ab\00"
@str = [31 x i8] c"Testing split_string_by_array\0A\00"
@str.18 = [58 x i8] c"split_string_by_array on \22abcdef\22 with 1,1,3,0,1 returns:\00"
@str.19 = [54 x i8] c"split_string_by_array on \22abcdef\22 with 1,2,1 returns:\00"
@str.20 = [50 x i8] c"split_string_by_array on \22ab\22 with 1,2,1 returns:\00"
define void @test_split_string_by_array() {
%1 = alloca [5 x i32]
%2 = alloca [3 x i32]
%3 = alloca [3 x i32]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%5 = bitcast [5 x i32]* %1 to i8*
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%7 = call i8** @split_string_by_array(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %6, i32 5)
%8 = icmp eq i8** %7, null
br i1 %8, label %105, label %9
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.18, i64 0, i64 0))
%11 = load i8*, i8** %7
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %7, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %7, i64 2
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%19 = getelementptr inbounds i8*, i8** %7, i64 3
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%22 = getelementptr inbounds i8*, i8** %7, i64 4
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%25 = load i8*, i8** %7
%26 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %45
28: ; preds = %9
%29 = load i8*, i8** %13
%30 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i8*, i8** %16
%34 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8*, i8** %19
%38 = call i64 @strcmp(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8*, i8** %22
%42 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = icmp eq i64 %42, 0
%44 = select i1 %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
br label %45
45: ; preds = %9, %28, %32, %40, %36
%46 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %36 ], [ %44, %40 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %32 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %28 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %9 ]
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %46)
%48 = call i32 @free_array(i8** %7, i32 5)
%49 = bitcast [3 x i32]* %2 to i8*
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%51 = call i8** @split_string_by_array(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %50, i32 3)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.19, i64 0, i64 0))
%53 = load i8*, i8** %51
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%55 = getelementptr inbounds i8*, i8** %51, i64 1
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%58 = getelementptr inbounds i8*, i8** %51, i64 2
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %59, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%61 = load i8*, i8** %51
%62 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %73
64: ; preds = %45
%65 = load i8*, i8** %55
%66 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8*, i8** %58
%70 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0), i8* %69)
%71 = icmp eq i64 %70, 0
%72 = select i1 %71, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
br label %73
73: ; preds = %45, %68, %64
%74 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %64 ], [ %72, %68 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %45 ]
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %74)
%76 = call i32 @free_array(i8** %51, i32 3)
%77 = bitcast [3 x i32]* %3 to i8*
%78 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%79 = call i8** @split_string_by_array(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i32* %78, i32 3)
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.20, i64 0, i64 0))
%81 = load i8*, i8** %79
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%83 = getelementptr inbounds i8*, i8** %79, i64 1
%84 = load i8*, i8** %83
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%86 = getelementptr inbounds i8*, i8** %79, i64 2
%87 = load i8*, i8** %86
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %87, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%89 = load i8*, i8** %79
%90 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %89)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %101
92: ; preds = %73
%93 = load i8*, i8** %83
%94 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %92
%97 = load i8*, i8** %86
%98 = call i64 @strcmp(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* %97)
%99 = icmp eq i64 %98, 0
%100 = select i1 %99, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
br label %101
101: ; preds = %73, %96, %92
%102 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %92 ], [ %100, %96 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), %73 ]
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %102)
%104 = call i32 @free_array(i8** %79, i32 3)
br label %105
105: ; preds = %0, %101
ret void
}