// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
callq 0x1080
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1040
movq 0x8(%r14), %rdi
callq 0x1090
movl %eax, 0x2e85(%rip)      # 0x4080
movq 0x10(%r14), %rdi
callq 0x1090
movl %eax, 0x368a(%rip)      # 0x4894
callq 0x1050
andl $0x0, 0x2e6e(%rip)      # 0x4084
movq %rax, 0x3683(%rip)      # 0x48a0
movl 0x2e5d(%rip), %eax      # 0x4080
movl 0x366b(%rip), %ecx      # 0x4894
cltd
idivl %ecx
movl %eax, 0x365e(%rip)      # 0x4890
leaq -0x1070(%rbp), %r14
leaq 0x2e50(%rip), %r15      # 0x4090
leaq 0xec(%rip), %r12        # 0x1333
movslq %ecx, %rax
cmpq %rax, %r13
jge 0x1276
movl %r13d, (%r15)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x10b0
incq %r13
movl 0x3628(%rip), %ecx      # 0x4894
addq $0x8, %r14
addq $0x4, %r15
jmp 0x1247
leaq 0x2e13(%rip), %rbx      # 0x4090
xorl %r14d, %r14d
movslq %ecx, %rax
cmpq %rax, %r14
jge 0x12ae
movq -0x1070(%rbp,%r14,8), %rdi
xorl %esi, %esi
callq 0x1060
movl (%rbx), %eax
addl %eax, 0x2de5(%rip)      # 0x4084
incq %r14
movl 0x35ec(%rip), %ecx      # 0x4894
addq $0x4, %rbx
jmp 0x1280
cvtsi2sdl 0x2dce(%rip), %xmm1 # 0x4084
mulsd 0xd4a(%rip), %xmm1      # 0x2008
cvtsi2sdl 0x2dba(%rip), %xmm0 # 0x4080
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x1050
movq %rax, 0x35cd(%rip)      # 0x48a8
leaq 0xd4e(%rip), %rdi       # 0x2030
movsd -0x30(%rbp), %xmm0
movb $0x1, %al
callq 0x1030
movq 0x35b3(%rip), %rax      # 0x48a8
subq 0x35a4(%rip), %rax      # 0x48a0
cvtsi2sd %rax, %xmm0
divsd 0xd07(%rip), %xmm0      # 0x2010
movsd %xmm0, 0x3587(%rip)     # 0x4898
leaq 0xd2b(%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