// File: /workspace/github_c_makefile_star2_O1/LPD-EPFL[P]mctop/src/mctop.c
// Function: print_lat_table
void 
print_lat_table(void* lt, size_t n, size_t n_sockets, test_format_t test_format,
		array_format_t format, uint is_smt, const char* hostname)
{
  ticks* lat_table_1d = (ticks*) lt;
  ticks** lat_table_2d = (ticks**) lt;
  if (test_format != NONE)
    {
      printf("## Lat table #############################################################\n");
    }
  switch (test_format)
    {
    case C_STRUCT:
      printf("size_t lat_table[%zu][%zu] = \n{\n", n, n);
      for (int x = 0; x < n; x++)
	{
	  printf("  { ");
	  for (int y = 0; y < n; y++)
	    {
	      ticks lat = (format == AR_2D) ? lat_table_2d[x][y] : lat_table_2d_get(lat_table_1d, n, x, y);
	      printf("%-3zu, ", lat);
	    }
	  printf("},\n");
	}
      printf("};\n");
      break;
    case LAT_TABLE:
      printf("     ");
      for (int y = 0; y < n; 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; y++)
	    {
	      ticks lat = (format == AR_2D) ? lat_table_2d[x][y] : lat_table_2d_get(lat_table_1d, n, x, y);
	      printf("%-3zu ", lat);
	    }
	  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, "w+");
	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, "#%s #HWCs %zu #Nodes %zu SMT %u\n", hostname, n, n_sockets, is_smt);
	for (int x = 0; x < n; x++)
	  {
	    for (int y = 0; y < n; y++)
	      {
		ticks lat = (format == AR_2D) ? lat_table_2d[x][y] : lat_table_2d_get(lat_table_1d, n, x, y);
		fprintf(ofp, "%-4d %-4d %zu\n", x, y, lat);
	      }
	  }
	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 $0x68, %rsp
movl %r9d, %r14d
movl %r8d, %ebp
movl %ecx, %ebx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
testl %ecx, %ecx
je 0x4b91
leaq 0x7a6d(%rip), %rdi      # 0xc5f9
callq 0x2080
cmpl $0x3, %ebx
movq %r15, 0x18(%rsp)
movl %ebx, 0x24(%rsp)
je 0x4d3f
cmpl $0x2, %ebx
je 0x4c6c
cmpl $0x1, %ebx
jne 0x4e3a
leaq 0x6b6d(%rip), %rdi      # 0xb729
movq %r15, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
testq %r15, %r15
je 0x4c5b
movslq %r15d, %rax
shlq $0x3, %rax
movq %rax, 0x10(%rsp)
leaq 0x6b6a(%rip), %r13      # 0xb74f
movq 0x8(%rsp), %r12
xorl %ebx, %ebx
leaq 0x6b57(%rip), %rdi      # 0xb74a
xorl %eax, %eax
callq 0x2100
movq %r15, %r14
movq %r12, (%rsp)
movq %r12, %r15
xorl %r12d, %r12d
movq %r15, %rax
cmpl $0x1, %ebp
jne 0x4c20
leaq (,%r12,8), %rax
movq 0x8(%rsp), %rcx
addq (%rcx,%rbx,8), %rax
movq (%rax), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r12
addq $0x8, %r15
decq %r14
jne 0x4c07
leaq 0x7a52(%rip), %rdi      # 0xc692
callq 0x2080
incq %rbx
movq (%rsp), %r12
addq 0x10(%rsp), %r12
movq 0x18(%rsp), %r15
cmpq %r15, %rbx
jne 0x4bec
leaq 0x7a2d(%rip), %rdi      # 0xc68f
callq 0x2080
jmp 0x4e3a
leaq 0x813b(%rip), %rdi      # 0xcdae
xorl %eax, %eax
callq 0x2100
testq %r15, %r15
je 0x4c9e
leaq 0x6ad1(%rip), %rbx      # 0xb757
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x2100
incq %r14
cmpq %r14, %r15
jne 0x4c89
movl $0xa, %edi
callq 0x2040
testq %r15, %r15
je 0x4e3a
movslq %r15d, %rax
shlq $0x3, %rax
movq %rax, 0x10(%rsp)
leaq 0x6aa1(%rip), %r13      # 0xb765
movq 0x8(%rsp), %r12
xorl %ebx, %ebx
leaq 0x6a8b(%rip), %rdi      # 0xb75d
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
movq %r15, %r14
movq %r12, (%rsp)
movq %r12, %r15
xorl %r12d, %r12d
movq %r15, %rax
cmpl $0x1, %ebp
jne 0x4d01
leaq (,%r12,8), %rax
movq 0x8(%rsp), %rcx
addq (%rcx,%rbx,8), %rax
movq (%rax), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r12
addq $0x8, %r15
decq %r14
jne 0x4ce8
movl $0xa, %edi
callq 0x2040
incq %rbx
movq (%rsp), %r12
addq 0x10(%rsp), %r12
movq 0x18(%rsp), %r15
cmpq %r15, %rbx
jne 0x4ccb
jmp 0x4e3a
movl %r14d, (%rsp)
movq 0xa0(%rsp), %rbx
leaq 0x6a1a(%rip), %rsi      # 0xb76c
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0x6a0f(%rip), %rdi      # 0xb77a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x6a16(%rip), %rsi      # 0xb792
movq %r14, %rdi
callq 0x2240
movq %rax, %r13
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x4e5c
leaq 0x6a39(%rip), %rsi      # 0xb7d5
movq %r13, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movq %r12, %r8
movl (%rsp), %r9d
xorl %eax, %eax
callq 0x2170
testq %r15, %r15
je 0x4e2a
movslq %r15d, %rax
shlq $0x3, %rax
movq %rax, 0x10(%rsp)
leaq 0x6a2b(%rip), %rbx      # 0xb7f6
movq 0x8(%rsp), %r15
xorl %r12d, %r12d
movq %r15, (%rsp)
xorl %r14d, %r14d
movq %r15, %rax
cmpl $0x1, %ebp
jne 0x4df3
leaq (,%r14,8), %rax
movq 0x8(%rsp), %rcx
addq (%rcx,%r12,8), %rax
movq (%rax), %r8
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2170
incq %r14
addq $0x8, %r15
cmpq %r14, 0x18(%rsp)
jne 0x4dda
incq %r12
movq (%rsp), %r15
addq 0x10(%rsp), %r15
cmpq 0x18(%rsp), %r12
jne 0x4dd3
cmpq $0x0, 0x28(%rsp)
je 0x4e3a
movq %r13, %rdi
callq 0x20e0
cmpl $0x0, 0x24(%rsp)
je 0x4e4d
leaq 0x78e3(%rip), %rdi      # 0xc72b
callq 0x2080
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc18d(%rip), %r14      # 0x10ff0
movq (%r14), %rdi
leaq 0x6928(%rip), %rsi      # 0xb795
leaq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%r14), %r13
jmp 0x4d95