// File: JRLamontagne[P]cdice_sa/CDICEMain.cpp
// Function: calc_CDICE(DICE*, DICE*)
void calc_CDICE(DICE *dice1, DICE *dice2)
{
	
  // Run the model over the dice object
  processModel(dice1);
  
  // Make temporary variables to hold the changes in utility
  double dutil_e;
  double dutil_c;
  int i;
  int t;
  int tsub;
  
  // Loop over the available time steps
  for(t=1; t<dice1->config.nPeriods; t++) {
    
    // Reset the temp dice object
    processModel(dice2);
    
    // Increment the consumption at this time step
    dice2->econ.c[t-1] += 1.0;
    
    // Do the post processing of this run
    postProcess(dice2);
    
    // Store the utility from this run
    dutil_c = dice2->econ.utility - dice1->econ.utility;
    
    // Reset the consumption
    dice2->econ.c[t-1] = dice1->econ.c[t-1];        
    
    // Increment the emissions at this time step
    dice2->econ.e[t-1] += 1.0;
    
    // Run the model on the temporary dice object
    for(tsub=t; tsub<dice1->config.nPeriods; tsub++) {
      calcCarb(dice2, tsub);
      if(dice2->ctrl.use_doeclim) {
				doeclim_dice_ts(dice2, tsub);
      }
      else {
				calcClim(dice2, tsub);
      }
      calcEcon(dice2, tsub);
    }
    
    // Do the post processing of this run
    postProcess(dice2);
    
    // Store the utility from this run
    dutil_e = dice2->econ.utility - dice1->econ.utility;
    
    // Calculate the SCC from these differences in utility
    dice1->econ.scc[t-1] = -1000.0 * (dutil_e / dutil_c);
  }
  
  // Delete the temporary DICE object
  //free_CDICE(dice2);
	
	return;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17f80
movl $0x1, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jge 0xa1cf
movq 0x28(%rsp), %rdi
callq 0x17f80
movq 0x28(%rsp), %rax
movq 0x308(%rax), %rax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x11f9f(%rip), %xmm0    # 0x1c008
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x28(%rsp), %rdi
callq 0x179f0
movq 0x28(%rsp), %rax
movsd 0x380(%rax), %xmm0
movq 0x30(%rsp), %rax
subsd 0x380(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq 0x308(%rax), %rax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movq 0x308(%rax), %rax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x28(%rsp), %rax
movq 0x3b8(%rax), %rax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x11f17(%rip), %xmm0    # 0x1c008
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jge 0xa162
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x167e0
movq 0x28(%rsp), %rax
cmpl $0x0, 0x58(%rax)
je 0xa139
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x1ac20
jmp 0xa147
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x16b20
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x16e20
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xa103
movq 0x28(%rsp), %rdi
callq 0x179f0
movq 0x28(%rsp), %rax
movsd 0x380(%rax), %xmm0
movq 0x30(%rsp), %rax
subsd 0x380(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm1
divsd 0x18(%rsp), %xmm1
movsd 0x11e70(%rip), %xmm0    # 0x1c010
mulsd %xmm1, %xmm0
movq 0x30(%rsp), %rax
movq 0x2b0(%rax), %rax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xa030
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)