// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movzbl (%r14), %eax
cmpl $0x8, %eax
je 0x75d77
cmpl $0x13, %eax
jne 0x75dc2
movq 0x10(%rcx), %rax
movq 0x8(%rax), %r15
cmpb $0x13, (%r15)
jne 0x75da7
movq 0x10(%rax), %rax
cmpb $0x1, (%rax)
jne 0x75de9
movq 0x8(%rax), %rax
cmpb $0xb, (%rax)
jne 0x75dee
movq 0x8(%rax), %r12
testq %r12, %r12
js 0x75e10
movb $0x1, %cl
jmp 0x75e3d
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x13, %r8d
movl $0x2, %r9d
jmp 0x75ddb
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8, %r8d
movl $0x1, %r9d
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xf1ae
xorl %r12d, %r12d
jmp 0x75e41
movq 0xde0(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
movl $0xb, %r8d
movl $0x3, %r9d
callq 0xf1ae
xorl %ecx, %ecx
jmp 0x75e3d
movq 0xde0(%rbx), %rcx
movq 0x8(%rcx), %rsi
movq 0xd8b46(%rip), %rdx     # 0x14e968
movq 0x140(%rbx), %r8
movq 0xe4da8(%rip), %r9      # 0x15abd8
movq %rbx, %rdi
movq %rax, %rcx
callq 0xb31d
xorl %ecx, %ecx
testb %cl, %cl
je 0x75eaf
movq 0x8(%r15), %r13
cmpq %r13, %r12
jge 0x75ea8
movq 0x10(%r15), %r15
cmpb $0x8, (%r14)
jne 0x75e71
movsbl 0x8(%r14), %esi
addq %r15, %r12
movq %r12, %rdi
callq 0x91d0
testq %rax, %rax
je 0x75ea8
movq %rax, %r14
subq %r15, %r14
jmp 0x75e92
cmpq $0x0, 0x8(%r14)
je 0x75ea8
movq 0x10(%r14), %rsi
addq %r12, %r15
movq %r15, %rdi
callq 0x9310
movq %rax, %r14
addq %r12, %r14
cmpq %r13, %r14
jge 0x75ea8
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x75eb9
leaq 0xd8aae(%rip), %rax     # 0x14e950
movq (%rax,%r14,8), %rax
jmp 0x75eaf
movq 0x120(%rbx), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x75ed1
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x75eaf