// File: /workspace/github_c_makefile_star2_O2/cogbee[P]vmir-latest/src/vmir_libc.c
// Function: dofmt
static void
dofmt(void (*output)(void *opaque, const char *str, int len),
      void *opaque, const char *fmt, const void *valist,
      ir_unit_t *iu)
{
  while(*fmt) {
    char c = *fmt;
    if(c != '%') {
      output(opaque, fmt, 1); // xxx: lame, should do long runs of unfmted str
      fmt++;
      continue;
    }
    int num_field_args = 0;
    const char *start = fmt;
    int flags = 0;
    fmt++;
  again:
    c = *fmt++;
  reswitch:
    switch(c) {
    case ' ':
    case '#':
    case '+':
    case '-':
    case '0':
      goto again;
    case '*':
      num_field_args++;
      goto again;

    case '.':
      if((c = *fmt++) == '*') {
        goto reswitch;
      }

      while(c >= '0' && c <= '9')
        c = *fmt++;
      goto reswitch;

    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      do {
        c = *fmt++;
      } while(c >= '0' && c <= '9');
      goto reswitch;
    case 'z':
      flags = 0;
      goto again;
    case 'l':
      if(flags & FMT_FLAGS_LONG)
        flags |= FMT_FLAGS_INT64;
      else
        flags |= FMT_FLAGS_LONG;
      goto again;

    case 'q':
      flags |= FMT_FLAGS_INT64;
      goto again;

    case 'c':
      dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_INT,
             &valist, iu);
      break;

    case 'O':
    case 'o':
    case 'D':
    case 'd':
    case 'i':
    case 'U':
    case 'u':
    case 'X':
    case 'x':
      if(flags & FMT_FLAGS_INT64) {
        dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_INT64,
               &valist, iu);
      } else {
        dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_INT,
               &valist, iu);
      }
      break;

    case 'e':
    case 'E':
    case 'f':
    case 'g':
    case 'G':
      dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_DOUBLE,
             &valist, iu);
      break;

    case 'p':
      dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_PTR,
             &valist, iu);
      break;

    case 's':
      dofmt2(output, opaque, start, fmt, num_field_args, FMT_TYPE_STR,
             &valist, iu);
      break;

    case 0:
      return;

    default:
      output(opaque, &c, 1);
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rsp), %rax
movq %rcx, (%rax)
leaq 0x114d8(%rip), %rbp     # 0x1ec88
movb (%r12), %al
testb %al, %al
je 0xd906
movb %al, 0xf(%rsp)
cmpb $0x25, %al
jne 0xd86c
leaq 0x1(%r12), %r13
xorl %r8d, %r8d
xorl %eax, %eax
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
movzbl %cl, %ecx
leal -0x20(%rcx), %edx
cmpl $0x2f, %edx
ja 0xd832
movslq (%rbp,%rdx,4), %rcx
addq %rbp, %rcx
jmpq *%rcx
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0xd7f2
jmp 0xd7dd
movb (%r13), %dl
incq %r13
movb %dl, 0xf(%rsp)
movb $0x2a, %cl
cmpb $0x2a, %dl
je 0xd7dd
leal -0x30(%rdx), %ecx
cmpb $0x9, %cl
ja 0xd82e
movb (%r13), %dl
incq %r13
movb %dl, 0xf(%rsp)
jmp 0xd819
movl %edx, %ecx
jmp 0xd7dd
leal -0x55(%rcx), %edx
cmpl $0x25, %edx
ja 0xd8cc
leaq 0x11503(%rip), %rsi     # 0x1ed48
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl %eax, %ecx
andl $0x1, %ecx
incl %ecx
orl %ecx, %eax
jmp 0xd7d2
orl $0x2, %eax
jmp 0xd7d2
incl %r8d
jmp 0xd7d2
movq %r14, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
callq *%r15
incq %r12
jmp 0xd7b0
testb $0x2, %al
jne 0xd8a4
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
pushq $0x1
jmp 0xd8b2
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
pushq $0x5
jmp 0xd8b2
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
pushq $0x2
popq %r9
pushq %rbx
leaq 0x18(%rsp), %rax
pushq %rax
callq 0xd94a
addq $0x10, %rsp
movq %r13, %r12
jmp 0xd7b0
testl %ecx, %ecx
je 0xd906
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
pushq $0x1
popq %rdx
callq *%r15
movq %r13, %r12
jmp 0xd7b0
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
pushq $0x3
jmp 0xd8b2
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
pushq $0x4
jmp 0xd8b2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq