#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 calcEnergy(int const, double *, double const **);
int /*<<< orphan*/ calcOutputPattern(int const, double const **, double *,
                                     double *);
int /*<<< orphan*/ copyPattern(int const, double const *, double *);
int /*<<< orphan*/ equals(double, double);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ showPatternAndDifference(double const *, double *);
void showAssociatedPattern(const int patternSize, const double W[][1000],
                           const double inputPattern[],
                           const double inputPatternWithNoise[],
                           double associatedPattern[]) {
  double patternWithNoise[patternSize];
  copyPattern(patternSize, inputPatternWithNoise, patternWithNoise);
  double energy = 0.0;
  double energyPrevious = 0.0;
  showPatternAndDifference(inputPattern, patternWithNoise);
  energy = calcEnergy(patternSize, patternWithNoise, W);
  printf("\n    Energy = %9.4f\n\n", energy);
  do {
    energyPrevious = energy;
    calcOutputPattern(patternSize, W, patternWithNoise, associatedPattern);
    energy = calcEnergy(patternSize, associatedPattern, W);
    copyPattern(patternSize, associatedPattern, patternWithNoise);
    showPatternAndDifference(inputPattern, associatedPattern);
    printf("\n    Energy = %9.4f\n\n", energy);
  } while (!equals(energyPrevious, energy));
}


x86 assembly (clang, -O0):
<showAssociatedPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <copyPattern@plt>
mov    -0x50(%rbp),%rsi
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <showPatternAndDifference@plt>
mov    -0x50(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rdx
call   1040 <calcEnergy@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xe14(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdx
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rcx
call   1030 <calcOutputPattern@plt>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <calcEnergy@plt>
mov    -0x50(%rbp),%rdx
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <copyPattern@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <showPatternAndDifference@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1080 <equals@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f1 <showAssociatedPattern+0x91>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showAssociatedPattern>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
mov    %edi,%eax
mov    %rsp,%r13
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rcx,%rsi
mov    %r13,%rdx
call   1070 <copyPattern@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <showPatternAndDifference@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1040 <calcEnergy@plt>
lea    0xe41(%rip),%rdi
movsd  %xmm0,-0x38(%rbp)
call   1060 <printf@plt>
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1030 <calcOutputPattern@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <calcEnergy@plt>
movsd  %xmm0,-0x30(%rbp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1070 <copyPattern@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <showPatternAndDifference@plt>
lea    0xdec(%rip),%rdi
movsd  -0x30(%rbp),%xmm0
call   1060 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1080 <equals@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
test   %eax,%eax
je     11d0 <showAssociatedPattern+0x70>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0A Energy = %9.4f\0A\0A\00"
define void @showAssociatedPattern(i32 %0, [1000 x double]* %1, double* %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca [1000 x double]*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %6
store [1000 x double]* %1, [1000 x double]** %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca double, i64 %16
store i64 %16, i64* %12
%19 = load i32, i32* %6
%20 = load double*, double** %9
%21 = call i32 @copyPattern(i32 %19, double* %20, double* %18)
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%22 = load double*, double** %8
%23 = call i32 @showPatternAndDifference(double* %22, double* %18)
%24 = load i32, i32* %6
%25 = load [1000 x double]*, [1000 x double]** %7
%26 = bitcast [1000 x double]* %25 to double**
%27 = call double @calcEnergy(i32 %24, double* %18, double** %26)
store double %27, double* %13
%28 = load double, double* %13
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %28)
br label %30
30: ; preds = %50, %5
%31 = load double, double* %13
store double %31, double* %14
%32 = load i32, i32* %6
%33 = load [1000 x double]*, [1000 x double]** %7
%34 = bitcast [1000 x double]* %33 to double**
%35 = load double*, double** %10
%36 = call i32 @calcOutputPattern(i32 %32, double** %34, double* %18, double* %35)
%37 = load i32, i32* %6
%38 = load double*, double** %10
%39 = load [1000 x double]*, [1000 x double]** %7
%40 = bitcast [1000 x double]* %39 to double**
%41 = call double @calcEnergy(i32 %37, double* %38, double** %40)
store double %41, double* %13
%42 = load i32, i32* %6
%43 = load double*, double** %10
%44 = call i32 @copyPattern(i32 %42, double* %43, double* %18)
%45 = load double*, double** %8
%46 = load double*, double** %10
%47 = call i32 @showPatternAndDifference(double* %45, double* %46)
%48 = load double, double* %13
%49 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %48)
br label %50
50: ; preds = %30
%51 = load double, double* %14
%52 = load double, double* %13
%53 = call i32 @equals(double %51, double %52)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
br i1 %55, label %30, label %56
56: ; preds = %50
%57 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0A Energy = %9.4f\0A\0A\00"
define void @showAssociatedPattern(i32 %0, [1000 x double]* %1, double* %2, double* %3, double* %4) {
%6 = zext i32 %0 to i64
%7 = alloca double, i64 %6
%8 = call i32 @copyPattern(i32 %0, double* %3, double* %7)
%9 = call i32 @showPatternAndDifference(double* %2, double* %7)
%10 = bitcast [1000 x double]* %1 to double**
%11 = call double @calcEnergy(i32 %0, double* %7, double** %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %11)
br label %13
13: ; preds = %13, %5
%14 = phi double [ %11, %5 ], [ %16, %13 ]
%15 = call i32 @calcOutputPattern(i32 %0, double** %10, double* %7, double* %4)
%16 = call double @calcEnergy(i32 %0, double* %4, double** %10)
%17 = call i32 @copyPattern(i32 %0, double* %4, double* %7)
%18 = call i32 @showPatternAndDifference(double* %2, double* %4)
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %16)
%20 = call i32 @equals(double %14, double %16)
%21 = icmp eq i32 %20, 0
br i1 %21, label %13, label %22
22: ; preds = %13
ret void
}