// File: /workspace/github_c_makefile_star2_O1/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 0x1228
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 0xe94(%rip), %r15       # 0x20e3
leaq 0xe7e(%rip), %r12       # 0x20d4
movq 0x2d83(%rip), %rbp      # 0x3fe0
leaq 0xdbc(%rip), %r14       # 0x2020
leaq 0xe63(%rip), %r13       # 0x20ce
movzbl (%rbx), %eax
cmpl $0x25, %eax
je 0x128c
testl %eax, %eax
je 0x1532
movsbl %al, %edi
movq (%rbp), %rsi
callq 0x1050
jmp 0x152a
movzbl 0x1(%rbx), %eax
incq %rbx
cmpl $0x62, %eax
jle 0x12cd
leal -0x63(%rax), %ecx
cmpl $0x15, %ecx
ja 0x1477
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x140f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x141d
cmpl $0x45, %eax
je 0x1300
cmpl $0x47, %eax
je 0x1325
cmpl $0x58, %eax
jne 0x1477
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1427
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1435
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x143f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x144d
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x145d
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x146b
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x147f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x148d
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x1498
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14a6
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x14af
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14bd
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x14c9
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14d7
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x14ea
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x14f8
movl 0x4(%rsp), %ecx
cmpq $0xa0, %rcx
ja 0x150a
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x1518
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
movq %r13, %rdi
jmp 0x1501
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
movq %r12, %rdi
jmp 0x1501
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
leaq 0xc88(%rip), %rdi       # 0x20e0
jmp 0x1523
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
movq %r15, %rdi
jmp 0x1523
movsbl %al, %edi
jmp 0x127e
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
leaq 0xc41(%rip), %rdi       # 0x20d7
jmp 0x1501
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %edi
callq 0x1030
jmp 0x152a
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
leaq 0xc13(%rip), %rdi       # 0x20da
jmp 0x14e1
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
leaq 0xc05(%rip), %rdi       # 0x20e6
xorl %eax, %eax
callq 0x1040
jmp 0x152a
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
leaq 0xbd0(%rip), %rdi       # 0x20d1
xorl %eax, %eax
callq 0x1040
jmp 0x152a
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsd (%rax), %xmm0
leaq 0xbba(%rip), %rdi       # 0x20dd
movb $0x1, %al
callq 0x1040
incq %rbx
jmp 0x126b
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq