// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_5/exercise_5_17/sort.c
// Function: parse_arg_list
int parse_arg_list(int argc, char *argv[])
{
  for (int i = 1; i < argc; ++i)
  {
    size_t arg_len = strlen(argv[i]);
    if (arg_len > 1 && argv[i][0] == '-')
    {
      for (size_t j = 1; j < arg_len; ++j)
      {
        if (isdigit(argv[i][j]) && !fields_options[i - 1][INDEX])
        {
          char field_index_str[INT_MAX_NR_OF_DIGITS];

          size_t k = 0;
          while (isdigit(argv[i][j]) && j < arg_len && k < INT_MAX_NR_OF_DIGITS)
          {
            field_index_str[k++] = argv[i][j++];
          }
          field_index_str[k] = '\0';

          fields_options[i - 1][INDEX] = atoi(field_index_str);

          --j;
          ++nr_of_fields;
        }
        else
        {
          switch (argv[i][j])
          {
          case 'n':
            comp = numcmp;
            break;

          case 'f':
            fold = 1;
            break;

          case 'd':
            directory = 1;
            break;

          case 'r':
            order = -1;
            break;

          default:
            return 0;
            break;
          }
        }
      }

      if (nr_of_fields || argc > 2)
      {
        if (!fields_options[i - 1][INDEX])
        {
          return 0;
        }

        fields_comp[i - 1] = comp;
        fields_options[i - 1][ORDER] = order;
        fields_options[i - 1][FOLD] = fold;
        fields_options[i - 1][DIRECTORY] = directory;

        comp = estrcmp;
        order = 1;
        fold = 0;
        directory = 0;
      }
    }
    else
    {
      return 0;
    }
  }

  if (nr_of_fields && nr_of_fields == argc - 1)
  {
    comp = fieldscmp;
  }
  else if (argc > 2)
  {
    return 0;
  }

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1835
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1060
movq %rax, -0x20(%rbp)
cmpq $0x1, -0x20(%rbp)
jbe 0x181c
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x181c
movq $0x1, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x1738
callq 0x10c0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x16ad
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x3baf(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x16ad
movsd 0x1aef(%rip), %xmm0     # 0x3008
callq 0x1070
callq 0x1090
movsd 0x1ae5(%rip), %xmm1     # 0x3010
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1ad2(%rip), %xmm1     # 0x3018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
callq 0x10c0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x161b
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x49(%rbp)
jae 0x161b
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movsd 0x1a36(%rip), %xmm0     # 0x3008
callq 0x1070
callq 0x1090
movq -0x58(%rbp), %rax
movsd 0x1a28(%rip), %xmm1     # 0x3010
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x1a15(%rip), %xmm1     # 0x3018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x1624
jmp 0x165d
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x28(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x28(%rbp)
movb (%rcx,%rdx), %dl
movq -0x40(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x40(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x1580
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
movb $0x0, (%rdi,%rax)
callq 0x10a0
movl %eax, %ecx
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
leaq 0x3a30(%rip), %rax      # 0x50b0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movl 0x3a0d(%rip), %eax      # 0x50a8
addl $0x1, %eax
movl %eax, 0x3a04(%rip)      # 0x50a8
movq -0x30(%rbp), %rax
movq %rax, %rsp
jmp 0x1725
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0xe, %eax
ja 0x1717
movq -0x60(%rbp), %rax
leaq 0x1946(%rip), %rcx      # 0x3020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x3c6(%rip), %rax       # 0x1ab0
movq %rax, 0x398f(%rip)      # 0x5080
jmp 0x1723
movl $0x1, 0x39a3(%rip)      # 0x50a0
jmp 0x1723
movl $0x1, 0x399b(%rip)      # 0x50a4
jmp 0x1723
movl $0xffffffff, 0x3963(%rip) # imm = 0xFFFFFFFF
jmp 0x1723
movl $0x0, -0x4(%rbp)
jmp 0x1876
jmp 0x1725
jmp 0x1727
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x14b2
cmpl $0x0, 0x3969(%rip)      # 0x50a8
jne 0x174b
cmpl $0x2, -0x8(%rbp)
jle 0x181a
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x3955(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x1773
movl $0x0, -0x4(%rbp)
jmp 0x1876
movq 0x3906(%rip), %rdx      # 0x5080
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x3f66(%rip), %rax      # 0x56f0
movq %rdx, (%rax,%rcx,8)
movl 0x38e4(%rip), %ecx      # 0x5078
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
leaq 0x390c(%rip), %rax      # 0x50b0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl 0x38ec(%rip), %ecx      # 0x50a0
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
leaq 0x38ec(%rip), %rax      # 0x50b0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl 0x38d0(%rip), %ecx      # 0x50a4
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
leaq 0x38cc(%rip), %rax      # 0x50b0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
leaq -0x625(%rip), %rax      # 0x11d0
movq %rax, 0x3884(%rip)      # 0x5080
movl $0x1, 0x3872(%rip)      # 0x5078
movl $0x0, 0x3890(%rip)      # 0x50a0
movl $0x0, 0x388a(%rip)      # 0x50a4
jmp 0x1825
movl $0x0, -0x4(%rbp)
jmp 0x1876
jmp 0x1827
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1466
cmpl $0x0, 0x386c(%rip)      # 0x50a8
je 0x185e
movl 0x3864(%rip), %eax      # 0x50a8
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x185e
leaq 0x2db(%rip), %rax       # 0x1b30
movq %rax, 0x3824(%rip)      # 0x5080
jmp 0x186f
cmpl $0x2, -0x8(%rbp)
jle 0x186d
movl $0x0, -0x4(%rbp)
jmp 0x1876
jmp 0x186f
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nop