// File: /workspace/github_c_makefile_star2_O1/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 0x83d4(%rip), %rax      # 0x120dc
movl (%rax), %eax
testl %eax, %eax
je 0x9d14
cvtsi2sd %eax, %xmm2
jmp 0x9d64
leaq 0x9425(%rip), %r14      # 0x13140
xorl %edi, %edi
movq %r14, %rsi
callq 0x3070
cvtsi2sdq (%r14), %xmm0
cvtsi2sdq 0x8(%r14), %xmm2
movsd 0x14b0(%rip), %xmm1     # 0xb1e8
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x9409(%rip), %rax      # 0x13150
xorps %xmm0, %xmm0
cvtsi2sdq (%rax), %xmm0
subsd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%rax), %xmm0
divsd %xmm1, %xmm0
subsd %xmm0, %xmm2
testl %ebx, %ebx
je 0xa017
cmpl $0x1, %ebx
je 0x9e3d
cmpl $0x2, %ebx
jne 0xa20f
testb $0x1, 0x8333(%rip)      # 0x120b8
je 0x9da7
leaq 0x836a(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x3e2e(%rip), %rdi      # 0xdbc6
movl $0xe, %esi
movl $0x1, %edx
callq 0x32c0
testb $0x2, 0x830a(%rip)      # 0x120b8
je 0x9dd0
leaq 0x8341(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x3e14(%rip), %rdi      # 0xdbd5
movl $0x14, %esi
movl $0x1, %edx
callq 0x32c0
testb $0x8, 0x82e1(%rip)      # 0x120b8
je 0xa20f
cmpq $0x0, 0x9433(%rip)      # 0x13218
jne 0x9dec
callq 0x9818
cmpl $0x0, 0x941d(%rip)      # 0x13210
jle 0xa20f
leaq 0x82f8(%rip), %r14      # 0x120f8
leaq 0x3de3(%rip), %rbx      # 0xdbea
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%r14), %rdi
movq 0x9401(%rip), %rax      # 0x13218
movq (%rax,%r15), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x93e1(%rip), %rax      # 0x13210
addq $0x20, %r15
cmpq %rax, %r12
jl 0x9e0d
jmp 0xa20f
testb $0x1, 0x8274(%rip)      # 0x120b8
movsd %xmm2, (%rsp)
je 0x9e76
leaq 0x82a6(%rip), %rax      # 0x120f8
movq (%rax), %rdi
movsd 0x932b(%rip), %xmm0     # 0x13188
movl 0x932d(%rip), %edx      # 0x13190
leaq 0x3d88(%rip), %rsi      # 0xdbf2
movb $0x1, %al
callq 0x31c0
movsd (%rsp), %xmm2
testb $0x2, 0x823b(%rip)      # 0x120b8
je 0x9fa7
leaq 0x826e(%rip), %r14      # 0x120f8
movq (%r14), %rdi
movq 0x930c(%rip), %rax      # 0x131a0
addq 0x92fd(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x1a98(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1aa0(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x8245(%rip), %r15      # 0x1210c
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
leaq 0x3d22(%rip), %rbx      # 0xdbfc
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x92b9(%rip), %xmm1     # 0x131a8
unpcklps 0x1a4a(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a52(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x9280(%rip), %xmm1     # 0x131b0
unpcklps 0x1a09(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a11(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x9247(%rip), %xmm1     # 0x131b8
unpcklps 0x19c8(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x19d0(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
testb $0x8, 0x810a(%rip)      # 0x120b8
je 0xa20f
cmpq $0x0, 0x925c(%rip)      # 0x13218
jne 0x9fc3
callq 0x9818
cmpl $0x0, 0x9246(%rip)      # 0x13210
jle 0xa20f
movl $0x8, %r14d
leaq 0x811b(%rip), %r15      # 0x120f8
leaq 0x3c21(%rip), %rbx      # 0xdc05
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x9227(%rip), %rax      # 0x13218
movq (%rax,%r14), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x9207(%rip), %rax      # 0x13210
addq $0x20, %r14
cmpq %rax, %r12
jl 0x9fe7
jmp 0xa20f
testb $0x1, 0x809a(%rip)      # 0x120b8
movsd %xmm2, (%rsp)
je 0xa061
leaq 0x80cc(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movsd 0x9151(%rip), %xmm0     # 0x13188
leaq 0x3bcc(%rip), %rsi      # 0xdc0a
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movl 0x9142(%rip), %edx      # 0x13190
leaq 0x3bd1(%rip), %rsi      # 0xdc26
xorl %eax, %eax
callq 0x31c0
movsd (%rsp), %xmm2
testb $0x2, 0x8050(%rip)      # 0x120b8
je 0xa1a7
leaq 0x8083(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movq 0x9121(%rip), %rax      # 0x131a0
addq 0x9112(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x18ad(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18b5(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x805a(%rip), %r14      # 0x1210c
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x3b7a(%rip), %rsi      # 0xdc3f
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x90d1(%rip), %xmm1     # 0x131a8
unpcklps 0x1862(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x186a(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x3b53(%rip), %rsi      # 0xdc5d
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x9094(%rip), %xmm1     # 0x131b0
unpcklps 0x181d(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1825(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x3b2c(%rip), %rsi      # 0xdc7b
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x9040(%rip), %rax      # 0x131a0
addq 0x9031(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x17cc(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17d4(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x3af9(%rip), %rsi      # 0xdc99
movb $0x1, %al
callq 0x31c0
testb $0x8, 0x7f0a(%rip)      # 0x120b8
je 0xa20f
cmpq $0x0, 0x9060(%rip)      # 0x13218
jne 0xa1bf
callq 0x9818
cmpl $0x0, 0x904a(%rip)      # 0x13210
jle 0xa20f
movl $0x8, %r14d
leaq 0x7f23(%rip), %r15      # 0x120f8
leaq 0x3adb(%rip), %rbx      # 0xdcb7
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x902f(%rip), %rax      # 0x13218
movq -0x8(%rax,%r14), %rdx
movq (%rax,%r14), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x900a(%rip), %rax      # 0x13210
addq $0x20, %r14
cmpq %rax, %r12
jl 0xa1df
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq