#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int exp(double);
void powellgrad(double *x, int N, double *g, void *params) {
  double t1, t2;
  t1 = (10000 * x[0] * x[1] - 1);
  t2 = (exp(-x[0]) + exp(-x[1]) - 1.0001);
  g[0] = 2 * t1 * 10000 * x[1] - 2 * exp(-x[0]) * t2;
  g[1] = 2 * t1 * 10000 * x[0] - 2 * exp(-x[1]) * t2;
}


x86 assembly (clang, -O0):
<powellgrad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xecd(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xecc(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe5c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe43(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xdb6(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xda1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powellgrad>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movapd %xmm0,%xmm1
mulsd  0xed2(%rip),%xmm1
mulsd  0x8(%rdi),%xmm1
addsd  0xecd(%rip),%xmm1
movapd %xmm1,(%rsp)
xorpd  0xed8(%rip),%xmm0
call   1030 <exp@plt>
mov    %eax,%ebp
movsd  0x8(%rbx),%xmm0
xorps  0xec5(%rip),%xmm0
call   1030 <exp@plt>
add    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xe9f(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd (%rsp),%xmm1
addsd  %xmm1,%xmm1
mulsd  0xe78(%rip),%xmm1
movapd %xmm1,(%rsp)
movsd  (%rbx),%xmm0
xorps  0xe88(%rip),%xmm0
movsd  0x8(%rbx),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
call   1030 <exp@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  0x8(%rbx),%xmm0
xorps  0xe4a(%rip),%xmm0
movapd (%rsp),%xmm1
mulsd  (%rbx),%xmm1
movapd %xmm1,(%rsp)
call   1030 <exp@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @powellgrad(double* %0, i32 %1, double* %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i8*
%9 = alloca double
%10 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store double* %2, double** %7
store i8* %3, i8** %8
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = fmul double 1.000000e+04, %13
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = load double, double* %16
%18 = call double @llvm.fmuladd.f64(double %14, double %17, double -1.000000e+00)
store double %18, double* %9
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fneg double %21
%23 = call i32 @exp(double %22)
%24 = load double*, double** %5
%25 = getelementptr inbounds double, double* %24, i64 1
%26 = load double, double* %25
%27 = fneg double %26
%28 = call i32 @exp(double %27)
%29 = add nsw i32 %23, %28
%30 = sitofp i32 %29 to double
%31 = fsub double %30, 1.000100e+00
store double %31, double* %10
%32 = load double, double* %9
%33 = fmul double 2.000000e+00, %32
%34 = fmul double %33, 1.000000e+04
%35 = load double*, double** %5
%36 = getelementptr inbounds double, double* %35, i64 1
%37 = load double, double* %36
%38 = load double*, double** %5
%39 = getelementptr inbounds double, double* %38, i64 0
%40 = load double, double* %39
%41 = fneg double %40
%42 = call i32 @exp(double %41)
%43 = mul nsw i32 2, %42
%44 = sitofp i32 %43 to double
%45 = load double, double* %10
%46 = fmul double %44, %45
%47 = fneg double %46
%48 = call double @llvm.fmuladd.f64(double %34, double %37, double %47)
%49 = load double*, double** %7
%50 = getelementptr inbounds double, double* %49, i64 0
store double %48, double* %50
%51 = load double, double* %9
%52 = fmul double 2.000000e+00, %51
%53 = fmul double %52, 1.000000e+04
%54 = load double*, double** %5
%55 = getelementptr inbounds double, double* %54, i64 0
%56 = load double, double* %55
%57 = load double*, double** %5
%58 = getelementptr inbounds double, double* %57, i64 1
%59 = load double, double* %58
%60 = fneg double %59
%61 = call i32 @exp(double %60)
%62 = mul nsw i32 2, %61
%63 = sitofp i32 %62 to double
%64 = load double, double* %10
%65 = fmul double %63, %64
%66 = fneg double %65
%67 = call double @llvm.fmuladd.f64(double %53, double %56, double %66)
%68 = load double*, double** %7
%69 = getelementptr inbounds double, double* %68, i64 1
store double %67, double* %69
ret void
}

LLVM IR (-O2):
define void @powellgrad(double* nocapture %0, i32 %1, double* nocapture writeonly %2, i8* nocapture readnone %3) {
%5 = load double, double* %0
%6 = fmul double %5, 1.000000e+04
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = tail call double @llvm.fmuladd.f64(double %6, double %8, double -1.000000e+00)
%10 = fneg double %5
%11 = tail call i32 @exp(double %10)
%12 = load double, double* %7
%13 = fneg double %12
%14 = tail call i32 @exp(double %13)
%15 = add nsw i32 %14, %11
%16 = sitofp i32 %15 to double
%17 = fadd double %16, -1.000100e+00
%18 = fmul double %9, 2.000000e+00
%19 = fmul double %18, 1.000000e+04
%20 = load double, double* %7
%21 = load double, double* %0
%22 = fneg double %21
%23 = tail call i32 @exp(double %22)
%24 = shl nsw i32 %23, 1
%25 = sitofp i32 %24 to double
%26 = fneg double %17
%27 = fmul double %26, %25
%28 = tail call double @llvm.fmuladd.f64(double %19, double %20, double %27)
store double %28, double* %2
%29 = load double, double* %0
%30 = load double, double* %7
%31 = fneg double %30
%32 = tail call i32 @exp(double %31)
%33 = shl nsw i32 %32, 1
%34 = sitofp i32 %33 to double
%35 = fmul double %26, %34
%36 = tail call double @llvm.fmuladd.f64(double %19, double %29, double %35)
%37 = getelementptr inbounds double, double* %2, i64 1
store double %36, double* %37
ret void
}