// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rsp), %rax
movq %rcx, (%rax)
leaq 0x1564f(%rip), %r12     # 0x23c78
cmpb $0x0, (%rbp)
je 0xe800
movb (%rbp), %al
movb %al, 0xf(%rsp)
cmpb $0x25, %al
jne 0xe737
leaq 0x1(%rbp), %r13
xorl %r8d, %r8d
xorl %eax, %eax
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
movzbl %cl, %ecx
leal -0x31(%rcx), %edx
cmpl $0x9, %edx
jae 0xe676
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0xe661
jmp 0xe656
cmpl $0x2f, %ecx
jg 0xe6b1
cmpl $0x2a, %ecx
jle 0xe6d9
cmpl $0x2e, %ecx
jne 0xe718
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0xe656
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0xe69c
jmp 0xe656
cmpl $0x46, %ecx
jle 0xe6f4
leal -0x55(%rcx), %edx
cmpl $0x25, %edx
ja 0xe75b
movslq (%r12,%rdx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl %eax, %ecx
andl $0x1, %ecx
incl %ecx
orl %ecx, %eax
jmp 0xe64b
cmpl $0x22, %ecx
jg 0xe6fe
testl %ecx, %ecx
je 0xe7c2
cmpl $0x20, %ecx
je 0xe64b
jmp 0xe7c6
cmpl $0x30, %ecx
jne 0xe74f
jmp 0xe64b
cmpl $0x23, %ecx
je 0xe64b
cmpl $0x2a, %ecx
jne 0xe7c6
incl %r8d
jmp 0xe64b
cmpl $0x2b, %ecx
je 0xe64b
cmpl $0x2d, %ecx
je 0xe64b
jmp 0xe7c6
orl $0x2, %eax
jmp 0xe64b
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq *%r15
incq %rbp
xorl %eax, %eax
movq %rbp, %r13
jmp 0xe7b5
cmpl $0x44, %ecx
je 0xe765
cmpl $0x45, %ecx
je 0xe77d
jmp 0xe7c6
cmpl $0x47, %ecx
je 0xe77d
cmpl $0x4f, %ecx
jne 0xe7c6
testb $0x2, %al
jne 0xe791
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x1, %r9d
jmp 0xe7a3
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x5, %r9d
jmp 0xe7a3
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x2, %r9d
pushq %rbx
leaq 0x18(%rsp), %rax
pushq %rax
callq 0xe844
addq $0x10, %rsp
xorl %eax, %eax
movq %r13, %rbp
testb %al, %al
je 0xe629
jmp 0xe800
movb $0x1, %al
jmp 0xe7b5
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq *%r15
jmp 0xe7b3
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x4, %r9d
jmp 0xe7a3
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x3, %r9d
jmp 0xe7a3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq