// File: /workspace/github_c_makefile_star2_O3/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, 0x3cac(%rip)      # 0x5470
movq (%rbx), %rdi
leaq 0x1940(%rip), %rsi      # 0x310e
callq 0x1fbc
leaq 0x1936(%rip), %r14      # 0x3110
leaq 0x1823(%rip), %r12      # 0x3004
leaq 0x1840(%rip), %r13      # 0x3028
movq 0x37e9(%rip), %r15      # 0x4fd8
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1150
cmpl $0x62, %eax
jg 0x1827
cmpl $0x4c, %eax
jle 0x1845
addl $-0x4d, %eax
cmpl $0x8, %eax
ja 0x196e
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x38f3(%rip)      # 0x5118
jmp 0x17ef
leal -0x6d(%rax), %ecx
cmpl $0xa, %ecx
ja 0x185f
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, 0x38d5(%rip)      # 0x5118
jmp 0x17ef
cmpl $0x43, %eax
je 0x18ad
cmpl $0x46, %eax
jne 0x1969
movl $0x1, 0x3893(%rip)      # 0x50f0
jmp 0x17ef
cmpl $0x63, %eax
je 0x1935
cmpl $0x66, %eax
jne 0x196e
movl $0x0, 0x3875(%rip)      # 0x50f0
jmp 0x17ef
movl $0x1, 0x385e(%rip)      # 0x50e8
jmp 0x17ef
movl $0x1, 0x3853(%rip)      # 0x50ec
jmp 0x17ef
movl $0x1, 0x3874(%rip)      # 0x511c
jmp 0x17ef
movl $0x1, 0x386d(%rip)      # 0x5124
jmp 0x17ef
movq (%r15), %rdi
leaq 0x1b60(%rip), %rsi      # 0x3426
leaq 0x1c(%rsp), %rdx
xorl %eax, %eax
callq 0x1110
cmpl $0x1, %eax
jne 0x1944
movl 0x1c(%rsp), %eax
movl %eax, 0x3813(%rip)      # 0x50f4
jmp 0x17ef
movl 0x3834(%rip), %eax      # 0x5120
leal 0x1(%rax), %ecx
movl %ecx, 0x382b(%rip)      # 0x5120
testl %eax, %eax
jle 0x195a
movl $0x5, %edi
callq 0x26bc
jmp 0x17ef
movl $0x0, 0x380a(%rip)      # 0x511c
jmp 0x17ef
movl $0x0, 0x37cb(%rip)      # 0x50ec
jmp 0x17ef
movl $0x0, 0x37b8(%rip)      # 0x50e8
jmp 0x17ef
movl $0x0, 0x37e5(%rip)      # 0x5124
jmp 0x17ef
movq (%r15), %rsi
leaq 0x17d3(%rip), %rdi      # 0x3121
xorl %eax, %eax
callq 0x220f
jmp 0x17ef
movl $0x4, %edi
callq 0x26bc
jmp 0x17ef
cmpl $-0x1, %eax
je 0x1984
movq (%rbx), %rsi
leaq 0x17c6(%rip), %rdi      # 0x313e
xorl %eax, %eax
callq 0x2013
jmp 0x17ef
movq 0x3645(%rip), %r14      # 0x4fd0
movslq (%r14), %rax
cmpl %ebp, %eax
jge 0x19ad
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jge 0x19bb
movq (%rbx,%rax,8), %rsi
leaq 0x1980(%rip), %rdi      # 0x3324
xorl %eax, %eax
callq 0x220f
jmp 0x19bb
leaq 0x195d(%rip), %rdi      # 0x3311
xorl %eax, %eax
callq 0x2013
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
leaq 0x1986(%rip), %rsi      # 0x334f
callq 0x1120
movq %rax, 0x373b(%rip)      # 0x5110
testq %rax, %rax
jne 0x19f6
movslq (%r14), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x1969(%rip), %rdi      # 0x3351
xorl %eax, %eax
callq 0x2013
movq 0x371a(%rip), %rax      # 0x5110
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rax, %rdx
callq 0x10b0
testq %rax, %rax
je 0x1c41
leaq 0x10(%rsp), %r14
leaq 0x1947(%rip), %r15      # 0x3367
movq %rbx, %rdi
movl $0x20, %esi
callq 0x1080
testq %rax, %rax
je 0x1c0c
movq %rax, %r12
movb $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1070
movsd %xmm0, 0x8(%rsp)
cmpq %rbx, 0x10(%rsp)
je 0x1c0c
incq %r12
movq %r12, %rdi
movl $0x20, %esi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1c0c
movq %rax, %r13
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
jle 0x1c0c
movl %eax, %ebp
leaq 0x1(%r13), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1aac
movb $0x0, (%rax)
movl $0x4, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x1050
testl %eax, %eax
je 0x1ba3
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1899(%rip), %rsi      # 0x336c
callq 0x1050
testl %eax, %eax
je 0x1bb9
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1882(%rip), %rsi      # 0x3371
callq 0x1050
testl %eax, %eax
je 0x1be2
movl $0x7, %edx
movq %r12, %rdi
leaq 0x186b(%rip), %rsi      # 0x3376
callq 0x1050
testl %eax, %eax
je 0x1bf8
movl $0x6, %edx
movq %r12, %rdi
leaq 0x1857(%rip), %rsi      # 0x337e
callq 0x1050
testl %eax, %eax
je 0x1c0c
movl $0x7, %edx
movq %r12, %rdi
leaq 0x1842(%rip), %rsi      # 0x3385
callq 0x1050
testl %eax, %eax
je 0x1c0c
movl $0x6, %edx
movq %r12, %rdi
leaq 0x182e(%rip), %rsi      # 0x338d
callq 0x1050
testl %eax, %eax
je 0x1c0c
movl $0x4, %edx
movq %r12, %rdi
leaq 0x1819(%rip), %rsi      # 0x3394
callq 0x1050
testl %eax, %eax
je 0x1c2b
leaq 0x180a(%rip), %rdi      # 0x3399
movsd 0x8(%rsp), %xmm0
movl %ebp, %esi
movq %r12, %rdx
movb $0x1, %al
callq 0x220f
jmp 0x1c0c
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x1413
jmp 0x1c0c
leaq 0x14b0(%rip), %rdi      # 0x3070
movl %ebp, %esi
xorl %eax, %eax
callq 0x24b2
movl %ebp, %edi
movl $0x1, %esi
callq 0x12ac
movq 0x8(%rax), %rax
movq %rax, 0x3548(%rip)      # 0x5128
jmp 0x1c0c
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x168e
jmp 0x1c0c
addq $0x9, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x16f9
movq 0x34fd(%rip), %rdx      # 0x5110
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x10b0
testq %rax, %rax
jne 0x1a20
jmp 0x1c41
addq $0x6, %r13
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movq %r13, %rsi
callq 0x15f4
jmp 0x1c0c
cmpl $0x0, 0x34a4(%rip)      # 0x50ec
je 0x1d5e
movl 0x34e0(%rip), %esi      # 0x5134
leaq 0x175c(%rip), %rdi      # 0x33b7
xorl %eax, %eax
callq 0x1090
movq 0x34bf(%rip), %rdi      # 0x5128
callq 0x1ef1
movslq 0x37ff(%rip), %r14      # 0x5474
movq %r14, %rdi
shlq $0x5, %rdi
callq 0x1100
movq %rax, %rbx
movq 0x37dd(%rip), %rax      # 0x5468
testq %rax, %rax
je 0x1cb2
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 0x1c93
leaq -0x555(%rip), %rcx      # 0x1764
movl $0x20, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1060
cmpl $0x0, 0x37a4(%rip)      # 0x5474
jle 0x1d2c
addq $0x10, %rbx
xorl %r15d, %r15d
leaq 0x16e5(%rip), %r14      # 0x33c5
movl -0x8(%rbx), %esi
movl -0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq -0x10(%rbx), %rdx
xorps %xmm2, %xmm2
cvtsi2sdl 0x3773(%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 0x3751(%rip), %rax      # 0x5474
addq $0x20, %rbx
cmpq %rax, %r15
jl 0x1ce0
movl 0x33fe(%rip), %esi      # 0x5130
leaq 0x16a4(%rip), %rdi      # 0x33dd
xorl %eax, %eax
callq 0x1090
movl 0x33f2(%rip), %esi      # 0x5138
leaq 0x16a6(%rip), %rdi      # 0x33f3
xorl %eax, %eax
callq 0x1090
movl $0xa, %edi
callq 0x1040
cmpl $0x0, 0x3383(%rip)      # 0x50e8
je 0x1d75
movq 0x33ba(%rip), %rdi      # 0x5128
xorl %esi, %esi
callq 0x1d89
xorl %eax, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq