// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_char_position
static s7_pointer g_char_position(s7_scheme *sc, s7_pointer args)
    {
#define H_char_position "(char-position char-or-str str (start 0)) returns the position of the first occurrence of char in str, or #f"
#define Q_char_position s7_make_signature(sc, 4, s7_make_signature(sc, 2, sc->is_integer_symbol, sc->not_symbol), s7_make_signature(sc, 2, sc->is_char_symbol, sc->is_string_symbol), sc->is_string_symbol, sc->is_integer_symbol)

        const char *porig, *pset;
        s7_int start, pos, len; /* not "int" because start arg might be most-negative-fixnum */
        s7_pointer arg1, arg2;

        arg1 = car(args);
        if ((!s7_is_character(arg1)) &&
                (!is_string(arg1)))
            return(method_or_bust(sc, arg1, sc->char_position_symbol, args, T_CHARACTER, 1));

        arg2 = cadr(args);
        if (!is_string(arg2))
            return(method_or_bust(sc, arg2, sc->char_position_symbol, args, T_STRING, 2));

        if (is_pair(cddr(args)))
        {
            s7_pointer arg3;
            arg3 = caddr(args);
            if (!s7_is_integer(arg3))
                return(method_or_bust(sc, arg3, sc->char_position_symbol, args, T_INTEGER, 3));
            start = s7_integer(arg3);
            if (start < 0)
                return(wrong_type_argument_with_type(sc, sc->char_position_symbol, 3, arg3, a_non_negative_integer_string));
        }
        else start = 0;

        porig = string_value(arg2);
        len = string_length(arg2);
        if (start >= len) return(sc->F);

        if (s7_is_character(arg1))
        {
            char c;
            const char *p;
            c = character(arg1);
            p = strchr((const char *)(porig + start), (int)c); /* use strchrnul in Gnu C to catch embedded null case */
            if (p)
                return(make_integer(sc, p - porig));
            return(sc->F);
        }

        if (string_length(arg1) == 0)
            return(sc->F);
        pset = string_value(arg1);

        pos = strcspn((const char *)(porig + start), (const char *)pset);
        if ((pos + start) < len)
            return(make_integer(sc, pos + start));

        /* if the string has an embedded null, we can get erroneous results here --
         *   perhaps check for null at pos+start?  What about a searched-for string that also has embedded nulls?
         */
        return(sc->F);
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x8(%rsi), %rsi
movzbl (%rsi), %edx
cmpl $0x8, %edx
je 0x5ad66
cmpl $0x13, %edx
jne 0x5ade0
movq 0x10(%rcx), %rdi
movq 0x8(%rdi), %rax
cmpb $0x13, (%rax)
jne 0x5adc9
movq 0x10(%rdi), %rdi
cmpb $0x1, (%rdi)
jne 0x5adf4
movq 0x8(%rdi), %r10
cmpb $0xb, (%r10)
jne 0x5ae3d
movq 0x8(%r10), %r14
testq %r14, %r14
jns 0x5adf7
movq 0xde0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xbabc3(%rip), %rdx     # 0x115968
movq 0x140(%rbx), %r8
movq 0xc6e25(%rip), %r9      # 0x121bd8
movq %rbx, %rdi
movq %r10, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x9bbb
movq 0xde0(%rbx), %rdx
pushq $0x13
popq %r8
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x5ae52
movq 0xde0(%rbx), %rdx
pushq $0x8
popq %r8
pushq $0x1
popq %r9
movq %rbx, %rdi
jmp 0x5ae52
xorl %r14d, %r14d
movq 0x8(%rax), %r12
cmpq %r12, %r14
jge 0x5ae99
movq 0x10(%rax), %r15
cmpb $0x8, %dl
jne 0x5ae62
movsbl 0x8(%rsi), %esi
addq %r15, %r14
movq %r14, %rdi
callq 0x81d0
testq %rax, %rax
je 0x5ae99
movq %rax, %r14
subq %r15, %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x5aeac
leaq 0xbab19(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %rax
jmp 0x5aea0
movq 0xde0(%rbx), %rdx
pushq $0xb
popq %r8
pushq $0x3
popq %r9
movq %rbx, %rdi
movq %r10, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xcd70
cmpq $0x0, 0x8(%rsi)
je 0x5ae99
movq 0x10(%rsi), %rsi
addq %r14, %r15
movq %r15, %rdi
callq 0x8310
movq %rax, %r15
addq %r14, %r15
cmpq %r12, %r15
jge 0x5ae99
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x5aee7
leaq 0xbaabd(%rip), %rax     # 0x115950
movq (%rax,%r15,8), %rax
jmp 0x5aea0
movq 0x120(%rbx), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5aecb
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x5aea0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5af06
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r15, 0x8(%rax)
jmp 0x5aea0