// File: /workspace/github_c_makefile_star2_O2/LPD-EPFL[P]mctop/src/mctop.c
// Function: print_mem_lat_table
void
print_mem_lat_table(ticks** mem_lat_table, size_t n, size_t n_sockets, test_format_t test_format, const char* hostname)
{
  if (test_format != NONE)
    {
      printf("## Mem. lat table ########################################################\n");
    }
  switch (test_format)
    {
    case C_STRUCT:
      printf("size_t mem_lat_table[%zu][%zu] = \n{\n", n, n_sockets);
      for (int x = 0; x < n; x++)
	{
	  printf("  { ");
	  for (int y = 0; y < n_sockets; y++)
	    {
	      printf("%-3zu, ", mem_lat_table[x][y]);
	    }
	  printf("},\n");
	}
      printf("};\n");
      break;
    case LAT_TABLE:
      printf("     ");
      for (int y = 0; y < n_sockets; y++)
	{
	  printf("%-3d ", y);
	}
      printf("\n");

      /* print lat table */
      for (int x = 0; x < n; x++)
	{
	  printf("[%02d] ", x);
	  for (int y = 0; y < n_sockets; y++)
	    {
	      printf("%-3zu, ", mem_lat_table[x][y]);
	    }
	  printf("\n");
	}
      break;
    case MCT_FILE:
      {
	char out_file[50];
	sprintf(out_file, "./desc/%s.mct", hostname);
	printf("## MCTOP output in: %s\n", out_file);

	int ofp_open = 1;
	FILE* ofp = fopen(out_file, "a");
	if (ofp == NULL) 
	  {
	    ofp_open = 0;
	    fprintf(stderr, "MCTOP Error: Cannot open output file %s! Using stderr instead.\n", out_file);
	    ofp = stderr;
	  }
	fprintf(ofp, "#Mem_latencies %zu\n", n_sockets);
	for (int x = 0; x < n; x++)
	  {
	    for (int y = 0; y < n_sockets; y++)
	      {
		fprintf(ofp, "%-4d %-4d %zu\n", x, y, mem_lat_table[x][y]);
	      }
	  }
	if (ofp_open)
	  {
	    fclose(ofp);
	  }
      }
    case NONE:
      break;
    }
  if (test_format != NONE)
    {
      printf("##########################################################################\n");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, (%rsp)
testl %ecx, %ecx
je 0x4b1b
movq %r8, %r12
movl %ecx, %ebp
movq %rdx, %rbx
movq %rdi, %r15
leaq 0x6cfd(%rip), %rdi      # 0xb644
callq 0x2080
cmpl $0x3, %ebp
je 0x4a56
cmpl $0x2, %ebp
je 0x49cd
cmpl $0x1, %ebp
jne 0x4b0f
leaq 0x6047(%rip), %rdi      # 0xa9b1
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2100
leaq 0x6d13(%rip), %r13      # 0xb692
leaq 0x5dc9(%rip), %rbp      # 0xa74f
xorl %r14d, %r14d
cmpq (%rsp), %r14
je 0x4b03
leaq 0x5db0(%rip), %rdi      # 0xa74a
xorl %eax, %eax
callq 0x2100
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x49c0
movq (%r15,%r14,8), %rax
movq (%rax,%r12,8), %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x2100
incq %r12
jmp 0x49a4
movq %r13, %rdi
callq 0x2080
incq %r14
jmp 0x4989
leaq 0x73da(%rip), %rdi      # 0xbdae
xorl %eax, %eax
callq 0x2100
leaq 0x5d75(%rip), %r14      # 0xa757
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x49fc
movq %r14, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x2100
incq %r12
jmp 0x49e5
pushq $0xa
popq %rdi
callq 0x2040
leaq 0x5d52(%rip), %r12      # 0xa75d
leaq 0x5d3d(%rip), %r13      # 0xa74f
xorl %ebp, %ebp
cmpq (%rsp), %rbp
je 0x4b0f
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2100
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x4a49
movq (%r15,%rbp,8), %rax
movq (%rax,%r14,8), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r14
jmp 0x4a2d
pushq $0xa
popq %rdi
callq 0x2040
incq %rbp
jmp 0x4a14
leaq 0x5d0f(%rip), %rsi      # 0xa76c
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x5d04(%rip), %rdi      # 0xa77a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x5d7e(%rip), %rsi      # 0xa805
movq %r14, %rdi
callq 0x2240
movq %rax, %r13
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x4b2a
leaq 0x5f2f(%rip), %rsi      # 0xa9d6
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2170
leaq 0x5d3b(%rip), %rbp      # 0xa7f6
xorl %r12d, %r12d
cmpq (%rsp), %r12
je 0x4af1
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x4aec
movq (%r15,%r12,8), %rax
movq (%rax,%r14,8), %r8
movq %r13, %rdi
movq %rbp, %rsi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2170
incq %r14
jmp 0x4ac7
incq %r12
jmp 0x4abe
cmpq $0x0, 0x8(%rsp)
je 0x4b0f
movq %r13, %rdi
callq 0x20e0
jmp 0x4b0f
leaq 0x6b85(%rip), %rdi      # 0xb68f
callq 0x2080
leaq 0x6c15(%rip), %rdi      # 0xb72b
callq 0x2080
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb4bf(%rip), %r14      # 0xfff0
movq (%r14), %rdi
leaq 0x5c5a(%rip), %rsi      # 0xa795
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%r14), %r13
jmp 0x4aa0