// File: JRLamontagne[P]cdice_sa/CDICE.cpp
// Function: calcEcon1(DICE*)
void calcEcon1(DICE *dice)
{

  Econ *econ  = &dice->econ;
  Clim *clim = &dice->clim;
  Dvars *dvars = &dice->dvars;
  Ctrl *ctrl = &dice->ctrl;
  Lims *lims = &dice->lims;
  Config *config = &dice->config;

  // Variable to hold the appropriate temperature
  double temp = 0.0;
  
  // Where do we get the temperature from?
  if(ctrl->use_doeclim == 1) {
    temp = clim->temp[config->hind_ns-1] - clim->temp[config->i1900];
    //temp = clim->temp[config->hind_ns-1];
  }
  else {
    temp = clim->tatm[0];
  }
  
  // Marginal cost of abatement
  econ->mcabate[0] = econ->pbacktime[0]*pow(dvars->miu[0],(econ->expcost2-1));
  
  // Damages fraction
  econ->damfrac[0] = econ->a1*temp+econ->a2*pow(temp,econ->a3);
  
  // Capital stock
  econ->k[0] = econ->k0;
  if(econ->k[0] < lims->k_lo) {
    econ->k[0] = lims->k_lo;
  }
  
  // Carbon price
  econ->cprice[0] = econ->pbacktime[0]*pow(dvars->miu[0],(econ->expcost2-1));
  
  // Gross world product (gross abatement and damages)
  econ->ygross[0] = econ->al[0]*pow((econ->l[0]/1000.0),(1.0-econ->gama))*pow(econ->k[0],econ->gama);
  if(econ->ygross[0] < lims->ygross_lo) {
    econ->ygross[0] = lims->ygross_lo;
  }
  
  // Industrial emissions
  econ->eind[0] = econ->sigma[0]*econ->ygross[0]*(1.0-dvars->miu[0]);
  
  // Total emissions	
  econ->e[0] = econ->eind[0]+econ->etree[0];
  
  // Cumulative emissions
  econ->cca[0] = 90.0;
  if(econ->cca[0] > lims->cca_up) {
    econ->cca[0] = lims->cca_up + 1.0;
  }
  
  // Cumulative total emissions
  econ->ccatot[0] = econ->cca[0] + econ->cumetree[0];

  // Net output damages
  econ->ynet[0] = econ->ygross[0]*(1.0-econ->damfrac[0]);
  
  // Abatement costs
  econ->abatecost[0] = econ->ygross[0]*econ->cost1[0]*pow(dvars->miu[0],econ->expcost2);
  
  // Damages
  econ->damages[0] = econ->ygross[0]*econ->damfrac[0];
  
  // Gross world product (net of abatement and damages)
  econ->y[0] = econ->ynet[0]-econ->abatecost[0];
  if(econ->y[0] < lims->y_lo) {
    econ->y[0] = lims->y_lo;
  }
  
  // Investment
  econ->i[0] = dvars->s[0]*econ->y[0];
  if(econ->i[0] < lims->i_lo) {
    econ->i[0] = lims->i_lo;
  }
  
  // Consumption
  econ->c[0] = econ->y[0]-econ->i[0];
  if(econ->c[0] < lims->c_lo) {
    econ->c[0] = lims->c_lo;
  }

  // Per capita consumption
  econ->cpc[0] = 1000.0*econ->c[0]/econ->l[0];
  if(econ->cpc[0] < lims->cpc_lo) {
    econ->cpc[0] = lims->cpc_lo;
  }

  return;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x68(%rsp)
movq 0x80(%rsp), %rax
addq $0x58, %rax
movq %rax, 0x60(%rsp)
movq 0x80(%rsp), %rax
addq $0x4a8, %rax            # imm = 0x4A8
movq %rax, 0x58(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x60(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x161e9
movq 0x70(%rsp), %rax
movq 0xe0(%rax), %rax
movq 0x50(%rsp), %rcx
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x70(%rsp), %rax
movq 0xe0(%rax), %rax
movq 0x50(%rsp), %rcx
movslq 0x2c(%rcx), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x161ff
movq 0x70(%rsp), %rax
movq 0xc8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x78(%rsp), %rax
movq 0x118(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x88(%rax), %xmm1
movsd 0x5dd1(%rip), %xmm2     # 0x1c008
subsd %xmm2, %xmm1
callq 0x9c60
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1d0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movsd 0x70(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x78(%rsp), %rax
movsd 0x78(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x78(%rsp), %rax
movsd 0x80(%rax), %xmm1
callq 0x9c60
movsd 0x30(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movaps %xmm0, %xmm3
movsd 0x40(%rsp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1c0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movsd 0x40(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x180(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x180(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16326
movq 0x58(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x180(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x118(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x88(%rax), %xmm1
movsd 0x5caa(%rip), %xmm2     # 0x1c008
subsd %xmm2, %xmm1
callq 0x9c60
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1e0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x100(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x78(%rsp), %rax
movq 0xf8(%rax), %rax
movsd (%rax), %xmm0
movsd 0x5dde(%rip), %xmm1     # 0x1c190
divsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movsd 0x5c45(%rip), %xmm1     # 0x1c008
subsd 0x10(%rax), %xmm1
callq 0x9c60
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x78(%rsp), %rax
movq 0x180(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x10(%rax), %xmm1
callq 0x9c60
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x60(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16456
movq 0x58(%rsp), %rax
movsd 0x60(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x160(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
mulsd (%rax), %xmm0
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x5b81(%rip), %xmm1     # 0x1c008
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x230(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x230(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x168(%rax), %rax
addsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x228(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x238(%rax), %rax
movsd 0x5cf5(%rip), %xmm0     # 0x1c1d8
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x238(%rax), %rax
movsd (%rax), %xmm0
movq 0x58(%rsp), %rax
ucomisd 0x70(%rax), %xmm0
jbe 0x16525
movq 0x58(%rsp), %rax
movsd 0x5af8(%rip), %xmm0     # 0x1c008
addsd 0x70(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x238(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x238(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x170(%rax), %rax
addsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x240(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1c0(%rax), %rax
movsd 0x5a8f(%rip), %xmm1     # 0x1c008
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1b0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x108(%rax), %rax
mulsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movsd 0x88(%rax), %xmm1
callq 0x9c60
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
movq 0x1c8(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a8(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1c0(%rax), %rax
mulsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1b8(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1b0(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1c8(%rax), %rax
subsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1a0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a0(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x58(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1668d
movq 0x58(%rsp), %rax
movsd 0x58(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1a0(%rax), %rax
movsd %xmm0, (%rax)
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x1a0(%rax), %rax
mulsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x190(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x190(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x68(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x166f4
movq 0x58(%rsp), %rax
movsd 0x68(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x190(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x1a0(%rax), %rax
movsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x190(%rax), %rax
subsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x178(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x178(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x28(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1675e
movq 0x58(%rsp), %rax
movsd 0x28(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x178(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x178(%rax), %rax
movsd 0x5a1e(%rip), %xmm0     # 0x1c190
mulsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0xf8(%rax), %rax
divsd (%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x188(%rax), %rax
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq 0x188(%rax), %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movsd 0x50(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x167d0
movq 0x58(%rsp), %rax
movsd 0x50(%rax), %xmm0
movq 0x78(%rsp), %rax
movq 0x188(%rax), %rax
movsd %xmm0, (%rax)
addq $0x88, %rsp
retq
nopl (%rax,%rax)