#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 fabs(double);
double delayed_functional_control(int *sources, int *targets, int *function,
                                  const int num_links, double *expression,
                                  double *delta_expression) {
  double sum = 0.0;
  int i = 0;
  for (i = 0; i < num_links; ++i) {
    if (function[i] == 1) {
      sum += 1.0 - fabs(expression[sources[i]] - delta_expression[targets[i]]);
    } else if (function[i] == -1) {
      sum += fabs(expression[sources[i]] - delta_expression[targets[i]]);
    }
  }
  return sum / (double)num_links;
}


x86 assembly (clang, -O0):
<delayed_functional_control>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1208 <delayed_functional_control+0x108>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    119f <delayed_functional_control+0x9f>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
subsd  (%rax,%rcx,8),%xmm1
movaps 0xe80(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe84(%rip),%xmm0
subsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11f5 <delayed_functional_control+0xf5>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
jne    11f0 <delayed_functional_control+0xf0>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe1e(%rip),%xmm1
pand   %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11f5 <delayed_functional_control+0xf5>
jmp    11fa <delayed_functional_control+0xfa>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1131 <delayed_functional_control+0x31>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<delayed_functional_control>:
push   %rbx
test   %ecx,%ecx
jle    117b <delayed_functional_control+0x7b>
mov    %ecx,%r10d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movapd 0xeea(%rip),%xmm1
movsd  0xef2(%rip),%xmm2
jmp    1145 <delayed_functional_control+0x45>
movslq (%rdi,%rbx,4),%rax
movsd  (%r8,%rax,8),%xmm3
movslq (%rsi,%rbx,4),%rax
subsd  (%r9,%rax,8),%xmm3
andpd  %xmm1,%xmm3
addsd  %xmm3,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r10
je     117f <delayed_functional_control+0x7f>
mov    (%rdx,%rbx,4),%r11d
cmp    $0xffffffff,%r11d
je     1120 <delayed_functional_control+0x20>
cmp    $0x1,%r11d
jne    113c <delayed_functional_control+0x3c>
movslq (%rdi,%rbx,4),%rax
movsd  (%r8,%rax,8),%xmm3
movslq (%rsi,%rbx,4),%rax
subsd  (%r9,%rax,8),%xmm3
andpd  %xmm1,%xmm3
movapd %xmm2,%xmm4
subsd  %xmm3,%xmm4
addsd  %xmm4,%xmm0
jmp    113c <delayed_functional_control+0x3c>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
divsd  %xmm1,%xmm0
pop    %rbx
ret

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

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