// File: /workspace/github_c_makefile_star2_O3/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 %rcx, 0x10(%rsp)
movb (%rdx), %al
testb %al, %al
je 0xe7e0
movq %r8, %rbx
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1568c(%rip), %r12     # 0x23c9c
movb %al, 0xf(%rsp)
cmpb $0x25, %al
jne 0xe71b
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 0xe650
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0xe63b
jmp 0xe630
cmpl $0x2f, %ecx
jg 0xe695
cmpl $0x2a, %ecx
jle 0xe6bd
cmpl $0x2e, %ecx
jne 0xe6fc
movb (%r13), %dl
incq %r13
movb %dl, 0xf(%rsp)
movb $0x2a, %cl
cmpb $0x2a, %dl
je 0xe630
leal -0x30(%rdx), %esi
movl %edx, %ecx
cmpb $0x9, %sil
ja 0xe630
movb (%r13), %cl
incq %r13
movb %cl, 0xf(%rsp)
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
jb 0xe680
jmp 0xe630
cmpl $0x46, %ecx
jle 0xe6d8
leal -0x55(%rcx), %edx
cmpl $0x25, %edx
ja 0xe73d
movslq (%r12,%rdx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl %eax, %ecx
andl $0x1, %ecx
incl %ecx
orl %ecx, %eax
jmp 0xe625
cmpl $0x22, %ecx
jg 0xe6e2
testl %ecx, %ecx
je 0xe7e0
cmpl $0x20, %ecx
je 0xe625
jmp 0xe7a6
cmpl $0x30, %ecx
jne 0xe731
jmp 0xe625
cmpl $0x23, %ecx
je 0xe625
cmpl $0x2a, %ecx
jne 0xe7a6
incl %r8d
jmp 0xe625
cmpl $0x2b, %ecx
je 0xe625
cmpl $0x2d, %ecx
je 0xe625
jmp 0xe7a6
orl $0x2, %eax
jmp 0xe625
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq *%r15
incq %rbp
movq %rbp, %r13
jmp 0xe795
cmpl $0x44, %ecx
je 0xe747
cmpl $0x45, %ecx
je 0xe75f
jmp 0xe7a6
cmpl $0x47, %ecx
je 0xe75f
cmpl $0x4f, %ecx
jne 0xe7a6
testb $0x2, %al
jne 0xe773
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x1, %r9d
jmp 0xe785
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x5, %r9d
jmp 0xe785
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x2, %r9d
pushq %rbx
leaq 0x18(%rsp), %rax
pushq %rax
callq 0xe824
addq $0x10, %rsp
movb (%r13), %al
movq %r13, %rbp
testb %al, %al
jne 0xe610
jmp 0xe7e0
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq *%r15
jmp 0xe795
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x4, %r9d
jmp 0xe785
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl $0x3, %r9d
jmp 0xe785
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq