// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: g_format
static s7_pointer g_format(s7_scheme *sc, s7_pointer args)
    {
#define H_format "(format out str . args) substitutes args into str sending the result to out. Most of \
        s7's format directives are taken from CL: ~% = newline, ~& = newline if the preceding output character was \
        no a newline, ~~ = ~, ~<newline> trims white space, ~* skips an argument, ~^ exits {} iteration if the arg list is exhausted, \
        ~nT spaces over to column n, ~A prints a representation of any object, ~S is the same, but puts strings in double quotes, \
        ~C prints a character, numbers are handled by ~F, ~E, ~G, ~B, ~O, ~D, and ~X with preceding numbers giving \
        spacing (and spacing character) and precision.  ~{ starts an embedded format directive which is ended by ~}: \n\
        \n\
        >(format #f \"dashed: ~{~A~^-~}\" '(1 2 3))\n\
        \"dashed: 1-2-3\"\n\
        \n\
        ~P inserts \"s\" if the current it is not 1 or 1.0 (use ~@P for \"ies\" or \"y\").\n\
        ~B is number->string in base 2, ~O in base 8, ~D base 10, ~X base 16,\n\
        ~E: (format #f \"~E\" 100.1) -&gt; \"1.001000e+02\" (%e in C)\n\
        ~F: (format #f \"~F\" 100.1) -&gt; \"100.100000\"   (%f in C)\n\
        ~G: (format #f \"~G\" 100.1) -&gt; \"100.1\"        (%g in C)\n\
        \n\
        If the 'out' it is not an output port, the resultant string is returned.  If it \
        is #t, the string is also sent to the current-output-port."

#define Q_format s7_make_circular_signature(sc, 2, 3, s7_make_signature(sc, 2, sc->is_string_symbol, sc->not_symbol), s7_make_signature(sc, 3, sc->is_output_port_symbol, sc->is_boolean_symbol, sc->is_null_symbol), sc->T)

        s7_pointer pt, str;
        sc->format_column = 0;
        pt = car(args);
        if (is_null(pt))
        {
            pt = sc->output_port;                  /* () -> (current-output-port) */
            if (pt == sc->F)                       /*   otherwise () -> #f so we get a returned string, which is confusing */
                return(pt);                          /*   but this means some error checks are skipped? */
        }

        if (!((s7_is_boolean(pt)) ||               /* #f or #t */
                    ((is_output_port(pt)) &&             /* (current-output-port) or call-with-open-file arg, etc */
                     (!port_is_closed(pt)))))
            return(method_or_bust_with_type(sc, pt, sc->format_symbol, args, an_output_port_string, 1));

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

        return(format_to_port_1(sc, (pt == sc->T) ? sc->output_port : pt,
                    string_value(str), cddr(args), NULL, !is_output_port(pt), true, string_length(str), str));
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl $0x0, 0x238(%rax)
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x2d5b3
movq 0x48(%rsp), %rax
movq 0x188(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
cmpq 0x120(%rcx), %rax
jne 0x2d5b1
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x2d70d
jmp 0x2d5b3
movq 0x38(%rsp), %rdi
callq 0x9c50
testb $0x1, %al
jne 0x2d614
movq 0x38(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x22, %eax
jne 0x2d5dd
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
testb $0x1, 0x2(%rax)
je 0x2d614
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rax
movq 0xf20(%rax), %rdx
movq 0x40(%rsp), %rcx
movq 0x1f4809(%rip), %r8     # 0x221e08
movl $0x1, %r9d
callq 0x14130
movq %rax, 0x50(%rsp)
jmp 0x2d70d
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x13, %eax
je 0x2d669
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rax
movq 0xf20(%rax), %rdx
movq 0x40(%rsp), %rcx
movl $0x13, %r8d
movl $0x2, %r9d
callq 0x13c50
movq %rax, 0x50(%rsp)
jmp 0x2d70d
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
cmpq 0x118(%rcx), %rax
jne 0x2d699
movq 0x48(%rsp), %rax
movq 0x188(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x2d6a3
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rcx
movq 0x38(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x22, %eax
sete %al
xorb $-0x1, %al
movq 0x30(%rsp), %r8
movq 0x8(%r8), %r9
movq 0x30(%rsp), %r10
xorl %r8d, %r8d
movq %rsp, %r8
movq %r10, 0x10(%r8)
movq %r9, 0x8(%r8)
movl $0x1, (%r8)
movzbl %al, %r9d
andl $0x1, %r9d
xorl %eax, %eax
movl %eax, %r8d
callq 0xd2940
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw (%rax,%rax)