// File: /workspace/github_c_makefile_star2_O3/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 0x8401(%rip), %rax      # 0x120dc
movl (%rax), %eax
testl %eax, %eax
je 0x9ce7
cvtsi2sd %eax, %xmm2
jmp 0x9d37
leaq 0x9452(%rip), %r14      # 0x13140
xorl %edi, %edi
movq %r14, %rsi
callq 0x3070
cvtsi2sdq (%r14), %xmm0
cvtsi2sdq 0x8(%r14), %xmm2
movsd 0x14dd(%rip), %xmm1     # 0xb1e8
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x9436(%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 0x9ff0
cmpl $0x1, %ebx
je 0x9e13
cmpl $0x2, %ebx
jne 0xa1eb
movl 0x8361(%rip), %eax      # 0x120b8
testb $0x1, %al
je 0x9d81
leaq 0x8396(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x3e5a(%rip), %rdi      # 0xdbc6
movl $0xe, %esi
movl $0x1, %edx
callq 0x32c0
movl 0x8337(%rip), %eax      # 0x120b8
testb $0x2, %al
je 0x9dab
leaq 0x836c(%rip), %rax      # 0x120f8
movq (%rax), %rcx
leaq 0x3e3f(%rip), %rdi      # 0xdbd5
movl $0x14, %esi
movl $0x1, %edx
callq 0x32c0
movl 0x830d(%rip), %eax      # 0x120b8
testb $0x8, %al
je 0xa1eb
cmpq $0x0, 0x945d(%rip)      # 0x13218
jne 0x9dc2
callq 0x97f4
cmpl $0x0, 0x9447(%rip)      # 0x13210
jle 0xa1eb
leaq 0x8322(%rip), %r14      # 0x120f8
leaq 0x3e0d(%rip), %rbx      # 0xdbea
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%r14), %rdi
movq 0x942b(%rip), %rax      # 0x13218
movq (%rax,%r15), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x940b(%rip), %rax      # 0x13210
addq $0x20, %r15
cmpq %rax, %r12
jl 0x9de3
jmp 0xa1eb
movl 0x829f(%rip), %eax      # 0x120b8
testb $0x1, %al
movsd %xmm2, (%rsp)
je 0x9e53
leaq 0x82cf(%rip), %rax      # 0x120f8
movq (%rax), %rdi
movsd 0x9354(%rip), %xmm0     # 0x13188
movl 0x9356(%rip), %edx      # 0x13190
leaq 0x3db1(%rip), %rsi      # 0xdbf2
movb $0x1, %al
callq 0x31c0
movsd (%rsp), %xmm2
movl 0x8265(%rip), %eax      # 0x120b8
testb $0x2, %al
je 0x9f85
leaq 0x8296(%rip), %r14      # 0x120f8
movq (%r14), %rdi
movq 0x9334(%rip), %rax      # 0x131a0
addq 0x9325(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x1ac0(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1ac8(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x826d(%rip), %r15      # 0x1210c
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
divsd %xmm1, %xmm0
leaq 0x3d4a(%rip), %rbx      # 0xdbfc
movq %rbx, %rsi
movb $0x1, %al
callq 0x31c0
movq (%r14), %rdi
movsd 0x92e1(%rip), %xmm1     # 0x131a8
unpcklps 0x1a72(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a7a(%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 0x92a8(%rip), %xmm1     # 0x131b0
unpcklps 0x1a31(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a39(%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 0x926f(%rip), %xmm1     # 0x131b8
unpcklps 0x19f0(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x19f8(%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
movl 0x8133(%rip), %eax      # 0x120b8
testb $0x8, %al
je 0xa1eb
cmpq $0x0, 0x9283(%rip)      # 0x13218
jne 0x9f9c
callq 0x97f4
cmpl $0x0, 0x926d(%rip)      # 0x13210
jle 0xa1eb
movl $0x8, %r14d
leaq 0x8142(%rip), %r15      # 0x120f8
leaq 0x3c48(%rip), %rbx      # 0xdc05
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x924e(%rip), %rax      # 0x13218
movq (%rax,%r14), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x922e(%rip), %rax      # 0x13210
addq $0x20, %r14
cmpq %rax, %r12
jl 0x9fc0
jmp 0xa1eb
movl 0x80c2(%rip), %eax      # 0x120b8
testb $0x1, %al
movsd %xmm2, (%rsp)
je 0xa041
leaq 0x80f2(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movsd 0x9177(%rip), %xmm0     # 0x13188
leaq 0x3bf2(%rip), %rsi      # 0xdc0a
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movl 0x9168(%rip), %edx      # 0x13190
leaq 0x3bf7(%rip), %rsi      # 0xdc26
xorl %eax, %eax
callq 0x31c0
movsd (%rsp), %xmm2
movl 0x8077(%rip), %eax      # 0x120b8
testb $0x2, %al
je 0xa188
leaq 0x80a8(%rip), %rbx      # 0x120f8
movq (%rbx), %rdi
movq 0x9146(%rip), %rax      # 0x131a0
addq 0x9137(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x18d2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18da(%rip), %xmm1     # 0xb950
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x807f(%rip), %r14      # 0x1210c
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
divsd %xmm1, %xmm0
leaq 0x3b9f(%rip), %rsi      # 0xdc3f
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x90f6(%rip), %xmm1     # 0x131a8
unpcklps 0x1887(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x188f(%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 0x3b78(%rip), %rsi      # 0xdc5d
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movsd 0x90b9(%rip), %xmm1     # 0x131b0
unpcklps 0x1842(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x184a(%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 0x3b51(%rip), %rsi      # 0xdc7b
movb $0x1, %al
callq 0x31c0
movq (%rbx), %rdi
movq 0x9065(%rip), %rax      # 0x131a0
addq 0x9056(%rip), %rax      # 0x13198
movq %rax, %xmm1
punpckldq 0x17f1(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17f9(%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 0x3b1e(%rip), %rsi      # 0xdc99
movb $0x1, %al
callq 0x31c0
movl 0x7f30(%rip), %eax      # 0x120b8
testb $0x8, %al
je 0xa1eb
cmpq $0x0, 0x9084(%rip)      # 0x13218
jne 0xa19b
callq 0x97f4
cmpl $0x0, 0x906e(%rip)      # 0x13210
jle 0xa1eb
movl $0x8, %r14d
leaq 0x7f47(%rip), %r15      # 0x120f8
leaq 0x3aff(%rip), %rbx      # 0xdcb7
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x9053(%rip), %rax      # 0x13218
movq -0x8(%rax,%r14), %rdx
movq (%rax,%r14), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31c0
incq %r12
movslq 0x902e(%rip), %rax      # 0x13210
addq $0x20, %r14
cmpq %rax, %r12
jl 0xa1bb
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq