// File: /workspace/github_c_makefile_star2_O2/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_7/exercise_7_03/minprintf.c
// Function: minprintf
void minprintf(const char *format, ...)
{
  va_list arg_p;

  va_start(arg_p, format);
  for (; *format != '\0'; ++format)
  {
    if (*format != '%')
    {
      putc(*format, stdout);
      continue;
    }

    switch (*++format)
    {
    case 'd':
    case 'i':
      printf("%d", va_arg(arg_p, int));
      break;

    case 'o':
      printf("%o", va_arg(arg_p, int));
      break;

    case 'x':
    case 'X':
      printf("%x", va_arg(arg_p, int));
      break;

    case 'u':
      printf("%u", va_arg(arg_p, int));
      break;

    case 'c':
      printf("%c", va_arg(arg_p, int));
      break;

    case 's':
      printf("%s", va_arg(arg_p, char *));
      break;

    case 'f':
      printf("%f", va_arg(arg_p, double));
      break;

    case 'e':
    case 'E':
      printf("%e", va_arg(arg_p, double));
      break;

    case 'g':
    case 'G':
      printf("%g", va_arg(arg_p, double));
      break;

    case 'p':
      printf("%p", va_arg(arg_p, void *));
      break;

    default:
      putc(*format, stdout);
      break;
    }
  }
  va_end(arg_p);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %r8, 0x20(%rdi)
movq %r9, 0x28(%rdi)
testb %al, %al
je 0x121d
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rsp)
leaq 0xe9f(%rip), %r15       # 0x20e3
leaq 0xe89(%rip), %r12       # 0x20d4
movq 0x2d8e(%rip), %rbp      # 0x3fe0
leaq 0xdc7(%rip), %r14       # 0x2020
leaq 0xe6e(%rip), %r13       # 0x20ce
movzbl (%rbx), %eax
cmpl $0x25, %eax
je 0x1281
testl %eax, %eax
je 0x1517
movsbl %al, %edi
movq (%rbp), %rsi
callq 0x1050
jmp 0x14f8
movzbl 0x1(%rbx), %eax
incq %rbx
leal -0x63(%rax), %ecx
cmpl $0x15, %ecx
ja 0x12b9
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x13ff
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x140d
cmpl $0x45, %eax
je 0x12e8
cmpl $0x47, %eax
je 0x130d
cmpl $0x58, %eax
jne 0x1332
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1435
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1443
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x1417
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x1425
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x144d
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x145b
movsbl %al, %edi
jmp 0x1273
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1464
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1472
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x147e
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x148c
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x149f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x14ad
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x14c1
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14cf
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x14da
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14e8
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1500
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x150e
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
movq %r13, %rdi
jmp 0x14f1
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
leaq 0xcb0(%rip), %rdi       # 0x20e0
jmp 0x14b8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
movq %r12, %rdi
jmp 0x14f1
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
movq %r15, %rdi
jmp 0x14b8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
leaq 0xc5e(%rip), %rdi       # 0x20da
jmp 0x1496
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
leaq 0xc50(%rip), %rdi       # 0x20e6
xorl %eax, %eax
callq 0x1040
jmp 0x14f8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
leaq 0xc25(%rip), %rdi       # 0x20dd
movb $0x1, %al
callq 0x1040
jmp 0x14f8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
leaq 0xbff(%rip), %rdi       # 0x20d7
jmp 0x14f1
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
leaq 0xbe0(%rip), %rdi       # 0x20d1
xorl %eax, %eax
callq 0x1040
incq %rbx
jmp 0x1260
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %edi
callq 0x1030
jmp 0x14f8
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq