// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x2, %edi
callq 0x1130
movl %eax, 0x3a13(%rip)      # 0x5460
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x171b(%rip), %rsi      # 0x3176
callq 0x23f0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x170a(%rip), %rdx      # 0x3178
callq 0x1140
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x1bf4
movl -0x1c(%rbp), %eax
addl $-0x43, %eax
movl %eax, %ecx
movq %rcx, -0x2058(%rbp)
subl $0x34, %eax
ja 0x1bd8
movq -0x2058(%rbp), %rax
leaq 0x155f(%rip), %rcx      # 0x3004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x365c(%rip)      # 0x5114
jmp 0x1bef
movl $0x0, 0x364d(%rip)      # 0x5114
jmp 0x1bef
movl $0x1, 0x360a(%rip)      # 0x50e0
jmp 0x1bef
movl $0x0, 0x35fb(%rip)      # 0x50e0
jmp 0x1bef
movl $0x1, 0x3614(%rip)      # 0x5108
jmp 0x1bef
movl $0x0, 0x3605(%rip)      # 0x5108
jmp 0x1bef
movl $0x0, 0x35c6(%rip)      # 0x50d8
jmp 0x1bef
movl $0x1, 0x35b7(%rip)      # 0x50d8
jmp 0x1bef
movl $0x0, 0x35ac(%rip)      # 0x50dc
jmp 0x1bef
movl $0x1, 0x359d(%rip)      # 0x50dc
jmp 0x1bef
movl $0x1, 0x35be(%rip)      # 0x510c
jmp 0x1bef
movl $0x0, 0x35af(%rip)      # 0x510c
jmp 0x1bef
movl 0x35a8(%rip), %eax      # 0x5110
addl $0x1, %eax
movl %eax, 0x359f(%rip)      # 0x5110
cmpl $0x1, 0x3598(%rip)      # 0x5110
jle 0x1b86
movl $0x5, %edi
callq 0x2bb0
jmp 0x1b90
movl $0x4, %edi
callq 0x2bb0
jmp 0x1bef
movq 0x343f(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
leaq 0x18eb(%rip), %rsi      # 0x348e
leaq -0x20(%rbp), %rdx
movb $0x0, %al
callq 0x1100
cmpl $0x1, %eax
jne 0x1bbe
movl -0x20(%rbp), %eax
movl %eax, 0x3528(%rip)      # 0x50e4
jmp 0x1bd6
movq 0x3413(%rip), %rax      # 0x4fd8
movq (%rax), %rsi
leaq 0x15ba(%rip), %rdi      # 0x3189
movb $0x0, %al
callq 0x26a0
jmp 0x1bef
jmp 0x1bda
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x15be(%rip), %rdi      # 0x31a6
movb $0x0, %al
callq 0x2480
jmp 0x1a60
movq 0x33d5(%rip), %rax      # 0x4fd0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x1c12
leaq 0x1770(%rip), %rdi      # 0x3379
movb $0x0, %al
callq 0x2480
jmp 0x1c47
movl -0x8(%rbp), %eax
movq 0x33b4(%rip), %rcx      # 0x4fd0
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x1c45
movq -0x10(%rbp), %rax
movq 0x33a0(%rip), %rcx      # 0x4fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x174e(%rip), %rdi      # 0x338c
movb $0x0, %al
callq 0x26a0
jmp 0x1c47
movq -0x10(%rbp), %rax
movq 0x337e(%rip), %rcx      # 0x4fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1757(%rip), %rsi      # 0x33b7
callq 0x1110
movq %rax, 0x3494(%rip)      # 0x5100
cmpq $0x0, %rax
jne 0x1c92
movq -0x10(%rbp), %rax
movq 0x3353(%rip), %rcx      # 0x4fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x172e(%rip), %rdi      # 0x33b9
movb $0x0, %al
callq 0x2480
jmp 0x1c94
leaq -0x2040(%rbp), %rdi
movq 0x345e(%rip), %rdx      # 0x5100
movl $0x2000, %esi           # imm = 0x2000
callq 0x10a0
cmpq $0x0, %rax
je 0x1f21
leaq -0x2040(%rbp), %rdi
movl $0x20, %esi
callq 0x1070
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1cda
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x1cdc
jmp 0x1c94
leaq -0x2040(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1060
movsd %xmm0, -0x2048(%rbp)
movq -0x30(%rbp), %rax
leaq -0x2040(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1d06
jmp 0x1c94
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x20, %esi
callq 0x1070
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x1d33
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
jmp 0x1d38
jmp 0x1c94
movq -0x28(%rbp), %rdi
callq 0x1160
movl %eax, -0x204c(%rbp)
cmpl $0x0, -0x204c(%rbp)
jg 0x1d55
jmp 0x1c94
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0xa, %esi
callq 0x1070
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x1d80
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rdi
leaq 0x1644(%rip), %rsi      # 0x33cf
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1dba
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq $0x5, %rsi
callq 0x1520
jmp 0x1f1c
movq -0x28(%rbp), %rdi
leaq 0x160f(%rip), %rsi      # 0x33d4
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1dec
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %edi
callq 0x14d0
jmp 0x1f1a
movq -0x28(%rbp), %rdi
leaq 0x15e2(%rip), %rsi      # 0x33d9
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1e26
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq $0x5, %rsi
callq 0x1860
jmp 0x1f18
movq -0x28(%rbp), %rdi
leaq 0x15ad(%rip), %rsi      # 0x33de
movl $0x7, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1e60
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x18d0
jmp 0x1f16
movq -0x28(%rbp), %rdi
leaq 0x157b(%rip), %rsi      # 0x33e6
movl $0x6, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1e7f
jmp 0x1f14
movq -0x28(%rbp), %rdi
leaq 0x1563(%rip), %rsi      # 0x33ed
movl $0x7, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1e9b
jmp 0x1f12
movq -0x28(%rbp), %rdi
leaq 0x154f(%rip), %rsi      # 0x33f5
movl $0x6, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1eb7
jmp 0x1f10
movq -0x28(%rbp), %rdi
leaq 0x153a(%rip), %rsi      # 0x33fc
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1eee
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %edi
movq -0x28(%rbp), %rsi
addq $0x5, %rsi
callq 0x17d0
jmp 0x1f0e
movsd -0x2048(%rbp), %xmm0
movl -0x204c(%rbp), %esi
movq -0x28(%rbp), %rdx
leaq 0x14fa(%rip), %rdi      # 0x3401
movb $0x1, %al
callq 0x26a0
jmp 0x1f10
jmp 0x1f12
jmp 0x1f14
jmp 0x1f16
jmp 0x1f18
jmp 0x1f1a
jmp 0x1f1c
jmp 0x1c94
cmpl $0x0, 0x31b4(%rip)      # 0x50dc
je 0x1f2f
callq 0x2140
cmpl $0x0, 0x31a2(%rip)      # 0x50d8
je 0x1f46
movq 0x31d9(%rip), %rdi      # 0x5118
xorl %esi, %esi
callq 0x1f60
xorl %eax, %eax
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopw %cs:(%rax,%rax)