// File: /workspace/github_c_makefile_star2_O2/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 0x4528
movl %r9d, %ebp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r14
leaq 0x7325(%rip), %rdi      # 0xb5f9
callq 0x2080
cmpl $0x3, %r15d
je 0x442f
cmpl $0x2, %r15d
je 0x4383
cmpl $0x1, %r15d
jne 0x451c
leaq 0x642b(%rip), %rdi      # 0xa729
movq %r14, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2100
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
leaq 0x6435(%rip), %rbp      # 0xa74f
xorl %r12d, %r12d
cmpq %r14, %r12
je 0x4510
leaq 0x641d(%rip), %rdi      # 0xa74a
xorl %eax, %eax
callq 0x2100
movq %r12, %rax
imulq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x4372
movq %r13, %rax
cmpl $0x1, %ebx
jne 0x435f
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r15,8), %rsi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x2100
incq %r15
jmp 0x4349
leaq 0x7319(%rip), %rdi      # 0xb692
callq 0x2080
incq %r12
jmp 0x431d
leaq 0x7a24(%rip), %rdi      # 0xbdae
xorl %eax, %eax
callq 0x2100
leaq 0x63bf(%rip), %r15      # 0xa757
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x43b2
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x2100
incq %r12
jmp 0x439b
pushq $0xa
popq %rdi
callq 0x2040
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
leaq 0x639c(%rip), %r13      # 0xa765
xorl %ebp, %ebp
cmpq %r14, %rbp
je 0x451c
leaq 0x6382(%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
cmpq %r15, %r14
je 0x4422
movq %r12, %rax
cmpl $0x1, %ebx
jne 0x440f
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2100
incq %r15
jmp 0x43f9
pushq $0xa
popq %rdi
callq 0x2040
incq %rbp
jmp 0x43cb
movq 0x90(%rsp), %rdx
leaq 0x632e(%rip), %rsi      # 0xa76c
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x22b0
leaq 0x6326(%rip), %rdi      # 0xa77a
movq %r15, %rsi
xorl %eax, %eax
callq 0x2100
leaq 0x632d(%rip), %rsi      # 0xa792
movq %r15, %rdi
callq 0x2240
movq %rax, %r13
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x4537
leaq 0x6350(%rip), %rsi      # 0xa7d5
movq %r13, %rdi
movq 0x90(%rsp), %rdx
movq %r14, %rcx
movq %r12, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x2170
movslq %r14d, %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
cmpq %r14, %rbp
je 0x44fe
movq %rbp, %rax
imulq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x44f9
movq %r12, %rax
cmpl $0x1, %ebx
jne 0x44da
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r15,8), %r8
movq %r13, %rdi
leaq 0x630e(%rip), %rsi      # 0xa7f6
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2170
incq %r15
jmp 0x44c4
incq %rbp
jmp 0x44aa
cmpq $0x0, 0x18(%rsp)
je 0x451c
movq %r13, %rdi
callq 0x20e0
jmp 0x451c
leaq 0x7178(%rip), %rdi      # 0xb68f
callq 0x2080
leaq 0x7208(%rip), %rdi      # 0xb72b
callq 0x2080
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbab2(%rip), %r15      # 0xfff0
movq (%r15), %rdi
leaq 0x624d(%rip), %rsi      # 0xa795
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2170
movq (%r15), %r13
jmp 0x447e