// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
cmpl $0x1, 0x58(%rdi)
jne 0x5042
movq 0x140(%rbx), %rax
movslq 0x20(%rbx), %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
movslq 0x2c(%rbx), %rcx
subsd (%rax,%rcx,8), %xmm0
jmp 0x504d
movq 0x128(%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x2a8(%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x48(%rbx), %rax
movsd (%rax), %xmm0
movsd 0x218(%rbx), %xmm1
addsd 0x3054(%rip), %xmm1     # 0x80d0
callq 0x2340
mulsd 0x10(%rsp), %xmm0
movq 0x360(%rbx), %rax
movsd %xmm0, (%rax)
movsd 0x208(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x210(%rbx), %xmm1
movsd 0x200(%rbx), %xmm2
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
callq 0x2340
mulsd 0x10(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movq 0x350(%rbx), %rax
movsd %xmm0, (%rax)
movsd 0x1d0(%rbx), %xmm1
movq 0x310(%rbx), %rax
movsd %xmm1, (%rax)
movsd 0x4b0(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5101
movsd %xmm0, (%rax)
movq 0x2a8(%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rbx), %rax
movsd (%rax), %xmm0
movsd 0x218(%rbx), %xmm1
addsd 0x2fa6(%rip), %xmm1     # 0x80d0
callq 0x2340
mulsd 0x8(%rsp), %xmm0
movq 0x370(%rbx), %rax
movsd %xmm0, (%rax)
movq 0x288(%rbx), %rax
movq 0x290(%rbx), %rcx
movsd (%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rax), %xmm0
divsd 0x2f7c(%rip), %xmm0     # 0x80e0
movsd 0x2e9c(%rip), %xmm1     # 0x8008
subsd 0x1a0(%rbx), %xmm1
callq 0x2340
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x310(%rbx), %rax
movsd (%rax), %xmm0
movsd 0x1a0(%rbx), %xmm1
callq 0x2340
mulsd 0x8(%rsp), %xmm0
movq 0x338(%rbx), %rax
movsd %xmm0, (%rax)
movsd 0x508(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x51c4
movsd %xmm1, (%rax)
movapd %xmm1, %xmm0
movq 0x2f0(%rbx), %rcx
mulsd (%rcx), %xmm0
movq 0x48(%rbx), %rcx
movsd 0x2e2d(%rip), %xmm2     # 0x8008
movapd %xmm2, %xmm1
subsd (%rcx), %xmm1
mulsd %xmm0, %xmm1
movq 0x3c0(%rbx), %rdx
movsd %xmm1, (%rdx)
movq 0x2f8(%rbx), %rdx
movq 0x3b8(%rbx), %rsi
addsd (%rdx), %xmm1
movsd %xmm1, (%rsi)
movq 0x3c8(%rbx), %rdx
movabsq $0x4056800000000000, %rsi # imm = 0x4056800000000000
movq %rsi, (%rdx)
movsd 0x518(%rbx), %xmm1
movsd 0x2edc(%rip), %xmm0     # 0x8108
ucomisd %xmm1, %xmm0
jbe 0x5242
addsd 0x2dce(%rip), %xmm1     # 0x8008
movsd %xmm1, (%rdx)
movapd %xmm1, %xmm0
movq 0x300(%rbx), %rdx
movq 0x3d0(%rbx), %rsi
addsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
movq 0x350(%rbx), %rdx
subsd (%rdx), %xmm2
mulsd (%rax), %xmm2
movq 0x340(%rbx), %rdx
movsd %xmm2, (%rdx)
movsd (%rax), %xmm0
movq 0x298(%rbx), %rax
mulsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rcx), %xmm0
movsd 0x218(%rbx), %xmm1
callq 0x2340
mulsd 0x8(%rsp), %xmm0
movq 0x358(%rbx), %rcx
movsd %xmm0, (%rcx)
movq 0x338(%rbx), %rax
movq 0x348(%rbx), %rdx
movsd (%rax), %xmm0
movq 0x350(%rbx), %rax
mulsd (%rax), %xmm0
movsd %xmm0, (%rdx)
movq 0x330(%rbx), %rax
movq 0x340(%rbx), %rdx
movsd (%rdx), %xmm0
subsd (%rcx), %xmm0
movsd %xmm0, (%rax)
movsd 0x500(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x52fa
movsd %xmm1, (%rax)
movapd %xmm1, %xmm0
movq 0x50(%rbx), %rcx
mulsd (%rcx), %xmm0
movq 0x320(%rbx), %rcx
movsd %xmm0, (%rcx)
movsd 0x510(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5323
movsd %xmm1, (%rcx)
movapd %xmm1, %xmm0
movsd (%rax), %xmm1
subsd %xmm0, %xmm1
movq 0x308(%rbx), %rax
movsd %xmm1, (%rax)
movsd 0x4d0(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x534c
movsd %xmm0, (%rax)
movapd %xmm0, %xmm1
mulsd 0x2d8c(%rip), %xmm1     # 0x80e0
movq 0x288(%rbx), %rcx
movq 0x318(%rbx), %rax
divsd (%rcx), %xmm1
movsd %xmm1, (%rax)
movsd 0x4f8(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x537c
movsd %xmm0, (%rax)
addq $0x20, %rsp
popq %rbx
retq