// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_7/exercise_7_06/compare.c
// Function: main
int main(int argc, char *argv[])
{
  if (!parse_arg_list(argc, argv))
  {
    fprintf(stderr, "Error: invalid arguments.\n");
    exit(EXIT_FAILURE);
  }

  char *program_name = argv[0];

  FILE *file_1;
  FILE *file_2;

  if ((file_1 = fopen(argv[1], "r")) == NULL)
  {
    fprintf(stderr, "%s: can't open %s.\n", program_name, argv[1]);
    exit(EXIT_FAILURE);
  }

  if ((file_2 = fopen(argv[2], "r")) == NULL)
  {
    fprintf(stderr, "%s: can't open %s.\n", program_name, argv[2]);
    exit(EXIT_FAILURE);
  }

  char line_1[MAX_LINE_LEN];
  char line_2[MAX_LINE_LEN];

  size_t line_number = 1;
  while (fgets(line_1, MAX_LINE_LEN, file_1) != NULL && fgets(line_2, MAX_LINE_LEN, file_2) != NULL)
  {
    if (strcmp(line_1, line_2) != 0)
    {
      printf("%s [%zu]: %s", argv[1], line_number, line_1);
      fclose(file_1);

      printf("%s [%zu]: %s", argv[2], line_number, line_2);
      fclose(file_2);
      break;
    }

    ++line_number;
  }

  exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x810, %rsp            # imm = 0x810
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1390
cmpl $0x0, %eax
jne 0x11ec
movq 0x2e27(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xe29(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1090
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe19(%rip), %rsi       # 0x201f
callq 0x1080
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x1243
movq 0x2ddc(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0xdef(%rip), %rsi       # 0x2021
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1090
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xdcd(%rip), %rsi       # 0x201f
callq 0x1080
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x128f
movq 0x2d90(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0xda3(%rip), %rsi       # 0x2021
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1090
movq $0x1, -0x808(%rbp)
leaq -0x410(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x1050
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x809(%rbp)
je 0x12e2
leaq -0x800(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x1050
cmpq $0x0, %rax
setne %al
movb %al, -0x809(%rbp)
movb -0x809(%rbp), %al
testb $0x1, %al
jne 0x12f1
jmp 0x137c
leaq -0x410(%rbp), %rdi
leaq -0x800(%rbp), %rsi
callq 0x1060
cmpl $0x0, %eax
je 0x1365
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x808(%rbp), %rdx
leaq -0x410(%rbp), %rcx
leaq 0xd0f(%rip), %rdi       # 0x2035
movb $0x0, %al
callq 0x1040
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x808(%rbp), %rdx
leaq -0x800(%rbp), %rcx
leaq 0xce2(%rip), %rdi       # 0x2035
movb $0x0, %al
callq 0x1040
movq -0x28(%rbp), %rdi
callq 0x1030
jmp 0x137c
movq -0x808(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x808(%rbp)
jmp 0x129a
xorl %edi, %edi
callq 0x1090
nopw %cs:(%rax,%rax)