#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_axpy(int, float, float *, float *);
int /*<<< orphan*/ bcnn_scal(int, float, float *);
void bcnn_sgd_update_cpu(float *weights, float *biases, float *weights_grad,
                         float *biases_grad, int weights_size, int biases_size,
                         int batch_size, float learning_rate, float momentum,
                         float decay) {
  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_axpy(weights_size, -learning_rate / batch_size, weights_grad, weights);
    bcnn_scal(weights_size, momentum, weights_grad);
  }
  return;
}


x86 assembly (clang, -O0):
<bcnn_sgd_update_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movss  %xmm0,-0x2c(%rbp)
movss  %xmm1,-0x30(%rbp)
movss  %xmm2,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a4 <bcnn_sgd_update_cpu+0x84>
cmpq   $0x0,-0x20(%rbp)
je     11a4 <bcnn_sgd_update_cpu+0x84>
mov    -0x28(%rbp),%edi
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtsi2ssl 0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    -0x28(%rbp),%edi
movss  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
call   1040 <bcnn_scal@plt>
cmpq   $0x0,-0x8(%rbp)
je     1214 <bcnn_sgd_update_cpu+0xf4>
cmpq   $0x0,-0x18(%rbp)
je     1214 <bcnn_sgd_update_cpu+0xf4>
mov    -0x24(%rbp),%edi
movss  -0x34(%rbp),%xmm0
cvtsi2ssl 0x10(%rbp),%xmm1
mulss  %xmm1,%xmm0
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    -0x24(%rbp),%edi
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtsi2ssl 0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <bcnn_axpy@plt>
mov    -0x24(%rbp),%edi
movss  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
call   1040 <bcnn_scal@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcnn_sgd_update_cpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movss  %xmm1,0xc(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %r8d,%r14d
mov    %rdx,%r15
mov    %rdi,%rbp
mov    0x60(%rsp),%r13d
test   %rsi,%rsi
je     119a <bcnn_sgd_update_cpu+0x7a>
mov    %rcx,%rbx
test   %rcx,%rcx
je     119a <bcnn_sgd_update_cpu+0x7a>
mov    %r9d,%r12d
mov    %rsi,%rdx
movaps 0xe9f(%rip),%xmm0
xorps  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %r13d,%xmm1
divss  %xmm1,%xmm0
mov    %r9d,%edi
mov    %rbx,%rsi
movss  %xmm2,0x8(%rsp)
call   1030 <bcnn_axpy@plt>
mov    %r12d,%edi
movss  0xc(%rsp),%xmm0
mov    %rbx,%rsi
call   1040 <bcnn_scal@plt>
movss  0x8(%rsp),%xmm2
test   %rbp,%rbp
je     1206 <bcnn_sgd_update_cpu+0xe6>
test   %r15,%r15
je     1206 <bcnn_sgd_update_cpu+0xe6>
xorps  %xmm0,%xmm0
cvtsi2ss %r13d,%xmm0
movss  %xmm0,0x8(%rsp)
mulss  %xmm0,%xmm2
mov    %r14d,%edi
movaps %xmm2,%xmm0
mov    %rbp,%rsi
mov    %r15,%rdx
call   1030 <bcnn_axpy@plt>
movaps 0x10(%rsp),%xmm0
xorps  0xe2d(%rip),%xmm0
divss  0x8(%rsp),%xmm0
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <bcnn_axpy@plt>
mov    %r14d,%edi
movss  0xc(%rsp),%xmm0
mov    %r15,%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <bcnn_scal@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bcnn_sgd_update_cpu(float* %0, float* %1, float* %2, float* %3, i32 %4, i32 %5, i32 %6, float %7, float %8, float %9) {
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca float
%19 = alloca float
%20 = alloca float
store float* %0, float** %11
store float* %1, float** %12
store float* %2, float** %13
store float* %3, float** %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store float %7, float* %18
store float %8, float* %19
store float %9, float* %20
%21 = load float*, float** %12
%22 = icmp ne float* %21, null
br i1 %22, label %23, label %40
23: ; preds = %10
%24 = load float*, float** %14
%25 = icmp ne float* %24, null
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i32, i32* %16
%28 = load float, float* %18
%29 = fneg float %28
%30 = load i32, i32* %17
%31 = sitofp i32 %30 to float
%32 = fdiv float %29, %31
%33 = load float*, float** %14
%34 = load float*, float** %12
%35 = call i32 @bcnn_axpy(i32 %27, float %32, float* %33, float* %34)
%36 = load i32, i32* %16
%37 = load float, float* %19
%38 = load float*, float** %14
%39 = call i32 @bcnn_scal(i32 %36, float %37, float* %38)
br label %40
40: ; preds = %26, %23, %10
%41 = load float*, float** %11
%42 = icmp ne float* %41, null
br i1 %42, label %43, label %68
43: ; preds = %40
%44 = load float*, float** %13
%45 = icmp ne float* %44, null
br i1 %45, label %46, label %68
46: ; preds = %43
%47 = load i32, i32* %15
%48 = load float, float* %20
%49 = load i32, i32* %17
%50 = sitofp i32 %49 to float
%51 = fmul float %48, %50
%52 = load float*, float** %11
%53 = load float*, float** %13
%54 = call i32 @bcnn_axpy(i32 %47, float %51, float* %52, float* %53)
%55 = load i32, i32* %15
%56 = load float, float* %18
%57 = fneg float %56
%58 = load i32, i32* %17
%59 = sitofp i32 %58 to float
%60 = fdiv float %57, %59
%61 = load float*, float** %13
%62 = load float*, float** %11
%63 = call i32 @bcnn_axpy(i32 %55, float %60, float* %61, float* %62)
%64 = load i32, i32* %15
%65 = load float, float* %19
%66 = load float*, float** %13
%67 = call i32 @bcnn_scal(i32 %64, float %65, float* %66)
br label %68
68: ; preds = %46, %43, %40
ret void
}

LLVM IR (-O2):
define void @bcnn_sgd_update_cpu(float* %0, float* %1, float* %2, float* %3, i32 %4, i32 %5, i32 %6, float %7, float %8, float %9) {
%11 = icmp ne float* %1, null
%12 = icmp ne float* %3, null
%13 = and i1 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = fneg float %7
%16 = sitofp i32 %6 to float
%17 = fdiv float %15, %16
%18 = tail call i32 @bcnn_axpy(i32 %5, float %17, float* %3, float* %1)
%19 = tail call i32 @bcnn_scal(i32 %5, float %8, float* %3)
br label %20
20: ; preds = %14, %10
%21 = icmp ne float* %0, null
%22 = icmp ne float* %2, null
%23 = and i1 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = sitofp i32 %6 to float
%26 = fmul float %25, %9
%27 = tail call i32 @bcnn_axpy(i32 %4, float %26, float* %0, float* %2)
%28 = fneg float %7
%29 = fdiv float %28, %25
%30 = tail call i32 @bcnn_axpy(i32 %4, float %29, float* %2, float* %0)
%31 = tail call i32 @bcnn_scal(i32 %4, float %8, float* %2)
br label %32
32: ; preds = %24, %20
ret void
}