// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/test_kstring.c
// Function: test_kinsertstr
static int test_kinsertstr(void) {
    kstring_t t = KS_INITIALIZE, res = KS_INITIALIZE;
    int i = 0;
    struct data {
        int pos;
        const char *val;
    };

    struct data tdata[] = { { -1, ""}, {0, "XYZ0123"}, {1, "0XYZ123"},
     {2, "01XYZ23"}, {3, "012XYZ3"}, {4, "0123XYZ"}, {5, ""} };

    for (i = -1; i < 6; ++i) {
        kstring_t s = KS_INITIALIZE;
        kputs("0123", &s);
        if (kinsert_str("XYZ", i, &s) < 0) {
            if ( i < 0 || i > 4) { ks_free(&s); continue; }  //expected failures
            fprintf(stderr, "kinsert_str failed\n");
            return -1;
        }
        if (s.s[s.l] != '\0') {
            fprintf(stderr, "No NUL termination on string from kinsert_str\n");
            return -1;
        }
        if (memcmp(s.s, tdata[i + 1].val, s.l + 1)) {
            fprintf(stderr, "kinsert_str comparison failed\n");
            return -1;
        }
        ks_free(&s);
    }
    //realloc checks
    for (i = 0; i < 15; ++i) {
        kstring_t val = KS_INITIALIZE;
        ksprintf(&val, "%c", 'A' + i);
        kputs(val.s, &res);
        if (kinsert_str(val.s, t.l, &t) < 0) {
            ks_free(&val);
            fprintf(stderr, "kinsert_str failed in realloc\n");
            return -1;
        }
        if (t.s[t.l] != '\0') {
            ks_free(&val); ks_free(&res);
            fprintf(stderr, "No NUL termination on string from kinsert_str in realloc\n");
            return -1;
        }
        if (memcmp(t.s, res.s, res.l+1)) {
            ks_free(&val); ks_free(&res);
            fprintf(stderr, "kinsert_str realloc comparison failed in realloc\n");
            return -1;
        }
        ks_free(&val);
    }
    //empty strings
    ks_free(&t);
    if (kinsert_str("", 1, &t)) { //expected
        if (kinsert_str("", 0, &t) || t.l != 0) {
            fprintf(stderr, "kinsert_str empty insertion failed\n");
            return -1;
        }
    } else {
        fprintf(stderr, "kinsert_str empty ins to invalid pos succeeded\n");
        return -1;
    }
    i = res.l;
    if (kinsert_str("", 1, &res) || i != res.l) {
        fprintf(stderr, "kinsert_str empty ins to valid pos failed\n");
        ks_free(&res);
        return -1;
    }
    ks_free(&res);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10b0
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10b0
movl $0x0, -0x3c(%rbp)
leaq -0xb0(%rbp), %rdi
leaq 0x64a0(%rip), %rsi      # 0x8d20
movl $0x70, %edx
callq 0x10e0
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
cmpl $0x6, -0x3c(%rbp)
jge 0x29ce
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10b0
leaq 0x3ce2(%rip), %rdi      # 0x6597
leaq -0xc8(%rbp), %rsi
callq 0x34d0
movslq -0x3c(%rbp), %rsi
leaq 0x3dff(%rip), %rdi      # 0x66cb
leaq -0xc8(%rbp), %rdx
callq 0x3910
cmpl $0x0, %eax
jge 0x291e
cmpl $0x0, -0x3c(%rbp)
jl 0x28e9
cmpl $0x4, -0x3c(%rbp)
jle 0x28fa
leaq -0xc8(%rbp), %rdi
callq 0x35f0
jmp 0x29c0
movq 0x66d7(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3dc4(%rip), %rsi      # 0x66cf
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
movq -0xb8(%rbp), %rax
movq -0xc8(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2959
movq 0x669c(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3d9d(%rip), %rsi      # 0x66e3
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
movq -0xb8(%rbp), %rdi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0xb0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq -0xc8(%rbp), %rdx
addq $0x1, %rdx
callq 0x10a0
cmpl $0x0, %eax
je 0x29b4
movq 0x6641(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3d71(%rip), %rsi      # 0x6712
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
leaq -0xc8(%rbp), %rdi
callq 0x35f0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2891
movl $0x0, -0x3c(%rbp)
cmpl $0xf, -0x3c(%rbp)
jge 0x2b1d
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10b0
movl -0x3c(%rbp), %edx
addl $0x41, %edx
leaq -0xe0(%rbp), %rdi
leaq 0x3d2b(%rip), %rsi      # 0x6731
movb $0x0, %al
callq 0x4400
movq -0xd0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x34d0
movq -0xd0(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x3910
cmpl $0x0, %eax
jge 0x2a66
leaq -0xe0(%rbp), %rdi
callq 0x35f0
movq 0x658f(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3ce1(%rip), %rsi      # 0x6734
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2ab0
leaq -0xe0(%rbp), %rdi
callq 0x35f0
leaq -0x38(%rbp), %rdi
callq 0x35f0
movq 0x6545(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3cb6(%rip), %rsi      # 0x6753
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
callq 0x10a0
cmpl $0x0, %eax
je 0x2b03
leaq -0xe0(%rbp), %rdi
callq 0x35f0
leaq -0x38(%rbp), %rdi
callq 0x35f0
movq 0x64f2(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3c9d(%rip), %rsi      # 0x678d
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
leaq -0xe0(%rbp), %rdi
callq 0x35f0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x29d5
leaq -0x20(%rbp), %rdi
callq 0x35f0
leaq 0x3a68(%rip), %rdi      # 0x6595
movl $0x1, %esi
leaq -0x20(%rbp), %rdx
callq 0x3910
cmpl $0x0, %eax
je 0x2b86
leaq 0x3a4e(%rip), %rdi      # 0x6595
xorl %eax, %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdx
callq 0x3910
cmpl $0x0, %eax
jne 0x2b60
cmpq $0x0, -0x20(%rbp)
je 0x2b84
movq 0x6471(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3c4e(%rip), %rsi      # 0x67bf
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
jmp 0x2ba7
movq 0x644b(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3c4c(%rip), %rsi      # 0x67e3
movb $0x0, %al
callq 0x1170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
movq -0x38(%rbp), %rax
movl %eax, -0x3c(%rbp)
leaq 0x39e0(%rip), %rdi      # 0x6595
movl $0x1, %esi
leaq -0x38(%rbp), %rdx
callq 0x3910
cmpl $0x0, %eax
jne 0x2bd2
movslq -0x3c(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x2bfc
movq 0x63ff(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3c30(%rip), %rsi      # 0x6813
movb $0x0, %al
callq 0x1170
leaq -0x38(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c0c
leaq -0x38(%rbp), %rdi
callq 0x35f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)