// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x5b42
leaq 0xac14(%rip), %rdi      # 0x1074f
movb $0x0, %al
callq 0x20d0
movl -0x1c(%rbp), %eax
movq %rax, -0x90(%rbp)
subq $0x3, %rax
ja 0x5e01
movq -0x90(%rbp), %rax
leaq 0x96f8(%rip), %rcx      # 0xf25c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xac1f(%rip), %rdi      # 0x1079b
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5bf9
leaq 0xa861(%rip), %rdi      # 0x103fc
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x30(%rbp)
movslq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5be0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xa833(%rip), %rdi      # 0x10401
movb $0x0, %al
callq 0x20d0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x5ba9
leaq 0xa822(%rip), %rdi      # 0x10409
movb $0x0, %al
callq 0x20d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5b8a
leaq 0xa80d(%rip), %rdi      # 0x1040d
movb $0x0, %al
callq 0x20d0
jmp 0x5e01
leaq 0xb39c(%rip), %rdi      # 0x10faf
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5c47
movl -0x34(%rbp), %esi
leaq 0xa7dc(%rip), %rdi      # 0x10411
movb $0x0, %al
callq 0x20d0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5c21
leaq 0x981d(%rip), %rdi      # 0xf46b
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5cce
movl -0x38(%rbp), %esi
leaq 0xa7a7(%rip), %rdi      # 0x10417
movb $0x0, %al
callq 0x20d0
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5cb5
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xa75e(%rip), %rdi      # 0x10401
movb $0x0, %al
callq 0x20d0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5c7e
leaq 0x97af(%rip), %rdi      # 0xf46b
movb $0x0, %al
callq 0x20d0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5c5c
jmp 0x5e01
leaq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0xa744(%rip), %rsi      # 0x10426
movb $0x0, %al
callq 0x2280
leaq -0x70(%rbp), %rsi
leaq 0xa740(%rip), %rdi      # 0x10434
movb $0x0, %al
callq 0x20d0
movl $0x1, -0x74(%rbp)
leaq -0x70(%rbp), %rdi
leaq 0xa84a(%rip), %rsi      # 0x10557
callq 0x2210
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x5d4e
movl $0x0, -0x74(%rbp)
movq 0xf2cd(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq -0x70(%rbp), %rdx
leaq 0xa716(%rip), %rsi      # 0x1044f
movb $0x0, %al
callq 0x2140
movq 0xf2b1(%rip), %rax      # 0x14ff8
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xaa63(%rip), %rsi      # 0x107c0
movb $0x0, %al
callq 0x2140
movl $0x0, -0x84(%rbp)
movslq -0x84(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5dee
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5ddb
movq -0x80(%rbp), %rdi
movl -0x84(%rbp), %edx
movl -0x88(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movslq -0x88(%rbp), %rsi
movq (%rax,%rsi,8), %r8
leaq 0xa6ed(%rip), %rsi      # 0x104b0
movb $0x0, %al
callq 0x2140
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x5d85
jmp 0x5ddd
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x5d6e
cmpl $0x0, -0x74(%rbp)
je 0x5dfd
movq -0x80(%rbp), %rdi
callq 0x20b0
jmp 0x5dff
jmp 0x5e01
cmpl $0x0, -0x1c(%rbp)
je 0x5e15
leaq 0xa6b1(%rip), %rdi      # 0x104bf
movb $0x0, %al
callq 0x20d0
addq $0x90, %rsp
popq %rbp
retq
nop