// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_5/exercise_5_17/sort.c
// Function: fieldscmp
int fieldscmp(const char *s1, const char *s2)
{
  int i = 0;
  while (i < nr_of_fields)
  {
    size_t start_s1 = str_nth_blank_pos(s1, fields_options[i][INDEX] - 1);
    size_t end_s1 = str_nth_blank_pos(s1, fields_options[i][INDEX]);
    char *field_s1 = substr(s1, start_s1, end_s1);

    size_t start_s2 = str_nth_blank_pos(s2, fields_options[i][INDEX] - 1);
    size_t end_s2 = str_nth_blank_pos(s2, fields_options[i][INDEX]);
    char *field_s2 = substr(s2, start_s2, end_s2);

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

    int comp_result = comp(field_s1, field_s2);

    afree(field_s1);
    afree(field_s2);

    if (comp_result == 0)
    {
      ++i;
    }
    else
    {
      return comp_result;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x3558(%rip), %eax      # 0x50a8
jge 0x1cbd
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x354b(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1cd0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x3524(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
callq 0x1cd0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x1da0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x34ed(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1cd0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x34c6(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movslq (%rax), %rsi
callq 0x1cd0
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x1da0
movq %rax, -0x50(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3ad3(%rip), %rax      # 0x56f0
movq (%rax,%rcx,8), %rax
movq %rax, 0x3458(%rip)      # 0x5080
movslq -0x1c(%rbp), %rcx
leaq 0x347d(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, 0x3435(%rip)      # 0x5078
movslq -0x1c(%rbp), %rcx
leaq 0x3462(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, 0x3442(%rip)      # 0x50a0
movslq -0x1c(%rbp), %rcx
leaq 0x3447(%rip), %rax      # 0x50b0
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, 0x342b(%rip)      # 0x50a4
movq 0x3400(%rip), %rax      # 0x5080
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq *%rax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1f90
movq -0x50(%rbp), %rdi
callq 0x1f90
cmpl $0x0, -0x54(%rbp)
jne 0x1cb0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1cb8
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1cc4
jmp 0x1b47
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)