#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 /*<<< orphan*/ bcnn_add_scalar(int, float, float *);
int /*<<< orphan*/ bcnn_axpby(int, float, float *, float, float *);
int /*<<< orphan*/ bcnn_axpy(int, float, float *, float *);
int /*<<< orphan*/ bcnn_pow(int, float *, float, float *);
int /*<<< orphan*/ bcnn_scal(int, float, float *);
int /*<<< orphan*/ bcnn_vdiv(int, float *, float *, float *);
int /*<<< orphan*/ bcnn_vmul(int, float *, float *, float *);
int /*<<< orphan*/ memset(float *, int /*<<< orphan*/, int);
float powf(float, float);
float sqrtf(float);
void bcnn_adam_update_cpu(float *weights, float *biases, float *weights_grad,
                          float *biases_grad, float *adam_m, float *adam_v,
                          int weights_size, int biases_size, int batch_size,
                          int iter, float beta1, float beta2,
                          float learning_rate, float momentum, float decay) {
  float mu_correction = sqrtf(1.0f - powf(beta2, (float)iter + 1)) /
                        (1.0f - powf(beta1, (float)iter + 1));
  if (biases && biases_grad) {
    bcnn_axpy(biases_size, -learning_rate / batch_size, biases_grad, biases);
    bcnn_scal(biases_size, momentum, biases_grad);
  }
  if (weights && weights_grad) {
    bcnn_axpy(weights_size, decay * batch_size, weights, weights_grad);
    bcnn_axpby(weights_size, 1.0f - beta1, weights_grad, beta1, adam_m);
    bcnn_vmul(weights_size, weights_grad, weights_grad, weights_grad);
    bcnn_axpby(weights_size, 1.0f - beta2, weights_grad, beta2, adam_v);
    bcnn_pow(weights_size, adam_v, 0.5f, weights_grad);
    bcnn_add_scalar(weights_size, 0.0000001f, weights_grad);
    bcnn_vdiv(weights_size, adam_m, weights_grad, weights_grad);
    bcnn_axpy(weights_size, -learning_rate / batch_size * mu_correction,
              weights_grad, weights);
    memset(weights_grad, 0, weights_size * sizeof(float));
  }
  return;
}


x86 assembly (clang, -O0):
<bcnn_adam_update_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movss  %xmm0,-0x34(%rbp)
movss  %xmm1,-0x38(%rbp)
movss  %xmm2,-0x3c(%rbp)
movss  %xmm3,-0x40(%rbp)
movss  %xmm4,-0x44(%rbp)
movss  -0x38(%rbp),%xmm0
cvtsi2ssl 0x28(%rbp),%xmm1
movss  0xe09(%rip),%xmm2
addss  %xmm2,%xmm1
call   1040 <powf@plt>
movaps %xmm0,%xmm1
movss  0xdf5(%rip),%xmm0
subss  %xmm1,%xmm0
call   1080 <sqrtf@plt>
movss  %xmm0,-0x4c(%rbp)
movss  -0x34(%rbp),%xmm0
cvtsi2ssl 0x28(%rbp),%xmm1
movss  0xdd5(%rip),%xmm2
addss  %xmm2,%xmm1
call   1040 <powf@plt>
movaps %xmm0,%xmm2
movss  -0x4c(%rbp),%xmm0
movss  0xdbc(%rip),%xmm1
subss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12a3 <bcnn_adam_update_cpu+0x103>
cmpq   $0x0,-0x20(%rbp)
je     12a3 <bcnn_adam_update_cpu+0x103>
mov    0x18(%rbp),%edi
movss  -0x3c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtsi2ssl 0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    0x18(%rbp),%edi
movss  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
call   1090 <bcnn_scal@plt>
cmpq   $0x0,-0x8(%rbp)
je     13b4 <bcnn_adam_update_cpu+0x214>
cmpq   $0x0,-0x18(%rbp)
je     13b4 <bcnn_adam_update_cpu+0x214>
mov    0x10(%rbp),%edi
movss  -0x44(%rbp),%xmm0
cvtsi2ssl 0x20(%rbp),%xmm1
mulss  %xmm1,%xmm0
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    0x10(%rbp),%edi
movss  0xd1e(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
movss  -0x34(%rbp),%xmm1
mov    -0x28(%rbp),%rdx
call   10b0 <bcnn_axpby@plt>
mov    0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   10a0 <bcnn_vmul@plt>
mov    0x10(%rbp),%edi
movss  0xce8(%rip),%xmm0
subss  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
movss  -0x38(%rbp),%xmm1
mov    -0x30(%rbp),%rdx
call   10b0 <bcnn_axpby@plt>
mov    0x10(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movss  0xcc6(%rip),%xmm0
call   10c0 <bcnn_pow@plt>
mov    0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
movss  0xcae(%rip),%xmm0
call   1060 <bcnn_add_scalar@plt>
mov    0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1070 <bcnn_vdiv@plt>
mov    0x10(%rbp),%edi
movss  -0x3c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtsi2ssl 0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
mulss  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    -0x18(%rbp),%rdi
movslq 0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcnn_adam_update_cpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movss  %xmm4,0x18(%rsp)
movss  %xmm3,0x14(%rsp)
movaps %xmm2,0x30(%rsp)
movaps %xmm1,%xmm2
movss  %xmm0,0x10(%rsp)
mov    %r9,0x20(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    0x90(%rsp),%eax
mov    %eax,0x4(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ssl 0x98(%rsp),%xmm1
mov    0x88(%rsp),%r12d
mov    0x80(%rsp),%r14d
addss  0xdf3(%rip),%xmm1
movss  %xmm2,0x1c(%rsp)
movaps %xmm2,%xmm0
movss  %xmm1,0xc(%rsp)
call   1040 <powf@plt>
movaps %xmm0,%xmm1
movss  0xdd4(%rip),%xmm0
subss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     123e <bcnn_adam_update_cpu+0x9e>
sqrtss %xmm0,%xmm0
jmp    1243 <bcnn_adam_update_cpu+0xa3>
call   1080 <sqrtf@plt>
movss  %xmm0,0x8(%rsp)
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1040 <powf@plt>
movaps %xmm0,%xmm1
test   %r15,%r15
je     12ab <bcnn_adam_update_cpu+0x10b>
test   %r13,%r13
je     12ab <bcnn_adam_update_cpu+0x10b>
movaps 0xda2(%rip),%xmm0
xorps  0x30(%rsp),%xmm0
movss  %xmm1,0xc(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ssl 0x4(%rsp),%xmm1
divss  %xmm1,%xmm0
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <bcnn_axpy@plt>
mov    %r12d,%edi
movss  0x14(%rsp),%xmm0
mov    %r13,%rsi
call   1090 <bcnn_scal@plt>
movss  0xc(%rsp),%xmm1
test   %rbp,%rbp
je     13dd <bcnn_adam_update_cpu+0x23d>
test   %rbx,%rbx
je     13dd <bcnn_adam_update_cpu+0x23d>
mov    %rbp,%r15
movss  0xd38(%rip),%xmm0
subss  %xmm1,%xmm0
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ssl 0x4(%rsp),%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x18(%rsp),%xmm0
mulss  %xmm1,%xmm0
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <bcnn_axpy@plt>
movss  0xcf5(%rip),%xmm0
movss  0x10(%rsp),%xmm1
subss  %xmm1,%xmm0
mov    %r14d,%edi
mov    %rbx,%rsi
mov    0x28(%rsp),%r12
mov    %r12,%rdx
call   10b0 <bcnn_axpby@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
call   10a0 <bcnn_vmul@plt>
movss  0x1c(%rsp),%xmm1
movss  0xcb9(%rip),%xmm0
subss  %xmm1,%xmm0
mov    %r14d,%edi
mov    %rbx,%rsi
mov    0x20(%rsp),%rbp
mov    %rbp,%rdx
call   10b0 <bcnn_axpby@plt>
movss  0xc9e(%rip),%xmm0
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10c0 <bcnn_pow@plt>
movss  0xc8c(%rip),%xmm0
mov    %r14d,%edi
mov    %rbx,%rsi
call   1060 <bcnn_add_scalar@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
call   1070 <bcnn_vdiv@plt>
movaps 0x30(%rsp),%xmm0
xorps  0xc6c(%rip),%xmm0
divss  0x4(%rsp),%xmm0
mulss  0x8(%rsp),%xmm0
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <bcnn_axpy@plt>
shl    $0x2,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <memset@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bcnn_adam_update_cpu(float* %0, float* %1, float* %2, float* %3, float* %4, float* %5, i32 %6, i32 %7, i32 %8, i32 %9, float %10, float %11, float %12, float %13, float %14) {
%16 = alloca float*
%17 = alloca float*
%18 = alloca float*
%19 = alloca float*
%20 = alloca float*
%21 = alloca float*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca float
%27 = alloca float
%28 = alloca float
%29 = alloca float
%30 = alloca float
%31 = alloca float
store float* %0, float** %16
store float* %1, float** %17
store float* %2, float** %18
store float* %3, float** %19
store float* %4, float** %20
store float* %5, float** %21
store i32 %6, i32* %22
store i32 %7, i32* %23
store i32 %8, i32* %24
store i32 %9, i32* %25
store float %10, float* %26
store float %11, float* %27
store float %12, float* %28
store float %13, float* %29
store float %14, float* %30
%32 = load float, float* %27
%33 = load i32, i32* %25
%34 = sitofp i32 %33 to float
%35 = fadd float %34, 1.000000e+00
%36 = call float @powf(float %32, float %35)
%37 = fsub float 1.000000e+00, %36
%38 = call float @sqrtf(float %37)
%39 = load float, float* %26
%40 = load i32, i32* %25
%41 = sitofp i32 %40 to float
%42 = fadd float %41, 1.000000e+00
%43 = call float @powf(float %39, float %42)
%44 = fsub float 1.000000e+00, %43
%45 = fdiv float %38, %44
store float %45, float* %31
%46 = load float*, float** %17
%47 = icmp ne float* %46, null
br i1 %47, label %48, label %65
48: ; preds = %15
%49 = load float*, float** %19
%50 = icmp ne float* %49, null
br i1 %50, label %51, label %65
51: ; preds = %48
%52 = load i32, i32* %23
%53 = load float, float* %28
%54 = fneg float %53
%55 = load i32, i32* %24
%56 = sitofp i32 %55 to float
%57 = fdiv float %54, %56
%58 = load float*, float** %19
%59 = load float*, float** %17
%60 = call i32 @bcnn_axpy(i32 %52, float %57, float* %58, float* %59)
%61 = load i32, i32* %23
%62 = load float, float* %29
%63 = load float*, float** %19
%64 = call i32 @bcnn_scal(i32 %61, float %62, float* %63)
br label %65
65: ; preds = %51, %48, %15
%66 = load float*, float** %16
%67 = icmp ne float* %66, null
br i1 %67, label %68, label %128
68: ; preds = %65
%69 = load float*, float** %18
%70 = icmp ne float* %69, null
br i1 %70, label %71, label %128
71: ; preds = %68
%72 = load i32, i32* %22
%73 = load float, float* %30
%74 = load i32, i32* %24
%75 = sitofp i32 %74 to float
%76 = fmul float %73, %75
%77 = load float*, float** %16
%78 = load float*, float** %18
%79 = call i32 @bcnn_axpy(i32 %72, float %76, float* %77, float* %78)
%80 = load i32, i32* %22
%81 = load float, float* %26
%82 = fsub float 1.000000e+00, %81
%83 = load float*, float** %18
%84 = load float, float* %26
%85 = load float*, float** %20
%86 = call i32 @bcnn_axpby(i32 %80, float %82, float* %83, float %84, float* %85)
%87 = load i32, i32* %22
%88 = load float*, float** %18
%89 = load float*, float** %18
%90 = load float*, float** %18
%91 = call i32 @bcnn_vmul(i32 %87, float* %88, float* %89, float* %90)
%92 = load i32, i32* %22
%93 = load float, float* %27
%94 = fsub float 1.000000e+00, %93
%95 = load float*, float** %18
%96 = load float, float* %27
%97 = load float*, float** %21
%98 = call i32 @bcnn_axpby(i32 %92, float %94, float* %95, float %96, float* %97)
%99 = load i32, i32* %22
%100 = load float*, float** %21
%101 = load float*, float** %18
%102 = call i32 @bcnn_pow(i32 %99, float* %100, float 5.000000e-01, float* %101)
%103 = load i32, i32* %22
%104 = load float*, float** %18
%105 = call i32 @bcnn_add_scalar(i32 %103, float 0x3E7AD7F2A0000000, float* %104)
%106 = load i32, i32* %22
%107 = load float*, float** %20
%108 = load float*, float** %18
%109 = load float*, float** %18
%110 = call i32 @bcnn_vdiv(i32 %106, float* %107, float* %108, float* %109)
%111 = load i32, i32* %22
%112 = load float, float* %28
%113 = fneg float %112
%114 = load i32, i32* %24
%115 = sitofp i32 %114 to float
%116 = fdiv float %113, %115
%117 = load float, float* %31
%118 = fmul float %116, %117
%119 = load float*, float** %18
%120 = load float*, float** %16
%121 = call i32 @bcnn_axpy(i32 %111, float %118, float* %119, float* %120)
%122 = load float*, float** %18
%123 = load i32, i32* %22
%124 = sext i32 %123 to i64
%125 = mul i64 %124, 4
%126 = trunc i64 %125 to i32
%127 = call i32 @memset(float* %122, i32 0, i32 %126)
br label %128
128: ; preds = %71, %68, %65
ret void
}

LLVM IR (-O2):
define void @bcnn_adam_update_cpu(float* %0, float* %1, float* %2, float* %3, float* %4, float* %5, i32 %6, i32 %7, i32 %8, i32 %9, float %10, float %11, float %12, float %13, float %14) {
%16 = sitofp i32 %9 to float
%17 = fadd float %16, 1.000000e+00
%18 = tail call float @powf(float %11, float %17)
%19 = fsub float 1.000000e+00, %18
%20 = tail call float @sqrtf(float %19)
%21 = tail call float @powf(float %10, float %17)
%22 = fsub float 1.000000e+00, %21
%23 = fdiv float %20, %22
%24 = icmp ne float* %1, null
%25 = icmp ne float* %3, null
%26 = and i1 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %15
%28 = fneg float %12
%29 = sitofp i32 %8 to float
%30 = fdiv float %28, %29
%31 = tail call i32 @bcnn_axpy(i32 %7, float %30, float* %3, float* %1)
%32 = tail call i32 @bcnn_scal(i32 %7, float %13, float* %3)
br label %33
33: ; preds = %27, %15
%34 = icmp ne float* %0, null
%35 = icmp ne float* %2, null
%36 = and i1 %34, %35
br i1 %36, label %37, label %55
37: ; preds = %33
%38 = sitofp i32 %8 to float
%39 = fmul float %38, %14
%40 = tail call i32 @bcnn_axpy(i32 %6, float %39, float* %0, float* %2)
%41 = fsub float 1.000000e+00, %10
%42 = tail call i32 @bcnn_axpby(i32 %6, float %41, float* %2, float %10, float* %4)
%43 = tail call i32 @bcnn_vmul(i32 %6, float* %2, float* %2, float* %2)
%44 = fsub float 1.000000e+00, %11
%45 = tail call i32 @bcnn_axpby(i32 %6, float %44, float* %2, float %11, float* %5)
%46 = tail call i32 @bcnn_pow(i32 %6, float* %5, float 5.000000e-01, float* %2)
%47 = tail call i32 @bcnn_add_scalar(i32 %6, float 0x3E7AD7F2A0000000, float* %2)
%48 = tail call i32 @bcnn_vdiv(i32 %6, float* %4, float* %2, float* %2)
%49 = fneg float %12
%50 = fdiv float %49, %38
%51 = fmul float %50, %23
%52 = tail call i32 @bcnn_axpy(i32 %6, float %51, float* %2, float* %0)
%53 = shl i32 %6, 2
%54 = tail call i32 @memset(float* %2, i32 0, i32 %53)
br label %55
55: ; preds = %37, %33
ret void
}