// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %rdi
callq 0x1140
movl %eax, 0x3dac(%rip)      # 0x5470
movq (%rbx), %rdi
leaq 0x1a40(%rip), %rsi      # 0x310e
callq 0x1e50
leaq 0x1a36(%rip), %r14      # 0x3110
leaq 0x1923(%rip), %r13      # 0x3004
leaq 0x1940(%rip), %r12      # 0x3028
movq 0x38e9(%rip), %r15      # 0x4fd8
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1150
leal -0x6d(%rax), %ecx
cmpl $0xa, %ecx
jbe 0x173a
leal -0x4d(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x174c
cmpl $0x43, %eax
je 0x1842
cmpl $0x46, %eax
je 0x181b
cmpl $0x63, %eax
je 0x1836
cmpl $0x66, %eax
je 0x182a
cmpl $-0x1, %eax
jne 0x1762
jmp 0x1874
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
andl $0x0, 0x39ce(%rip)      # 0x5118
jmp 0x16ef
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x1, 0x39b8(%rip)      # 0x5118
jmp 0x16ef
movq (%rbx), %rsi
leaq 0x19d2(%rip), %rdi      # 0x313e
xorl %eax, %eax
callq 0x1ea7
jmp 0x16ef
andl $0x0, 0x399d(%rip)      # 0x511c
jmp 0x16ef
movl 0x3996(%rip), %eax      # 0x5120
leal 0x1(%rax), %ecx
movl %ecx, 0x398d(%rip)      # 0x5120
testl %eax, %eax
jle 0x1867
pushq $0x5
popq %rdi
callq 0x253a
jmp 0x16ef
movq (%r15), %rdi
leaq 0x1c74(%rip), %rsi      # 0x3426
leaq 0x1c(%rsp), %rdx
xorl %eax, %eax
callq 0x1110
cmpl $0x1, %eax
jne 0x1851
movl 0x1c(%rsp), %eax
movl %eax, 0x3923(%rip)      # 0x50f4
jmp 0x16ef
andl $0x0, 0x390b(%rip)      # 0x50e8
jmp 0x16ef
andl $0x0, 0x3903(%rip)      # 0x50ec
jmp 0x16ef
movl $0x1, 0x38f0(%rip)      # 0x50e8
jmp 0x16ef
movl $0x1, 0x38e5(%rip)      # 0x50ec
jmp 0x16ef
movl $0x1, 0x3906(%rip)      # 0x511c
jmp 0x16ef
movl $0x1, 0x38cb(%rip)      # 0x50f0
jmp 0x16ef
andl $0x0, 0x38bf(%rip)      # 0x50f0
jmp 0x16ef
andl $0x0, 0x38e7(%rip)      # 0x5124
jmp 0x16ef
movl $0x1, 0x38d8(%rip)      # 0x5124
jmp 0x16ef
movq (%r15), %rsi
leaq 0x18c6(%rip), %rdi      # 0x3121
xorl %eax, %eax
callq 0x2099
jmp 0x16ef
pushq $0x4
popq %rdi
callq 0x253a
jmp 0x16ef
movq 0x3755(%rip), %r14      # 0x4fd0
movslq (%r14), %rax
cmpl %ebp, %eax
jge 0x189d
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jge 0x18ab
movq (%rbx,%rax,8), %rsi
leaq 0x1a90(%rip), %rdi      # 0x3324
xorl %eax, %eax
callq 0x2099
jmp 0x18ab
leaq 0x1a6d(%rip), %rdi      # 0x3311
xorl %eax, %eax
callq 0x1ea7
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
leaq 0x1a96(%rip), %rsi      # 0x334f
callq 0x1120
movq %rax, 0x384b(%rip)      # 0x5110
testq %rax, %rax
jne 0x18df
movslq (%r14), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x1a79(%rip), %rdi      # 0x3351
xorl %eax, %eax
callq 0x1ea7
leaq 0x20(%rsp), %rbx
pushq $0x20
popq %rbp
leaq 0x10(%rsp), %r14
movq 0x381d(%rip), %rdx      # 0x5110
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x10b0
testq %rax, %rax
je 0x1aee
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1080
testq %rax, %rax
je 0x18ec
movq %rax, %r12
movb $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1070
movsd %xmm0, 0x8(%rsp)
cmpq %rbx, 0x10(%rsp)
je 0x18ec
incq %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x18ec
movq %rax, %r15
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x1170
testl %eax, %eax
jle 0x18ec
movl %eax, %r12d
movq %r14, %rbp
leaq 0x1(%r15), %r13
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x1080
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1981
movb $0x0, (%rax)
movq %r13, %rdi
leaq 0x19dc(%rip), %rsi      # 0x3367
pushq $0x4
popq %r14
movq %r14, %rdx
callq 0x1050
testl %eax, %eax
je 0x1a76
movq %r13, %rdi
leaq 0x19c3(%rip), %rsi      # 0x336c
movq %r14, %rdx
callq 0x1050
testl %eax, %eax
je 0x1a8d
movq %r13, %rdi
leaq 0x19ae(%rip), %rsi      # 0x3371
movq %r14, %rdx
callq 0x1050
testl %eax, %eax
je 0x1a97
movq %r13, %rdi
leaq 0x1999(%rip), %rsi      # 0x3376
pushq $0x7
popq %rdx
callq 0x1050
testl %eax, %eax
movq %rbp, %r14
je 0x1ab7
movq %r13, %rdi
leaq 0x1984(%rip), %rsi      # 0x337e
pushq $0x6
popq %rdx
callq 0x1050
testl %eax, %eax
pushq $0x20
popq %rbp
je 0x18ec
movq %r13, %rdi
leaq 0x196e(%rip), %rsi      # 0x3385
pushq $0x7
popq %rdx
callq 0x1050
testl %eax, %eax
je 0x18ec
movq %r13, %rdi
leaq 0x195c(%rip), %rsi      # 0x338d
pushq $0x6
popq %rdx
callq 0x1050
testl %eax, %eax
je 0x18ec
movq %r13, %rdi
leaq 0x1949(%rip), %rsi      # 0x3394
pushq $0x4
popq %rdx
callq 0x1050
testl %eax, %eax
je 0x1ad4
leaq 0x193b(%rip), %rdi      # 0x3399
movsd 0x8(%rsp), %xmm0
movl %r12d, %esi
movq %r13, %rdx
movb $0x1, %al
callq 0x2099
jmp 0x18ec
addq $0x6, %r15
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
movq %r15, %rsi
callq 0x13d4
jmp 0x1aac
movl %r12d, %edi
callq 0x13aa
jmp 0x1aac
addq $0x6, %r15
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
movq %r15, %rsi
callq 0x15e7
movq %rbp, %r14
pushq $0x20
popq %rbp
jmp 0x18ec
addq $0x9, %r15
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
movq %r15, %rsi
callq 0x1629
pushq $0x20
popq %rbp
jmp 0x18ec
addq $0x6, %r15
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
movq %r15, %rsi
callq 0x1578
jmp 0x18ec
cmpl $0x0, 0x35f7(%rip)      # 0x50ec
je 0x1bf7
movl 0x3633(%rip), %esi      # 0x5134
leaq 0x18af(%rip), %rdi      # 0x33b7
xorl %eax, %eax
callq 0x1090
movq 0x3612(%rip), %rdi      # 0x5128
callq 0x1d8b
movslq 0x3952(%rip), %r14      # 0x5474
movq %r14, %rdi
shlq $0x5, %rdi
callq 0x1100
movq %rax, %rbx
leaq 0x3930(%rip), %rax      # 0x5468
movq %rbx, %rcx
movq (%rax), %rax
testq %rax, %rax
je 0x1b5f
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movupd %xmm1, 0x10(%rcx)
movupd %xmm0, (%rcx)
addq $0x18, %rax
addq $0x20, %rcx
jmp 0x1b3b
leaq -0x4fb(%rip), %rcx      # 0x166b
pushq $0x20
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1060
addq $0x10, %rbx
xorl %r15d, %r15d
leaq 0x1843(%rip), %r14      # 0x33c5
movslq 0x38eb(%rip), %rax      # 0x5474
cmpq %rax, %r15
jge 0x1bc7
movl -0x8(%rbx), %esi
movl -0x4(%rbx), %eax
cvtsi2sd %rax, %xmm0
movq -0x10(%rbx), %rdx
cvtsi2sdl 0x38cb(%rip), %xmm2 # 0x5470
divsd %xmm2, %xmm0
movl (%rbx), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm2, %xmm1
movq %r14, %rdi
movb $0x2, %al
callq 0x1090
incq %r15
addq $0x20, %rbx
jmp 0x1b82
movl 0x3563(%rip), %esi      # 0x5130
leaq 0x1809(%rip), %rdi      # 0x33dd
xorl %eax, %eax
callq 0x1090
movl 0x3557(%rip), %esi      # 0x5138
leaq 0x180b(%rip), %rdi      # 0x33f3
xorl %eax, %eax
callq 0x1090
pushq $0xa
popq %rdi
callq 0x1040
cmpl $0x0, 0x34ea(%rip)      # 0x50e8
je 0x1c0e
movq 0x3521(%rip), %rdi      # 0x5128
xorl %esi, %esi
callq 0x1c22
xorl %eax, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq