// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x520a
leaq 0xb18c(%rip), %rdi      # 0x1038f
movb $0x0, %al
callq 0x20d0
movl -0x1c(%rbp), %eax
movq %rax, -0xc8(%rbp)
subq $0x3, %rax
ja 0x55d2
movq -0xc8(%rbp), %rax
leaq 0xa020(%rip), %rcx      # 0xf24c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq 0xb197(%rip), %rdi      # 0x103db
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5302
leaq 0xb195(%rip), %rdi      # 0x103fc
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x40(%rbp)
movslq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x52e6
cmpl $0x1, -0x20(%rbp)
jne 0x52a2
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd0(%rbp)
jmp 0x52be
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0x2fb0
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
leaq 0xb12d(%rip), %rdi      # 0x10401
movb $0x0, %al
callq 0x20d0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5275
leaq 0xb11c(%rip), %rdi      # 0x10409
movb $0x0, %al
callq 0x20d0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5252
leaq 0xb104(%rip), %rdi      # 0x1040d
movb $0x0, %al
callq 0x20d0
jmp 0x55d2
leaq 0xbc93(%rip), %rdi      # 0x10faf
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5350
movl -0x4c(%rbp), %esi
leaq 0xb0d3(%rip), %rdi      # 0x10411
movb $0x0, %al
callq 0x20d0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x532a
leaq 0xa114(%rip), %rdi      # 0xf46b
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x50(%rbp)
movslq -0x50(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5418
movl -0x50(%rbp), %esi
leaq 0xb09a(%rip), %rdi      # 0x10417
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x53fc
cmpl $0x1, -0x20(%rbp)
jne 0x53b8
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd8(%rbp)
jmp 0x53d4
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
movl -0x50(%rbp), %edx
movl -0x54(%rbp), %ecx
callq 0x2fb0
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
leaq 0xb035(%rip), %rdi      # 0x1041f
movb $0x0, %al
callq 0x20d0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x538b
leaq 0xa068(%rip), %rdi      # 0xf46b
movb $0x0, %al
callq 0x20d0
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x5365
jmp 0x55d2
leaq -0xa0(%rbp), %rdi
movq 0x10(%rbp), %rdx
leaq 0xaff7(%rip), %rsi      # 0x10426
movb $0x0, %al
callq 0x2280
leaq -0xa0(%rbp), %rsi
leaq 0xaff0(%rip), %rdi      # 0x10434
movb $0x0, %al
callq 0x20d0
movl $0x1, -0xa4(%rbp)
leaq -0xa0(%rbp), %rdi
leaq 0xafe9(%rip), %rsi      # 0x1044c
callq 0x2210
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x54b3
movl $0x0, -0xa4(%rbp)
movq 0xfb6e(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq -0xa0(%rbp), %rdx
leaq 0xafb4(%rip), %rsi      # 0x1044f
movb $0x0, %al
callq 0x2140
movq 0xfb4f(%rip), %rax      # 0x14ff8
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq 0x10(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movl -0x24(%rbp), %r9d
leaq 0xafbe(%rip), %rsi      # 0x1048f
movb $0x0, %al
callq 0x2140
movl $0x0, -0xb4(%rbp)
movslq -0xb4(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x55b9
movl $0x0, -0xb8(%rbp)
movslq -0xb8(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x55a3
cmpl $0x1, -0x20(%rbp)
jne 0x5537
movq -0x38(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
jmp 0x5559
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
movl -0xb4(%rbp), %edx
movl -0xb8(%rbp), %ecx
callq 0x2fb0
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdi
movl -0xb4(%rbp), %edx
movl -0xb8(%rbp), %ecx
movq -0xc0(%rbp), %r8
leaq 0xaf28(%rip), %rsi      # 0x104b0
movb $0x0, %al
callq 0x2140
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x54fd
jmp 0x55a5
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x54e2
cmpl $0x0, -0xa4(%rbp)
je 0x55ce
movq -0xb0(%rbp), %rdi
callq 0x20b0
jmp 0x55d0
jmp 0x55d2
cmpl $0x0, -0x1c(%rbp)
je 0x55e6
leaq 0xaee0(%rip), %rdi      # 0x104bf
movb $0x0, %al
callq 0x20d0
addq $0xe0, %rsp
popq %rbp
retq
nop