// File: /workspace/github_c_makefile_star2_O3/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 0x70533
cmpl $0x13, %edx
jne 0x705b8
movq 0x10(%rcx), %rdi
movq 0x8(%rdi), %rax
cmpb $0x13, (%rax)
jne 0x7059a
movq 0x10(%rdi), %rdi
cmpb $0x1, (%rdi)
jne 0x705d0
movq 0x8(%rdi), %r10
cmpb $0xb, (%r10)
jne 0x70621
movq 0x8(%r10), %r14
testq %r14, %r14
jns 0x705d3
movq 0xde0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd63f2(%rip), %rdx     # 0x146968
movq 0x140(%rbx), %r8
movq 0xe2654(%rip), %r9      # 0x152bd8
movq %rbx, %rdi
movq %r10, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xa4e4
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
movl $0x13, %r8d
movl $0x2, %r9d
jmp 0x7063a
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movl $0x8, %r8d
movl $0x1, %r9d
jmp 0x7063a
xorl %r14d, %r14d
movq 0x8(%rax), %r12
cmpq %r12, %r14
jge 0x70681
movq 0x10(%rax), %r15
cmpb $0x8, %dl
jne 0x7064a
movsbl 0x8(%rsi), %esi
addq %r15, %r14
movq %r14, %rdi
callq 0x81d0
testq %rax, %rax
je 0x70681
movq %rax, %r14
subq %r15, %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x70694
leaq 0xd6335(%rip), %rax     # 0x146950
movq (%rax,%r14,8), %rax
jmp 0x70688
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movq %r10, %rsi
movl $0xb, %r8d
movl $0x3, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xe42d
cmpq $0x0, 0x8(%rsi)
je 0x70681
movq 0x10(%rsi), %rsi
addq %r14, %r15
movq %r15, %rdi
callq 0x8310
movq %rax, %r15
addq %r14, %r15
cmpq %r12, %r15
jge 0x70681
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x706cf
leaq 0xd62d5(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %rax
jmp 0x70688
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 0x706b3
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x70688
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x706ee
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r15, 0x8(%rax)
jmp 0x70688