// File: /workspace/github_c_makefile_star2_O2/mvermeulen[P]wspy/system.c
// Function: print_system
void print_system(enum output_format oformat){
  double elapsed;
  int i;
  if (interval) elapsed = interval;
  else {
    clock_gettime(CLOCK_REALTIME,&finish_time);
    elapsed = finish_time.tv_sec + finish_time.tv_nsec / 1000000000.0 -
      start_time.tv_sec - start_time.tv_nsec / 1000000000.0;    
  }

  switch(oformat){
  case PRINT_CSV_HEADER:
    if (system_mask & SYSTEM_LOADAVG) fprintf(outfile,"load,runnable,");
    if (system_mask & SYSTEM_CPU) fprintf(outfile,"cpu,idle,iowait,irq,");
#if AMDGPU
    if (system_mask & SYSTEM_GPU)
      fprintf(outfile,"gpu temp,gpu gfx,gpu umc,gpu_mm,");
#endif
    if (system_mask & SYSTEM_NETWORK){
      if (system_state.netinfo == NULL) setup_net_info();
      for (i=0;i<system_state.num_net;i++) fprintf(outfile,"net %s,",system_state.netinfo[i].name);
    }
    break;
  case PRINT_CSV:
    if (system_mask & SYSTEM_LOADAVG) fprintf(outfile,"%4.2f,%d,",system_state.load,system_state.runnable);
    if (system_mask & SYSTEM_CPU){
      fprintf(outfile,"%3.2f%%,",
	      (double) (system_state.cpu.usertime+system_state.cpu.systemtime)/elapsed/num_procs);
      fprintf(outfile,"%3.2f%%,",
	      (double) (system_state.cpu.idletime)/elapsed/num_procs);
      fprintf(outfile,"%3.2f%%,",
	      (double) (system_state.cpu.iowaittime)/elapsed/num_procs);      
      fprintf(outfile,"%3.2f%%,",
	      (double) (system_state.cpu.irqtime)/elapsed/num_procs);
    }
#if AMDGPU
    if (system_mask & SYSTEM_GPU){
      fprintf(outfile,"%d,",system_state.gpu.temperature);
      fprintf(outfile,"%d%%,",system_state.gpu.gfx_activity);
      fprintf(outfile,"%d%%,",system_state.gpu.umc_activity);
      fprintf(outfile,"%d%%,",system_state.gpu.mm_activity);
    }
#endif
    if (system_mask & SYSTEM_NETWORK){
      if (system_state.netinfo == NULL) setup_net_info();
      for (i=0;i<system_state.num_net;i++){
	fprintf(outfile,"%lu,",system_state.netinfo[i].bytes);
      }
    }    
    break;
  case PRINT_NORMAL:
    if (system_mask & SYSTEM_LOADAVG){
      fprintf(outfile,"load                 %4.2f\n",system_state.load);
      fprintf(outfile,"runnable             %d\n",system_state.runnable);      
    }
    if (system_mask & SYSTEM_CPU){
      fprintf(outfile,"cpu                  %3.2f%%\n",
	      (double) (system_state.cpu.usertime+system_state.cpu.systemtime)/elapsed/num_procs);
      fprintf(outfile,"idle                 %3.2f%%\n",
	      (double) (system_state.cpu.idletime/elapsed/num_procs));
      fprintf(outfile,"io                   %3.2f%%\n",
	      (double) (system_state.cpu.iowaittime/elapsed/num_procs));      
      fprintf(outfile,"irq                  %3.2f%%\n",
	      (double) (system_state.cpu.usertime+system_state.cpu.systemtime)/elapsed/num_procs);      
    }
#if AMDGPU
    if (system_mask & SYSTEM_GPU){
      fprintf(outfile,"temperature          %dC\n",system_state.gpu.temperature);
      fprintf(outfile,"gpu gfx              %d%%\n",system_state.gpu.gfx_activity);
      fprintf(outfile,"gpu umc              %d%%\n",system_state.gpu.umc_activity);
      fprintf(outfile,"gpu mm               %d%%\n",system_state.gpu.mm_activity);      
    }
#endif
    if (system_mask & SYSTEM_NETWORK){
      if (system_state.netinfo == NULL) setup_net_info();
      for (i=0;i<system_state.num_net;i++){
	fprintf(outfile,"%-14s       %lu\n",system_state.netinfo[i].name,system_state.netinfo[i].bytes);
      }
    }    
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x769d(%rip), %rax      # 0x110ec
movl (%rax), %eax
testl %eax, %eax
je 0x9a5b
cvtsi2sd %eax, %xmm2
jmp 0x9aa5
leaq 0x86ee(%rip), %r14      # 0x12150
xorl %edi, %edi
movq %r14, %rsi
callq 0x3070
cvtsi2sdq (%r14), %xmm0
cvtsi2sdq 0x8(%r14), %xmm2
movsd 0x769(%rip), %xmm1      # 0xa1e8
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x86d2(%rip), %rax      # 0x12160
cvtsi2sdq (%rax), %xmm0
subsd %xmm0, %xmm2
cvtsi2sdq 0x8(%rax), %xmm0
divsd %xmm1, %xmm0
subsd %xmm0, %xmm2
testl %ebx, %ebx
je 0x9d30
cmpl $0x1, %ebx
je 0x9b6d
cmpl $0x2, %ebx
jne 0x9ec0
movl 0x7603(%rip), %eax      # 0x110c8
testb $0x1, %al
je 0x9aeb
leaq 0x7638(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x30ec(%rip), %rdi      # 0xcbc6
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
movl 0x75dd(%rip), %eax      # 0x110c8
testb $0x2, %al
je 0x9b11
leaq 0x7612(%rip), %rax      # 0x11108
movq (%rax), %rcx
leaq 0x30d5(%rip), %rdi      # 0xcbd5
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
movl 0x75b7(%rip), %eax      # 0x110c8
testb $0x8, %al
je 0x9ec0
cmpq $0x0, 0x8707(%rip)      # 0x12228
jne 0x9b28
callq 0x95d0
leaq 0x75d9(%rip), %r14      # 0x11108
leaq 0x30b4(%rip), %rbx      # 0xcbea
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0x86dd(%rip), %rax      # 0x12220
cmpq %rax, %r12
jge 0x9ec0
movq (%r14), %rdi
movq 0x86d2(%rip), %rax      # 0x12228
movq (%rax,%r15), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
addq $0x20, %r15
jmp 0x9b3c
movl 0x7555(%rip), %eax      # 0x110c8
testb $0x1, %al
movsd %xmm2, (%rsp)
je 0x9bad
leaq 0x7585(%rip), %rax      # 0x11108
movq (%rax), %rdi
movsd 0x860a(%rip), %xmm0     # 0x12198
movl 0x860c(%rip), %edx      # 0x121a0
leaq 0x3057(%rip), %rsi      # 0xcbf2
movb $0x1, %al
callq 0x31c0
movsd (%rsp), %xmm2
movl 0x751b(%rip), %eax      # 0x110c8
testb $0x2, %al
je 0x9cd3
leaq 0x754c(%rip), %r14      # 0x11108
movq (%r14), %rdi
movq 0x85ea(%rip), %rax      # 0x121b0
addq 0x85db(%rip), %rax      # 0x121a8
movq %rax, %xmm1
punpckldq 0xd66(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xd6e(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x7523(%rip), %r15      # 0x1111c
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
leaq 0x2ff3(%rip), %rbx      # 0xcbfc
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x859a(%rip), %xmm1     # 0x121b8
unpcklps 0xd1b(%rip), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xd23(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x8564(%rip), %xmm1     # 0x121c0
unpcklps 0xcdd(%rip), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xce5(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x852e(%rip), %xmm1     # 0x121c8
unpcklps 0xc9f(%rip), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xca7(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movl 0x73f5(%rip), %eax      # 0x110c8
testb $0x8, %al
je 0x9ec0
cmpq $0x0, 0x8545(%rip)      # 0x12228
jne 0x9cea
callq 0x95d0
pushq $0x8
popq %r14
leaq 0x7413(%rip), %r15      # 0x11108
leaq 0x2f09(%rip), %rbx      # 0xcc05
xorl %r12d, %r12d
movslq 0x851a(%rip), %rax      # 0x12220
cmpq %rax, %r12
jge 0x9ec0
movq (%r15), %rdi
movq 0x850f(%rip), %rax      # 0x12228
movq (%rax,%r14), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
addq $0x20, %r14
jmp 0x9cff
movl 0x7392(%rip), %eax      # 0x110c8
testb $0x1, %al
movsd %xmm2, (%rsp)
je 0x9d81
leaq 0x73c2(%rip), %rbx      # 0x11108
movq (%rbx), %rdi
movsd 0x8447(%rip), %xmm0     # 0x12198
leaq 0x2eb2(%rip), %rsi      # 0xcc0a
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movl 0x8438(%rip), %edx      # 0x121a0
leaq 0x2eb7(%rip), %rsi      # 0xcc26
xorl %eax, %eax
callq 0x31c0
movsd (%rsp), %xmm2
movl 0x7347(%rip), %eax      # 0x110c8
testb $0x2, %al
je 0x9ebc
leaq 0x7378(%rip), %rbx      # 0x11108
movq (%rbx), %rdi
movq 0x8416(%rip), %rax      # 0x121b0
addq 0x8407(%rip), %rax      # 0x121a8
movq %rax, %xmm1
punpckldq 0xb92(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb9a(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x734f(%rip), %r14      # 0x1111c
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x2e62(%rip), %rsi      # 0xcc3f
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x83c9(%rip), %xmm1     # 0x121b8
unpcklps 0xb4a(%rip), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb52(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x2e3e(%rip), %rsi      # 0xcc5d
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x838f(%rip), %xmm1     # 0x121c0
unpcklps 0xb08(%rip), %xmm1      # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb10(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x2e1a(%rip), %rsi      # 0xcc7b
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x833e(%rip), %rax      # 0x121b0
addq 0x832f(%rip), %rax      # 0x121a8
movq %rax, %xmm1
punpckldq 0xaba(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xac2(%rip), %xmm1      # 0xa950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x2dea(%rip), %rsi      # 0xcc99
movb $0x1, %al
callq 0x31c0
movl 0x720c(%rip), %eax      # 0x110c8
testb $0x8, %al
jne 0x9ecc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpq $0x0, 0x8354(%rip)      # 0x12228
jne 0x9edb
callq 0x95d0
pushq $0x8
popq %r14
leaq 0x7222(%rip), %r15      # 0x11108
leaq 0x2dca(%rip), %rbx      # 0xccb7
xorl %r12d, %r12d
movslq 0x8329(%rip), %rax      # 0x12220
cmpq %rax, %r12
jge 0x9ec0
movq (%r15), %rdi
movq 0x8322(%rip), %rax      # 0x12228
movq -0x8(%rax,%r14), %rdx
movq (%rax,%r14), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
addq $0x20, %r14
jmp 0x9ef0