// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/proctree.c
// Function: main
int main(int argc,char *const argv[],char *const envp[]){
  int opt;
  int value;
  char *p,*p2,*cmd;
  char *orig_buffer;
  char buffer[8192];
  double elapsed;
  int event_pid;

  clocks_per_second = sysconf(_SC_CLK_TCK);

  initialize_error_subsystem(argv[0],"-");

  // parse options
  while ((opt = getopt(argc,argv,"+CcFfMmSsTtUuvw:")) != -1){
    switch(opt){
    case 'C':
      print_cmdline = 1;
      break;
    case 'c':
      print_cmdline = 0;
      break;
    case 'F':
      fflag = 1;
      break;
    case 'f':
      fflag = 0;
      break;
    case 'M':
      mflag = 1;
      break;
    case 'm':
      mflag = 0;
      break;
    case 't':
      treeflag = 0;
      break;
    case 'T':
      treeflag = 1;
      break;
    case 's':
      statflag = 0;
      break;
    case 'S':
      statflag = 1;
      break;
    case 'U':
      uflag = 1;
      break;
    case 'u':
      uflag = 0;
      break;
    case 'v':
      vflag++;
      if (vflag>1) set_error_level(ERROR_LEVEL_DEBUG2);
      else set_error_level(ERROR_LEVEL_DEBUG);
      break;
    case 'w':
      if (sscanf(optarg,"%d",&value) == 1){
	output_width = value;
      } else {
	warning("bad output width:%s ignored\n",optarg);
      }
      break;
    default:
    usage:
      fatal("usage: %s -[CcFfSsTtuv][-w width] file\n"
	    "\t-C\tturn on longer command line\n"
	    "\t-c\tturn on abbreviated command (default)\n"
	    "\t-F\turn on start/finish info (default)\n"
	    "\t-f\tturn off start/finish info\n"
	    "\t-M\tturn on vmsize printing\n"
	    "\t-m\tturn off vmsize printing\n"
	    "\t-S\tturn on summary output\n"
	    "\t-s\tturn off summary output (default)\n"
	    "\t-T\tturn on tree output (default)\n"
	    "\t-t\tturn off tree output\n"
	    "\t-U\tturn off utime in tree\n"
	    "\t-u\tturn on utime in tree\n"
	    "\t-v\tverbose messages\n"
	    "\t-w width\tset command width\n",
	    argv[0]);
      break;
    }
  }

  if (optind >= argc){
    fatal("missing data file\n");
  } else if (argc > optind + 1){
    warning("extra arguments after filename %s ignored\n",argv[optind]);
  }
  if ((process_file = fopen(argv[optind],"r")) == NULL){
    fatal("can not open file %s\n",argv[optind]);
  }

  // parse the input file
  while (fgets(buffer,sizeof(buffer),process_file) != NULL){
    if (p = strchr(buffer,' ')) *p = 0;
    else continue;
    elapsed = strtod(buffer,&p2);
    if (p2 == buffer) // no value parsed, there can be newlines in input so ignore
      continue;
    
    p++;
    
    if (p2 = strchr(p,' ')) *p2 = 0;
    else continue;
    event_pid = atoi(p); // no value parsed, there can be newlines in input so ignore
    if (event_pid <= 0) continue;
    p = p2+1;
    if (p2 = strchr(p,'\n')) *p2 = 0; // zap newline
    
    if (!strncmp(p,"fork",4)){
      handle_fork(elapsed,event_pid,p+5);
    } else if (!strncmp(p,"root",4)){
      handle_root(elapsed,event_pid);
    } else if (!strncmp(p,"comm",4)){
      handle_comm(elapsed,event_pid,p+5);
    } else if (!strncmp(p,"cmdline",7)){
      handle_cmdline(elapsed,event_pid,p+8);
    } else if (!strncmp(p,"exited",6)){
      // ignore exited events.
    } else if (!strncmp(p,"unknown",7)){
      // ignore unknown events
    } else if (!strncmp(p,"signal",6)){
      // ignore signal events
    } else if (!strncmp(p,"exit",4)){
      handle_exit(elapsed,event_pid,p+5);
    } else {
      warning("unknown command: %4.2f %d %s\n",elapsed,event_pid,p);
    }
  }

  if (statflag) print_statistics();
  if (treeflag) print_tree(root_process,0);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
movq %rsi, %rbx
movl %edi, %ebp
movl $0x2, %edi
callq 0x1140
movl %eax, 0x3c83(%rip)      # 0x5470
movq (%rbx), %rdi
leaq 0x18fb(%rip), %rsi      # 0x30f2
callq 0x1fd4
leaq 0x18f1(%rip), %r14      # 0x30f4
leaq 0x17fa(%rip), %r12      # 0x3004
leaq 0x1817(%rip), %r13      # 0x3028
movq 0x37c0(%rip), %r15      # 0x4fd8
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1150
cmpl $0x62, %eax
jg 0x1850
cmpl $0x4c, %eax
jle 0x186e
addl $-0x4d, %eax
cmpl $0x8, %eax
ja 0x1997
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x38ca(%rip)      # 0x5118
jmp 0x1818
leal -0x6d(%rax), %ecx
cmpl $0xa, %ecx
ja 0x1888
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, 0x38ac(%rip)      # 0x5118
jmp 0x1818
cmpl $0x43, %eax
je 0x18d6
cmpl $0x46, %eax
jne 0x1992
movl $0x1, 0x386a(%rip)      # 0x50f0
jmp 0x1818
cmpl $0x63, %eax
je 0x195e
cmpl $0x66, %eax
jne 0x1997
movl $0x0, 0x384c(%rip)      # 0x50f0
jmp 0x1818
movl $0x1, 0x3835(%rip)      # 0x50e8
jmp 0x1818
movl $0x1, 0x382a(%rip)      # 0x50ec
jmp 0x1818
movl $0x1, 0x384b(%rip)      # 0x511c
jmp 0x1818
movl $0x1, 0x3844(%rip)      # 0x5124
jmp 0x1818
movq (%r15), %rdi
leaq 0x1b1b(%rip), %rsi      # 0x340a
leaq 0x1c(%rsp), %rdx
xorl %eax, %eax
callq 0x1110
cmpl $0x1, %eax
jne 0x196d
movl 0x1c(%rsp), %eax
movl %eax, 0x37ea(%rip)      # 0x50f4
jmp 0x1818
movl 0x380b(%rip), %eax      # 0x5120
leal 0x1(%rax), %ecx
movl %ecx, 0x3802(%rip)      # 0x5120
testl %eax, %eax
jle 0x1983
movl $0x5, %edi
callq 0x26da
jmp 0x1818
movl $0x0, 0x37e1(%rip)      # 0x511c
jmp 0x1818
movl $0x0, 0x37a2(%rip)      # 0x50ec
jmp 0x1818
movl $0x0, 0x378f(%rip)      # 0x50e8
jmp 0x1818
movl $0x0, 0x37bc(%rip)      # 0x5124
jmp 0x1818
movq (%r15), %rsi
leaq 0x178e(%rip), %rdi      # 0x3105
xorl %eax, %eax
callq 0x222d
jmp 0x1818
movl $0x4, %edi
callq 0x26da
jmp 0x1818
cmpl $-0x1, %eax
je 0x19ad
movq (%rbx), %rsi
leaq 0x1781(%rip), %rdi      # 0x3122
xorl %eax, %eax
callq 0x2031
jmp 0x1818
movq 0x361c(%rip), %r14      # 0x4fd0
movslq (%r14), %rax
cmpl %ebp, %eax
jge 0x19d6
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jge 0x19e4
movq (%rbx,%rax,8), %rsi
leaq 0x193b(%rip), %rdi      # 0x3308
xorl %eax, %eax
callq 0x222d
jmp 0x19e4
leaq 0x1918(%rip), %rdi      # 0x32f5
xorl %eax, %eax
callq 0x2031
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
leaq 0x1941(%rip), %rsi      # 0x3333
callq 0x1120
movq %rax, 0x3712(%rip)      # 0x5110
testq %rax, %rax
jne 0x1a18
movslq (%r14), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x1924(%rip), %rdi      # 0x3335
xorl %eax, %eax
callq 0x2031
movq 0x36f1(%rip), %rdx      # 0x5110
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x10b0
testq %rax, %rax
je 0x1c67
leaq 0x10(%rsp), %r14
leaq 0x1905(%rip), %r15      # 0x334b
movq %rbx, %rdi
movl $0x20, %esi
callq 0x1080
testq %rax, %rax
je 0x1c32
movq %rax, %r12
movb $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1070
movsd %xmm0, 0x8(%rsp)
cmpq %rbx, 0x10(%rsp)
je 0x1c32
incq %r12
movq %r12, %rdi
movl $0x20, %esi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1c32
movq %rax, %r13
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
jle 0x1c32
movl %eax, %ebp
leaq 0x1(%r13), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1ad2
movb $0x0, (%rax)
movl $0x4, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x1050
testl %eax, %eax
je 0x1bc9
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1857(%rip), %rsi      # 0x3350
callq 0x1050
testl %eax, %eax
je 0x1bdf
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1840(%rip), %rsi      # 0x3355
callq 0x1050
testl %eax, %eax
je 0x1c08
movl $0x7, %edx
movq %r12, %rdi
leaq 0x1829(%rip), %rsi      # 0x335a
callq 0x1050
testl %eax, %eax
je 0x1c1e
movl $0x6, %edx
movq %r12, %rdi
leaq 0x1815(%rip), %rsi      # 0x3362
callq 0x1050
testl %eax, %eax
je 0x1c32
movl $0x7, %edx
movq %r12, %rdi
leaq 0x1800(%rip), %rsi      # 0x3369
callq 0x1050
testl %eax, %eax
je 0x1c32
movl $0x6, %edx
movq %r12, %rdi
leaq 0x17ec(%rip), %rsi      # 0x3371
callq 0x1050
testl %eax, %eax
je 0x1c32
movl $0x4, %edx
movq %r12, %rdi
leaq 0x17d7(%rip), %rsi      # 0x3378
callq 0x1050
testl %eax, %eax
je 0x1c51
leaq 0x17c8(%rip), %rdi      # 0x337d
movsd 0x8(%rsp), %xmm0
movl %ebp, %esi
movq %r12, %rdx
movb $0x1, %al
callq 0x222d
jmp 0x1c32
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x1412
jmp 0x1c32
leaq 0x146e(%rip), %rdi      # 0x3054
movl %ebp, %esi
xorl %eax, %eax
callq 0x24d0
movl %ebp, %edi
movl $0x1, %esi
callq 0x12ac
movq 0x8(%rax), %rax
movq %rax, 0x3522(%rip)      # 0x5128
jmp 0x1c32
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x16a7
jmp 0x1c32
addq $0x9, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x171a
movq 0x34d7(%rip), %rdx      # 0x5110
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x10b0
testq %rax, %rax
jne 0x1a46
jmp 0x1c67
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x1606
jmp 0x1c32
cmpl $0x0, 0x347e(%rip)      # 0x50ec
je 0x1d84
movl 0x34ba(%rip), %esi      # 0x5134
leaq 0x171a(%rip), %rdi      # 0x339b
xorl %eax, %eax
callq 0x1090
movq 0x3499(%rip), %rdi      # 0x5128
callq 0x1f17
movslq 0x37d9(%rip), %r14      # 0x5474
movq %r14, %rdi
shlq $0x5, %rdi
callq 0x1100
movq %rax, %rbx
movq 0x37b7(%rip), %rax      # 0x5468
testq %rax, %rax
je 0x1cd8
movq %rbx, %rcx
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movupd %xmm1, 0x10(%rcx)
movupd %xmm0, (%rcx)
movq 0x18(%rax), %rax
addq $0x20, %rcx
testq %rax, %rax
jne 0x1cb9
leaq -0x552(%rip), %rcx      # 0x178d
movl $0x20, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1060
cmpl $0x0, 0x377e(%rip)      # 0x5474
jle 0x1d52
addq $0x10, %rbx
xorl %r15d, %r15d
leaq 0x16a3(%rip), %r14      # 0x33a9
movl -0x8(%rbx), %esi
movl -0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq -0x10(%rbx), %rdx
xorps %xmm2, %xmm2
cvtsi2sdl 0x374d(%rip), %xmm2 # 0x5470
divsd %xmm2, %xmm0
movl (%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm2, %xmm1
movq %r14, %rdi
movb $0x2, %al
callq 0x1090
incq %r15
movslq 0x372b(%rip), %rax      # 0x5474
addq $0x20, %rbx
cmpq %rax, %r15
jl 0x1d06
movl 0x33d8(%rip), %esi      # 0x5130
leaq 0x1662(%rip), %rdi      # 0x33c1
xorl %eax, %eax
callq 0x1090
movl 0x33cc(%rip), %esi      # 0x5138
leaq 0x1664(%rip), %rdi      # 0x33d7
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
cmpl $0x0, 0x335d(%rip)      # 0x50e8
je 0x1d9b
movq 0x3394(%rip), %rdi      # 0x5128
xorl %esi, %esi
callq 0x1daf
xorl %eax, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq