#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double CalculateEnergyFunction(int **, int *);
int /*<<< orphan*/ DisplayPattern(int *);
int /*<<< orphan*/ GeneratePattern(int **);
int /*<<< orphan*/ SetInitialState(int **, int *);
int /*<<< orphan*/ SetWeightValue(int **, int **);
int /*<<< orphan*/ UpdateState(int **, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int pattern[3][100];
  int state[100];
  int w[100][100];
  double energy;
  FILE *fp;
  int iteration;
  GeneratePattern(pattern);
  SetWeightValue(pattern, w);
  srand((unsigned int)time(NULL));
  SetInitialState(pattern, state);
  DisplayPattern(state);
  fp = fopen("energy.dat", "w");
  for (iteration = 0; iteration < 1e4; iteration++) {
    UpdateState(w, state);
    energy = CalculateEnergyFunction(w, state);
    fprintf(fp, "%10d %15.6e\n", iteration, energy);
  }
  fclose(fp);
  DisplayPattern(state);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa2b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x4c0(%rbp),%rdi
call   1050 <GeneratePattern@plt>
lea    -0x4c0(%rbp),%rdi
lea    -0xa290(%rbp),%rsi
call   1060 <SetWeightValue@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    -0x4c0(%rbp),%rdi
lea    -0x650(%rbp),%rsi
call   1030 <SetInitialState@plt>
lea    -0x650(%rbp),%rdi
call   10d0 <DisplayPattern@plt>
lea    0xdf1(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xa2a0(%rbp)
movl   $0x0,-0xa2a4(%rbp)
cvtsi2sdl -0xa2a4(%rbp),%xmm1
ff
movsd  0xdbc(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12b1 <main+0x101>
lea    -0xa290(%rbp),%rdi
lea    -0x650(%rbp),%rsi
call   1040 <UpdateState@plt>
lea    -0xa290(%rbp),%rdi
lea    -0x650(%rbp),%rsi
call   10c0 <CalculateEnergyFunction@plt>
movsd  %xmm0,-0xa298(%rbp)
ff
mov    -0xa2a0(%rbp),%rdi
mov    -0xa2a4(%rbp),%edx
movsd  -0xa298(%rbp),%xmm0
ff
lea    0xd7d(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0xa2a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa2a4(%rbp)
jmp    1234 <main+0x84>
mov    -0xa2a0(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0x650(%rbp),%rdi
call   10d0 <DisplayPattern@plt>
xor    %eax,%eax
add    $0xa2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa280,%rsp
lea    0x190(%rsp),%r12
mov    %r12,%rdi
call   1050 <GeneratePattern@plt>
lea    0x640(%rsp),%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <SetWeightValue@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    %rsp,%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <SetInitialState@plt>
mov    %r15,%rdi
call   10d0 <DisplayPattern@plt>
lea    0xdf0(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
lea    0xde7(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <UpdateState@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10c0 <CalculateEnergyFunction@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
add    $0x1,%ebx
cmp    $0x2710,%ebx
jne    1230 <main+0x80>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %rsp,%rdi
call   10d0 <DisplayPattern@plt>
xor    %eax,%eax
add    $0xa280,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"energy.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"%10d %15.6e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [100 x i32]]
%3 = alloca [100 x i32]
%4 = alloca [100 x [100 x i32]]
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = getelementptr inbounds [3 x [100 x i32]], [3 x [100 x i32]]* %2, i64 0, i64 0
%9 = bitcast [100 x i32]* %8 to i32**
%10 = call i32 @GeneratePattern(i32** %9)
%11 = getelementptr inbounds [3 x [100 x i32]], [3 x [100 x i32]]* %2, i64 0, i64 0
%12 = bitcast [100 x i32]* %11 to i32**
%13 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %4, i64 0, i64 0
%14 = bitcast [100 x i32]* %13 to i32**
%15 = call i32 @SetWeightValue(i32** %12, i32** %14)
%16 = call i64 @time(i32* null)
%17 = trunc i64 %16 to i32
%18 = call i32 @srand(i32 %17)
%19 = getelementptr inbounds [3 x [100 x i32]], [3 x [100 x i32]]* %2, i64 0, i64 0
%20 = bitcast [100 x i32]* %19 to i32**
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%22 = call i32 @SetInitialState(i32** %20, i32* %21)
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%24 = call i32 @DisplayPattern(i32* %23)
%25 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
store i32 0, i32* %7
br label %26
26: ; preds = %43, %0
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = fcmp olt double %28, 1.000000e+04
br i1 %29, label %30, label %46
30: ; preds = %26
%31 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %4, i64 0, i64 0
%32 = bitcast [100 x i32]* %31 to i32**
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%34 = call i32 @UpdateState(i32** %32, i32* %33)
%35 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %4, i64 0, i64 0
%36 = bitcast [100 x i32]* %35 to i32**
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%38 = call double @CalculateEnergyFunction(i32** %36, i32* %37)
store double %38, double* %5
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = load double, double* %5
%42 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %40, double %41)
br label %43
43: ; preds = %30
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %26
46: ; preds = %26
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
%49 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%50 = call i32 @DisplayPattern(i32* %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"energy.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"%10d %15.6e\0A\00"
define i32 @main() {
%1 = alloca [3 x [100 x i32]]
%2 = alloca [100 x i32]
%3 = alloca [100 x [100 x i32]]
%4 = bitcast [3 x [100 x i32]]* %1 to i8*
%5 = bitcast [100 x i32]* %2 to i8*
%6 = bitcast [100 x [100 x i32]]* %3 to i8*
%7 = bitcast [3 x [100 x i32]]* %1 to i32**
%8 = call i32 @GeneratePattern(i32** %7)
%9 = bitcast [100 x [100 x i32]]* %3 to i32**
%10 = call i32 @SetWeightValue(i32** %7, i32** %9)
%11 = call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%15 = call i32 @SetInitialState(i32** %7, i32* %14)
%16 = call i32 @DisplayPattern(i32* %14)
%17 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %0, %18
%19 = phi i32 [ 0, %0 ], [ %23, %18 ]
%20 = call i32 @UpdateState(i32** %9, i32* %14)
%21 = call double @CalculateEnergyFunction(i32** %9, i32* %14)
%22 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19, double %21)
%23 = add nuw nsw i32 %19, 1
%24 = icmp eq i32 %23, 10000
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = call i32 @fclose(i32* %17)
%27 = call i32 @DisplayPattern(i32* %14)
ret i32 0
}