// File: /workspace/github_cpp_makefile_star2_O1/dekanfrus[P]pThreads/osproj2a.c
// Function: main
int main( int argc, char *argv[] )
{
  /* local variables */
  int ii;
  int retval;
  pthread_t p_threads[MAX_THREADS];
  pthread_attr_t attr;
  double computed_pi;

  /* initialize local variables */
  retval = 0;

  pthread_attr_init( &attr );
  pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );

  /* parse command line arguments into sample points and number of threads */
  /* there is no error checking here!!!!! */
  sample_points = atoi(argv[1]);
  num_threads = atoi(argv[2]);

  /* uncomment this block if you want interactive input!!!! */
  /* if so...comment out the two statements above */
    
  /*printf( "Enter number of sample points: " );
  scanf( "%d", &sample_points );
  printf( "Enter number of threads: " );
  scanf( "%d%", &num_threads );*/
  
  // Store the current time in the "start" variable
  start = clock();
  
  total_hits = 0;
  sample_points_per_thread = sample_points / num_threads;

  // Create the number of threads as requested by the user from the command line
  // Each thread will execute the compute_pi function
  for( ii=0; ii<num_threads; ii++ )
    {
	  
      hits[ii] = ii;
      pthread_create( &p_threads[ ii ], &attr, compute_pi, (void *) &hits[ii] );
	  
    }

  // Join all threads
  for( ii=0; ii<num_threads; ii++ )
    {
       pthread_join( p_threads[ ii ], NULL );
       total_hits += hits[ ii ];
	   
    }
  
   computed_pi = 4.0 * (double) total_hits / ((double) (sample_points));

   // Store the final clock time
   end = clock();

   printf( "Computed PI = %lf\n", computed_pi );

   // Calculate the total execution time and then print that to the screen
   total = (double)(end - start) / CLOCKS_PER_SEC;

   printf("Execution Time = %lf\n", total);

  /* return to calling environment */
  return( retval );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movq %rsi, %rbx
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x1080
movq %r14, %rdi
xorl %esi, %esi
callq 0x1040
movq 0x8(%rbx), %rdi
callq 0x1090
movl %eax, 0x2e88(%rip)      # 0x4080
movq 0x10(%rbx), %rdi
callq 0x1090
movl %eax, 0x368d(%rip)      # 0x4894
callq 0x1050
movq %rax, 0x368d(%rip)      # 0x48a0
movl $0x0, 0x2e67(%rip)      # 0x4084
movl 0x2e5d(%rip), %eax      # 0x4080
movl 0x366b(%rip), %ecx      # 0x4894
cltd
idivl %ecx
movl %eax, 0x365e(%rip)      # 0x4890
testl %ecx, %ecx
jle 0x127d
leaq -0x1070(%rbp), %rbx
leaq 0x2e4c(%rip), %r14      # 0x4090
xorl %r13d, %r13d
leaq 0xf4(%rip), %r15        # 0x1342
leaq -0x68(%rbp), %r12
movl %r13d, (%r14)
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x10b0
incq %r13
movslq 0x3624(%rip), %rax      # 0x4894
addq $0x8, %rbx
addq $0x4, %r14
cmpq %rax, %r13
jl 0x1252
cmpl $0x0, 0x3610(%rip)      # 0x4894
jle 0x12ba
leaq 0x2e03(%rip), %rbx      # 0x4090
xorl %r14d, %r14d
movq -0x1070(%rbp,%r14,8), %rdi
xorl %esi, %esi
callq 0x1060
movl (%rbx), %eax
addl %eax, 0x2ddd(%rip)      # 0x4084
incq %r14
movslq 0x35e3(%rip), %rax      # 0x4894
addq $0x4, %rbx
cmpq %rax, %r14
jl 0x1290
cvtsi2sdl 0x2dc2(%rip), %xmm1 # 0x4084
mulsd 0xd3e(%rip), %xmm1      # 0x2008
cvtsi2sdl 0x2dae(%rip), %xmm0 # 0x4080
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x1050
movq %rax, 0x35c1(%rip)      # 0x48a8
leaq 0xd42(%rip), %rdi       # 0x2030
movsd -0x30(%rbp), %xmm0
movb $0x1, %al
callq 0x1030
movq 0x35a7(%rip), %rax      # 0x48a8
subq 0x3598(%rip), %rax      # 0x48a0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0xcf8(%rip), %xmm0      # 0x2010
movsd %xmm0, 0x3578(%rip)     # 0x4898
leaq 0xd1c(%rip), %rdi       # 0x2043
movb $0x1, %al
callq 0x1030
xorl %eax, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq