#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*/ initialize(int **, int *, int *);
double mag_analytic(double);
int /*<<< orphan*/ mcmove(int **, int *, int *);
int /*<<< orphan*/ printf(char *, int, ...);
int total_energy(int **, int *, int *);
int total_mag(int **);
main() {
  int itime;
  int i;
  long int iseed;
  int spin[30][30];
  int nbr1[30];
  int nbr2[30];
  int big_energy;
  int big_mag;
  double E_per_spin;
  double M_per_spin;
  iseed = -12888333;
  itime = 0;
  big_energy = 0;
  big_mag = 0;
  initialize(spin, nbr1, nbr2);
  for (i = 1; i <= 5; i++) {
    itime = i;
    mcmove(spin, nbr1, nbr2);
  }
  for (i = (5 + 1); i <= 100; i++) {
    itime = i;
    mcmove(spin, nbr1, nbr2);
    big_mag = big_mag + total_mag(spin);
    big_energy = big_energy + total_energy(spin, nbr1, nbr2);
  }
  M_per_spin = big_mag;
  M_per_spin = M_per_spin / ((100 - 5) * (30 * 30));
  E_per_spin = big_energy;
  E_per_spin = E_per_spin / ((100 - 5) * (30 * 30));
  printf("Mag/spin %lf \n", M_per_spin);
  printf("Energy/spin %lf \n", E_per_spin);
  printf("Analytic: Mag/spin %f, Energy/spin -2 to 0\n", mag_analytic(0.9));
  printf("Temperature %lf, Edge length of system %d \n", 0.9, 30);
  printf("No. of warm-up steps %d, No. of MCS %d \n", 5, 100);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffff3b56f3,-0x18(%rbp)
ff
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xf34(%rbp)
movl   $0x0,-0xf38(%rbp)
lea    -0xe30(%rbp),%rdi
lea    -0xeb0(%rbp),%rsi
lea    -0xf30(%rbp),%rdx
call   1050 <initialize@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     11ee <main+0x8e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0xe30(%rbp),%rdi
lea    -0xeb0(%rbp),%rsi
lea    -0xf30(%rbp),%rdx
call   1030 <mcmove@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b6 <main+0x56>
movl   $0x6,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jg     128b <main+0x12b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0xe30(%rbp),%rdi
lea    -0xeb0(%rbp),%rsi
lea    -0xf30(%rbp),%rdx
call   1030 <mcmove@plt>
mov    -0xf38(%rbp),%eax
mov    %eax,-0xf50(%rbp)
lea    -0xe30(%rbp),%rdi
call   1060 <total_mag@plt>
mov    %eax,%ecx
mov    -0xf50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xf38(%rbp)
mov    -0xf34(%rbp),%eax
mov    %eax,-0xf4c(%rbp)
lea    -0xe30(%rbp),%rdi
lea    -0xeb0(%rbp),%rsi
lea    -0xf30(%rbp),%rdx
call   1070 <total_energy@plt>
mov    %eax,%ecx
mov    -0xf4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xf34(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f5 <main+0x95>
cvtsi2sdl -0xf38(%rbp),%xmm0
ff
movsd  %xmm0,-0xf48(%rbp)
ff
movsd  -0xf48(%rbp),%xmm0
ff
movsd  0xd5d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xf48(%rbp)
ff
cvtsi2sdl -0xf34(%rbp),%xmm0
ff
movsd  %xmm0,-0xf40(%rbp)
ff
movsd  -0xf40(%rbp),%xmm0
ff
movsd  0xd31(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xf40(%rbp)
ff
cvttsd2si -0xf48(%rbp),%esi
ff
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvttsd2si -0xf40(%rbp),%esi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xce9(%rip),%xmm0
call   1080 <mag_analytic@plt>
cvttsd2si %xmm0,%esi
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd28(%rip),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd3f(%rip),%rdi
mov    $0x5,%esi
mov    $0x64,%edx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xf50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf28,%rsp
lea    0x110(%rsp),%r12
lea    0x90(%rsp),%r14
lea    0x10(%rsp),%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <initialize@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
xor    %ebp,%ebp
mov    $0x5f,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
call   1060 <total_mag@plt>
add    %eax,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <total_energy@plt>
add    %eax,%r13d
add    $0xffffffff,%ebx
jne    11f0 <main+0x90>
cvtsi2sd %ebp,%xmm0
movsd  0xdd6(%rip),%xmm1
cvtsi2sd %r13d,%xmm2
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
cvttsd2si %xmm0,%esi
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cvttsd2si 0x8(%rsp),%esi
lea    0xdc3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0xd9d(%rip),%xmm0
call   1080 <mag_analytic@plt>
cvttsd2si %xmm0,%esi
lea    0xdb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd4(%rip),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x5,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Mag/spin %lf \0A\00"
@.str.1 = [18 x i8] c"Energy/spin %lf \0A\00"
@.str.2 = [44 x i8] c"Analytic: Mag/spin %f, Energy/spin -2 to 0\0A\00"
@.str.3 = [44 x i8] c"Temperature %lf, Edge length of system %d \0A\00"
@.str.4 = [41 x i8] c"No. of warm-up steps %d, No. of MCS %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca [30 x [30 x i32]]
%6 = alloca [30 x i32]
%7 = alloca [30 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store i32 0, i32* %1
store i64 -12888333, i64* %4
store i32 0, i32* %2
store i32 0, i32* %8
store i32 0, i32* %9
%12 = getelementptr inbounds [30 x [30 x i32]], [30 x [30 x i32]]* %5, i64 0, i64 0
%13 = bitcast [30 x i32]* %12 to i32**
%14 = getelementptr inbounds [30 x i32], [30 x i32]* %6, i64 0, i64 0
%15 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%16 = call i32 @initialize(i32** %13, i32* %14, i32* %15)
store i32 1, i32* %3
br label %17
17: ; preds = %27, %0
%18 = load i32, i32* %3
%19 = icmp sle i32 %18, 5
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i32, i32* %3
store i32 %21, i32* %2
%22 = getelementptr inbounds [30 x [30 x i32]], [30 x [30 x i32]]* %5, i64 0, i64 0
%23 = bitcast [30 x i32]* %22 to i32**
%24 = getelementptr inbounds [30 x i32], [30 x i32]* %6, i64 0, i64 0
%25 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%26 = call i32 @mcmove(i32** %23, i32* %24, i32* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %17
30: ; preds = %17
store i32 6, i32* %3
br label %31
31: ; preds = %53, %30
%32 = load i32, i32* %3
%33 = icmp sle i32 %32, 100
br i1 %33, label %34, label %56
34: ; preds = %31
%35 = load i32, i32* %3
store i32 %35, i32* %2
%36 = getelementptr inbounds [30 x [30 x i32]], [30 x [30 x i32]]* %5, i64 0, i64 0
%37 = bitcast [30 x i32]* %36 to i32**
%38 = getelementptr inbounds [30 x i32], [30 x i32]* %6, i64 0, i64 0
%39 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%40 = call i32 @mcmove(i32** %37, i32* %38, i32* %39)
%41 = load i32, i32* %9
%42 = getelementptr inbounds [30 x [30 x i32]], [30 x [30 x i32]]* %5, i64 0, i64 0
%43 = bitcast [30 x i32]* %42 to i32**
%44 = call i32 @total_mag(i32** %43)
%45 = add nsw i32 %41, %44
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = getelementptr inbounds [30 x [30 x i32]], [30 x [30 x i32]]* %5, i64 0, i64 0
%48 = bitcast [30 x i32]* %47 to i32**
%49 = getelementptr inbounds [30 x i32], [30 x i32]* %6, i64 0, i64 0
%50 = getelementptr inbounds [30 x i32], [30 x i32]* %7, i64 0, i64 0
%51 = call i32 @total_energy(i32** %48, i32* %49, i32* %50)
%52 = add nsw i32 %46, %51
store i32 %52, i32* %8
br label %53
53: ; preds = %34
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %31
56: ; preds = %31
%57 = load i32, i32* %9
%58 = sitofp i32 %57 to double
store double %58, double* %11
%59 = load double, double* %11
%60 = fdiv double %59, 8.550000e+04
store double %60, double* %11
%61 = load i32, i32* %8
%62 = sitofp i32 %61 to double
store double %62, double* %10
%63 = load double, double* %10
%64 = fdiv double %63, 8.550000e+04
store double %64, double* %10
%65 = load double, double* %11
%66 = fptosi double %65 to i32
%67 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %66)
%68 = load double, double* %10
%69 = fptosi double %68 to i32
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = call double @mag_analytic(double 9.000000e-01)
%72 = fptosi double %71 to i32
%73 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 30)
%75 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 100)
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str = [15 x i8] c"Mag/spin %lf \0A\00"
@.str.1 = [18 x i8] c"Energy/spin %lf \0A\00"
@.str.2 = [44 x i8] c"Analytic: Mag/spin %f, Energy/spin -2 to 0\0A\00"
@.str.3 = [44 x i8] c"Temperature %lf, Edge length of system %d \0A\00"
@.str.4 = [41 x i8] c"No. of warm-up steps %d, No. of MCS %d \0A\00"
define i32 @main() {
%1 = alloca [30 x [30 x i32]]
%2 = alloca [30 x i32]
%3 = alloca [30 x i32]
%4 = bitcast [30 x [30 x i32]]* %1 to i8*
%5 = bitcast [30 x i32]* %2 to i8*
%6 = bitcast [30 x i32]* %3 to i8*
%7 = bitcast [30 x [30 x i32]]* %1 to i32**
%8 = getelementptr inbounds [30 x i32], [30 x i32]* %2, i64 0, i64 0
%9 = getelementptr inbounds [30 x i32], [30 x i32]* %3, i64 0, i64 0
%10 = call i32 @initialize(i32** %7, i32* %8, i32* %9)
%11 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
%12 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
%13 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
%14 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
%15 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
br label %16
16: ; preds = %0, %16
%17 = phi i32 [ %25, %16 ], [ 6, %0 ]
%18 = phi i32 [ %22, %16 ], [ 0, %0 ]
%19 = phi i32 [ %24, %16 ], [ 0, %0 ]
%20 = call i32 @mcmove(i32** %7, i32* %8, i32* %9)
%21 = call i32 @total_mag(i32** %7)
%22 = add nsw i32 %21, %18
%23 = call i32 @total_energy(i32** %7, i32* %8, i32* %9)
%24 = add nsw i32 %23, %19
%25 = add nuw nsw i32 %17, 1
%26 = icmp eq i32 %25, 101
br i1 %26, label %27, label %16
27: ; preds = %16
%28 = sitofp i32 %22 to double
%29 = fdiv double %28, 8.550000e+04
%30 = sitofp i32 %24 to double
%31 = fdiv double %30, 8.550000e+04
%32 = fptosi double %29 to i32
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = fptosi double %31 to i32
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call double @mag_analytic(double 9.000000e-01)
%37 = fptosi double %36 to i32
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 30)
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 100)
ret i32 0
}