// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rdi, 0x8(%rsp)
testl %ecx, %ecx
je 0x4e50
movl %r9d, %ebp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r14
leaq 0x6a12(%rip), %rdi      # 0xb5f9
callq 0x2080
cmpl $0x3, %r15d
je 0x4d58
cmpl $0x2, %r15d
je 0x4ca4
cmpl $0x1, %r15d
jne 0x4e44
leaq 0x5b18(%rip), %rdi      # 0xa729
movq %r14, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x4c93
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
leaq 0x5b1d(%rip), %r13      # 0xa74f
xorl %r12d, %r12d
leaq 0x5b0e(%rip), %rdi      # 0xa74a
xorl %eax, %eax
callq 0x2100
movq %r12, %rax
imulq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
xorl %r15d, %r15d
movq %rbp, %rax
cmpl $0x1, %ebx
jne 0x4c69
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r15
cmpq %r15, %r14
jne 0x4c58
leaq 0x6a0c(%rip), %rdi      # 0xb692
callq 0x2080
incq %r12
cmpq %r14, %r12
jne 0x4c35
leaq 0x69f5(%rip), %rdi      # 0xb68f
callq 0x2080
jmp 0x4e44
leaq 0x7103(%rip), %rdi      # 0xbdae
xorl %eax, %eax
callq 0x2100
testq %r14, %r14
je 0x4e3a
leaq 0x5a95(%rip), %r15      # 0xa757
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x2100
incq %r12
cmpq %r12, %r14
jne 0x4cc5
movl $0xa, %edi
callq 0x2040
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
leaq 0x5a72(%rip), %r13      # 0xa765
xorl %ebp, %ebp
leaq 0x5a61(%rip), %rdi      # 0xa75d
movl %ebp, %esi
xorl %eax, %eax
callq 0x2100
movq %rbp, %rax
imulq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
xorl %r15d, %r15d
movq %r12, %rax
cmpl $0x1, %ebx
jne 0x4d2b
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r15
cmpq %r15, %r14
jne 0x4d1a
movl $0xa, %edi
callq 0x2040
incq %rbp
cmpq %r14, %rbp
jne 0x4cf5
jmp 0x4e44
movq 0x90(%rsp), %rdx
leaq 0x5a05(%rip), %rsi      # 0xa76c
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x22b0
leaq 0x59fd(%rip), %rdi      # 0xa77a
movq %r15, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x5a04(%rip), %rsi      # 0xa792
movq %r15, %rdi
callq 0x2240
movq %rax, %r13
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x4e5f
leaq 0x5a27(%rip), %rsi      # 0xa7d5
movq %r13, %rdi
movq 0x90(%rsp), %rdx
movq %r14, %rcx
movq %r12, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x2170
testq %r14, %r14
je 0x4e28
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
movq %rbp, %rax
imulq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
xorl %r15d, %r15d
movq %r12, %rax
cmpl $0x1, %ebx
jne 0x4dfe
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r15,8), %r8
movq %r13, %rdi
leaq 0x59ea(%rip), %rsi      # 0xa7f6
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2170
incq %r15
cmpq %r15, %r14
jne 0x4ded
incq %rbp
cmpq %r14, %rbp
jne 0x4dd8
cmpq $0x0, 0x18(%rsp)
je 0x4e44
movq %r13, %rdi
callq 0x20e0
jmp 0x4e44
movl $0xa, %edi
callq 0x2040
leaq 0x68e0(%rip), %rdi      # 0xb72b
callq 0x2080
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb18a(%rip), %r15      # 0xfff0
movq (%r15), %rdi
leaq 0x5925(%rip), %rsi      # 0xa795
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%r15), %r13
jmp 0x4da7