#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 exp(double);
void soft_max(double net_outputs[3], double activations[3]) {
  int i;
  double sum;
  sum = (double)0.0;
  for (i = 0; i < 3; i++) {
    sum += exp(-activations[i]);
  }
  for (i = 0; i < 3; i++) {
    net_outputs[i] = exp(-activations[i]) / sum;
  }
}


x86 assembly (clang, -O0):
<soft_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    117a <soft_max+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <soft_max+0x1f>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11d4 <soft_max+0xc4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
divsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <soft_max+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soft_max>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  (%rsi),%xmm0
xorpd  0xeda(%rip),%xmm0
call   1030 <exp@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rbx),%xmm0
xorpd  0xebb(%rip),%xmm0
call   1030 <exp@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rbx),%xmm0
xorpd  0xe9f(%rip),%xmm0
call   1030 <exp@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rbx),%xmm0
xorpd  0xe84(%rip),%xmm0
call   1030 <exp@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%rbx),%xmm0
xorpd  0xe68(%rip),%xmm0
call   1030 <exp@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%r14)
movsd  0x10(%rbx),%xmm0
xorpd  0xe4b(%rip),%xmm0
call   1030 <exp@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @soft_max(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %7
7: ; preds = %20, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load double*, double** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
%16 = fneg double %15
%17 = call double @exp(double %16)
%18 = load double, double* %6
%19 = fadd double %18, %17
store double %19, double* %6
br label %20
20: ; preds = %10
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %7
store i32 0, i32* %5
br label %24
24: ; preds = %41, %23
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = load double*, double** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fneg double %32
%34 = call double @exp(double %33)
%35 = load double, double* %6
%36 = fdiv double %34, %35
%37 = load double*, double** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
store double %36, double* %40
br label %41
41: ; preds = %27
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %24
44: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @soft_max(double* nocapture writeonly %0, double* nocapture %1) {
%3 = load double, double* %1
%4 = fneg double %3
%5 = tail call double @exp(double %4)
%6 = fadd double %5, 0.000000e+00
%7 = getelementptr inbounds double, double* %1, i64 1
%8 = load double, double* %7
%9 = fneg double %8
%10 = tail call double @exp(double %9)
%11 = fadd double %6, %10
%12 = getelementptr inbounds double, double* %1, i64 2
%13 = load double, double* %12
%14 = fneg double %13
%15 = tail call double @exp(double %14)
%16 = fadd double %11, %15
%17 = load double, double* %1
%18 = fneg double %17
%19 = tail call double @exp(double %18)
%20 = fdiv double %19, %16
store double %20, double* %0
%21 = load double, double* %7
%22 = fneg double %21
%23 = tail call double @exp(double %22)
%24 = fdiv double %23, %16
%25 = getelementptr inbounds double, double* %0, i64 1
store double %24, double* %25
%26 = load double, double* %12
%27 = fneg double %26
%28 = tail call double @exp(double %27)
%29 = fdiv double %28, %16
%30 = getelementptr inbounds double, double* %0, i64 2
store double %29, double* %30
ret void
}