#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 */
double const sqrt(double);
void adadelta(double rho, double eps, int n, const double *g, double *x,
              double *eg, double *dx) {
  for (int i = 0; i < n; ++i) {
    eg[i] = rho * eg[i] + (1 - rho) * g[i] * g[i];
    double dxi = sqrt(dx[i] + eps) / sqrt(eg[i] + eps) * g[i];
    dx[i] = rho * dx[i] + (1 - rho) * dxi * dxi;
    x[i] -= dxi;
  }
}


x86 assembly (clang, -O0):
<adadelta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124e <adadelta+0x13e>
movsd  -0x8(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  0xe9e(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  0xdff(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    113c <adadelta+0x2c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adadelta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edi,%edi
jle    123f <adadelta+0x12f>
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
movapd %xmm0,%xmm3
movsd  0xec2(%rip),%xmm4
subsd  %xmm0,%xmm4
mov    %edi,%r13d
xor    %ebp,%ebp
xorpd  %xmm5,%xmm5
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm4,0x8(%rsp)
jmp    11ca <adadelta+0xba>
nop
movsd  %xmm6,0x20(%rsp)
call   1030 <sqrt@plt>
movsd  0x20(%rsp),%xmm6
xorpd  %xmm5,%xmm5
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
divsd  %xmm0,%xmm6
mulsd  (%r12,%rbp,8),%xmm6
movapd %xmm4,%xmm0
mulsd  %xmm6,%xmm0
mulsd  %xmm6,%xmm0
movsd  (%r14,%rbp,8),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r14,%rbp,8)
movsd  (%r15,%rbp,8),%xmm0
subsd  %xmm6,%xmm0
movsd  %xmm0,(%r15,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
je     123f <adadelta+0x12f>
movsd  (%r12,%rbp,8),%xmm0
movapd %xmm4,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movsd  (%rbx,%rbp,8),%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
movsd  (%r14,%rbp,8),%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm5,%xmm0
jb     1210 <adadelta+0x100>
xorps  %xmm6,%xmm6
sqrtsd %xmm0,%xmm6
jmp    1223 <adadelta+0x113>
nopw   0x0(%rax,%rax,1)
call   1030 <sqrt@plt>
xorpd  %xmm5,%xmm5
movsd  0x18(%rsp),%xmm1
movapd %xmm0,%xmm6
movsd  (%rbx,%rbp,8),%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm5,%xmm0
jb     1160 <adadelta+0x50>
sqrtsd %xmm0,%xmm0
jmp    117b <adadelta+0x6b>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @adadelta(double %0, double %1, i32 %2, double* %3, double* %4, double* %5, double* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca double
store double %0, double* %8
store double %1, double* %9
store i32 %2, i32* %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
store double* %6, double** %14
store i32 0, i32* %15
br label %17
17: ; preds = %94, %7
%18 = load i32, i32* %15
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %97
21: ; preds = %17
%22 = load double, double* %8
%23 = load double*, double** %13
%24 = load i32, i32* %15
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %8
%29 = fsub double 1.000000e+00, %28
%30 = load double*, double** %11
%31 = load i32, i32* %15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fmul double %29, %34
%36 = load double*, double** %11
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = fmul double %35, %40
%42 = call double @llvm.fmuladd.f64(double %22, double %27, double %41)
%43 = load double*, double** %13
%44 = load i32, i32* %15
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
%47 = load double*, double** %14
%48 = load i32, i32* %15
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = load double, double* %9
%53 = fadd double %51, %52
%54 = call double @sqrt(double %53)
%55 = load double*, double** %13
%56 = load i32, i32* %15
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double, double* %9
%61 = fadd double %59, %60
%62 = call double @sqrt(double %61)
%63 = fdiv double %54, %62
%64 = load double*, double** %11
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = fmul double %63, %68
store double %69, double* %16
%70 = load double, double* %8
%71 = load double*, double** %14
%72 = load i32, i32* %15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = load double, double* %8
%77 = fsub double 1.000000e+00, %76
%78 = load double, double* %16
%79 = fmul double %77, %78
%80 = load double, double* %16
%81 = fmul double %79, %80
%82 = call double @llvm.fmuladd.f64(double %70, double %75, double %81)
%83 = load double*, double** %14
%84 = load i32, i32* %15
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
store double %82, double* %86
%87 = load double, double* %16
%88 = load double*, double** %12
%89 = load i32, i32* %15
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = fsub double %92, %87
store double %93, double* %91
br label %94
94: ; preds = %21
%95 = load i32, i32* %15
%96 = add nsw i32 %95, 1
store i32 %96, i32* %15
br label %17
97: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @adadelta(double %0, double %1, i32 %2, double* nocapture %3, double* nocapture %4, double* nocapture %5, double* nocapture %6) {
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = fsub double 1.000000e+00, %0
%11 = zext i32 %2 to i64
br label %13
12: ; preds = %13, %7
ret void
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %39, %13 ]
%15 = getelementptr inbounds double, double* %5, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %3, i64 %14
%18 = load double, double* %17
%19 = fmul double %10, %18
%20 = fmul double %18, %19
%21 = tail call double @llvm.fmuladd.f64(double %0, double %16, double %20)
store double %21, double* %15
%22 = getelementptr inbounds double, double* %6, i64 %14
%23 = load double, double* %22
%24 = fadd double %23, %1
%25 = tail call double @sqrt(double %24)
%26 = load double, double* %15
%27 = fadd double %26, %1
%28 = tail call double @sqrt(double %27)
%29 = fdiv double %25, %28
%30 = load double, double* %17
%31 = fmul double %29, %30
%32 = load double, double* %22
%33 = fmul double %10, %31
%34 = fmul double %31, %33
%35 = tail call double @llvm.fmuladd.f64(double %0, double %32, double %34)
store double %35, double* %22
%36 = getelementptr inbounds double, double* %4, i64 %14
%37 = load double, double* %36
%38 = fsub double %37, %31
store double %38, double* %36
%39 = add nuw nsw i64 %14, 1
%40 = icmp eq i64 %39, %11
br i1 %40, label %12, label %13
}