// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
testl %ecx, %ecx
je 0x5015
leaq 0x7634(%rip), %rdi      # 0xc644
callq 0x2080
cmpl $0x3, %ebp
movl %ebp, 0x14(%rsp)
je 0x5155
cmpl $0x2, %ebp
je 0x50b6
cmpl $0x1, %ebp
jne 0x520a
leaq 0x6976(%rip), %rdi      # 0xb9b1
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2100
testq %rbx, %rbx
je 0x50a5
leaq 0x7639(%rip), %rbp      # 0xc692
leaq 0x66ef(%rip), %rbx      # 0xb74f
xorl %r15d, %r15d
leaq 0x66e0(%rip), %rdi      # 0xb74a
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x5093
xorl %r13d, %r13d
movq (%r12,%r15,8), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
incq %r13
cmpq %r13, %r14
jne 0x5079
movq %rbp, %rdi
callq 0x2080
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x5063
leaq 0x75e3(%rip), %rdi      # 0xc68f
callq 0x2080
jmp 0x520a
leaq 0x7cf1(%rip), %rdi      # 0xcdae
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x50e8
leaq 0x6687(%rip), %rbx      # 0xb757
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x2100
incq %r15
cmpq %r15, %r14
jne 0x50d3
movl $0xa, %edi
callq 0x2040
cmpq $0x0, 0x8(%rsp)
je 0x520a
leaq 0x6658(%rip), %r13      # 0xb75d
leaq 0x6643(%rip), %rbp      # 0xb74f
xorl %ebx, %ebx
movq %r13, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x513c
xorl %r15d, %r15d
movq (%r12,%rbx,8), %rax
movq (%rax,%r15,8), %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x2100
incq %r15
cmpq %r15, %r14
jne 0x5122
movl $0xa, %edi
callq 0x2040
incq %rbx
cmpq 0x8(%rsp), %rbx
jne 0x510e
jmp 0x520a
leaq 0x6610(%rip), %rsi      # 0xb76c
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x6605(%rip), %rdi      # 0xb77a
movq %r15, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x667f(%rip), %rsi      # 0xb805
movq %r15, %rdi
callq 0x2240
movq %rax, %rbp
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x522c
leaq 0x6830(%rip), %rsi      # 0xb9d6
movq %rbp, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2170
cmpq $0x0, 0x8(%rsp)
je 0x51fa
leaq 0x6634(%rip), %rbx      # 0xb7f6
xorl %r13d, %r13d
testq %r14, %r14
je 0x51f0
xorl %r15d, %r15d
movq (%r12,%r13,8), %rax
movq (%rax,%r15,8), %r8
movq %rbp, %rdi
movq %rbx, %rsi
movl %r13d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2170
incq %r15
cmpq %r15, %r14
jne 0x51cd
incq %r13
cmpq 0x8(%rsp), %r13
jne 0x51c5
cmpq $0x0, 0x18(%rsp)
je 0x520a
movq %rbp, %rdi
callq 0x20e0
cmpl $0x0, 0x14(%rsp)
je 0x521d
leaq 0x7513(%rip), %rdi      # 0xc72b
callq 0x2080
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbdbd(%rip), %rbx      # 0x10ff0
movq (%rbx), %rdi
leaq 0x6558(%rip), %rsi      # 0xb795
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%rbx), %rbp
jmp 0x519f