// File: /workspace/github_c_makefile_star2_O3/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 0x51f5
movq %r8, %r12
movl %ecx, %ebp
movq %rdx, %rbx
movq %rdi, %r15
leaq 0x664b(%rip), %rdi      # 0xb644
callq 0x2080
cmpl $0x3, %ebp
je 0x5136
cmpl $0x2, %ebp
je 0x5099
cmpl $0x1, %ebp
jne 0x51e9
leaq 0x5991(%rip), %rdi      # 0xa9b1
movq (%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x5088
leaq 0x6655(%rip), %r13      # 0xb692
leaq 0x570b(%rip), %rbp      # 0xa74f
xorl %r14d, %r14d
leaq 0x56fc(%rip), %rdi      # 0xa74a
xorl %eax, %eax
callq 0x2100
testq %rbx, %rbx
je 0x5077
xorl %r12d, %r12d
movq (%r15,%r14,8), %rax
movq (%rax,%r12,8), %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x2100
incq %r12
cmpq %r12, %rbx
jne 0x505d
movq %r13, %rdi
callq 0x2080
incq %r14
cmpq (%rsp), %r14
jne 0x5047
leaq 0x6600(%rip), %rdi      # 0xb68f
callq 0x2080
jmp 0x51e9
leaq 0x6d0e(%rip), %rdi      # 0xbdae
xorl %eax, %eax
callq 0x2100
testq %rbx, %rbx
je 0x50cb
leaq 0x56a4(%rip), %r14      # 0xa757
xorl %r12d, %r12d
movq %r14, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x2100
incq %r12
cmpq %r12, %rbx
jne 0x50b6
movl $0xa, %edi
callq 0x2040
cmpq $0x0, (%rsp)
je 0x51e9
leaq 0x5676(%rip), %r12      # 0xa75d
leaq 0x5661(%rip), %r13      # 0xa74f
xorl %ebp, %ebp
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2100
testq %rbx, %rbx
je 0x511e
xorl %r14d, %r14d
movq (%r15,%rbp,8), %rax
movq (%rax,%r14,8), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r14
cmpq %r14, %rbx
jne 0x5104
movl $0xa, %edi
callq 0x2040
incq %rbp
cmpq (%rsp), %rbp
jne 0x50f0
jmp 0x51e9
leaq 0x562f(%rip), %rsi      # 0xa76c
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x5624(%rip), %rdi      # 0xa77a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x569e(%rip), %rsi      # 0xa805
movq %r14, %rdi
callq 0x2240
movq %rax, %r13
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5204
leaq 0x584f(%rip), %rsi      # 0xa9d6
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2170
cmpq $0x0, (%rsp)
je 0x51d9
leaq 0x5654(%rip), %rbp      # 0xa7f6
xorl %r12d, %r12d
testq %rbx, %rbx
je 0x51d0
xorl %r14d, %r14d
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
cmpq %r14, %rbx
jne 0x51ad
incq %r12
cmpq (%rsp), %r12
jne 0x51a5
cmpq $0x0, 0x8(%rsp)
je 0x51e9
movq %r13, %rdi
callq 0x20e0
leaq 0x653b(%rip), %rdi      # 0xb72b
callq 0x2080
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xade5(%rip), %r14      # 0xfff0
movq (%r14), %rdi
leaq 0x5580(%rip), %rsi      # 0xa795
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%r14), %r13
jmp 0x5180