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

    struct data tdata[] = { { -1, ""}, {0, "X0123"}, {1, "0X123"}, {2, "01X23"},
     {3, "012X3"}, {4, "0123X"}, {5, ""} };

    for (i = -1; i < 6; ++i) {
        kstring_t s = KS_INITIALIZE;
        kputs("0123", &s);
        if (kinsert_char('X', i, &s) < 0) {
            if ( i < 0 || i > 4) { ks_free(&s); continue; }  //expected failures
            fprintf(stderr, "kinsert_char failed\n");
            ks_free(&s);
            return -1;
        }
        if (s.s[s.l] != '\0') {
            fprintf(stderr, "No NUL termination on string from kinsert_char\n");
            ks_free(&s);
            return -1;
        }
        if (memcmp(s.s, tdata[i + 1].val, s.l + 1)) {
            fprintf(stderr, "kinsert_char comparison failed\n");
            ks_free(&s);
            return -1;
        }
        ks_free(&s);
    }
    //realloc checks
    for (i = 0; i < 7; ++i) {
        kputc('A' + i, &res);
        if (kinsert_char('A' + i, t.l, &t) < 0) {
            fprintf(stderr, "kinsert_char failed in realloc\n");
            ks_free(&res); ks_free(&t);
            return -1;
        }
        if (t.s[t.l] != '\0') {
            fprintf(stderr, "No NUL termination on string from kinsert_char in realloc\n");
            ks_free(&res); ks_free(&t);
            return -1;
        }
        if (memcmp(t.s, res.s, res.l+1)) {
            fprintf(stderr, "kinsert_char realloc comparison failed in realloc\n");
            ks_free(&res); ks_free(&t);
            return -1;
        }
    }
    ks_free(&t);
    ks_free(&res);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %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 0x6720(%rip), %rsi      # 0x8cb0
movl $0x70, %edx
callq 0x10e0
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
cmpl $0x6, -0x3c(%rbp)
jge 0x2700
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10b0
leaq 0x3fd2(%rip), %rdi      # 0x6597
leaq -0xc8(%rbp), %rsi
callq 0x34d0
movslq -0x3c(%rbp), %rsi
movl $0x58, %edi
leaq -0xc8(%rbp), %rdx
callq 0x37c0
cmpl $0x0, %eax
jge 0x2638
cmpl $0x0, -0x3c(%rbp)
jl 0x25f7
cmpl $0x4, -0x3c(%rbp)
jle 0x2608
leaq -0xc8(%rbp), %rdi
callq 0x35f0
jmp 0x26f2
movq 0x69c9(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3f9b(%rip), %rsi      # 0x65b4
movb $0x0, %al
callq 0x1170
leaq -0xc8(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
movq -0xb8(%rbp), %rax
movq -0xc8(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x267f
movq 0x6982(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3f69(%rip), %rsi      # 0x65c9
movb $0x0, %al
callq 0x1170
leaq -0xc8(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
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 0x26e6
movq 0x691b(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3f32(%rip), %rsi      # 0x65f9
movb $0x0, %al
callq 0x1170
leaq -0xc8(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
leaq -0xc8(%rbp), %rdi
callq 0x35f0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x25a1
movl $0x0, -0x3c(%rbp)
cmpl $0x7, -0x3c(%rbp)
jge 0x2812
movl -0x3c(%rbp), %edi
addl $0x41, %edi
leaq -0x38(%rbp), %rsi
callq 0x3890
movl -0x3c(%rbp), %eax
addl $0x41, %eax
movq -0x20(%rbp), %rsi
leaq -0x20(%rbp), %rdx
movsbl %al, %edi
callq 0x37c0
cmpl $0x0, %eax
jge 0x2771
movq 0x6896(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3ecd(%rip), %rsi      # 0x6619
movb $0x0, %al
callq 0x1170
leaq -0x38(%rbp), %rdi
callq 0x35f0
leaq -0x20(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x27b5
movq 0x684f(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3ea6(%rip), %rsi      # 0x6639
movb $0x0, %al
callq 0x1170
leaq -0x38(%rbp), %rdi
callq 0x35f0
leaq -0x20(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
callq 0x10a0
cmpl $0x0, %eax
je 0x2802
movq 0x6802(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3e94(%rip), %rsi      # 0x6674
movb $0x0, %al
callq 0x1170
leaq -0x38(%rbp), %rdi
callq 0x35f0
leaq -0x20(%rbp), %rdi
callq 0x35f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x282b
jmp 0x2804
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2707
leaq -0x20(%rbp), %rdi
callq 0x35f0
leaq -0x38(%rbp), %rdi
callq 0x35f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)