#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 *);
int /*<<< orphan*/ mcmove(int *, int *, int *);
int /*<<< orphan*/ printf(char *, int, ...);
double tanh(double);
int total_energy(int *, int *, int *);
int total_mag(int *);
main() {
  int itime;
  int i;
  long int iseed;
  int spin[1000];
  int nbr1[1000];
  int nbr2[1000];
  double energy_analytic;
  int big_energy;
  int big_mag;
  double E_per_spin;
  double M_per_spin;
  big_energy = 0;
  big_mag = 0;
  itime = 0;
  iseed = -12888333;
  energy_analytic = -1.0 * tanh(1.0 / 2.0);
  initialize(spin, nbr1, nbr2);
  for (i = 1; i <= 10; i++) {
    itime = i;
    mcmove(spin, nbr1, nbr2);
  }
  for (i = (10 + 1); i <= 1000; 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 / ((1000 - 10) * (1000));
  E_per_spin = big_energy;
  E_per_spin = E_per_spin / ((1000 - 10) * (1000));
  printf("spin %lf \n", M_per_spin);
  printf("Energy %lf \n", E_per_spin);
  printf("spin is zero, Energy/spin is %lf \n", energy_analytic);
  printf("T %lf, Size= %d \n", 2.0, 1000);
  printf("# of warm-up steps is %d, No. of MCS is %d \n", 10, 1000);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2f0c(%rbp)
movl   $0x0,-0x2f10(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0xffffffffff3b56f3,-0x18(%rbp)
ff
movsd  0xe6b(%rip),%xmm0
call   1040 <tanh@plt>
movaps %xmm0,%xmm1
movsd  0xe53(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x2f08(%rbp)
ff
lea    -0xfc0(%rbp),%rdi
lea    -0x1f60(%rbp),%rsi
lea    -0x2f00(%rbp),%rdx
call   1060 <initialize@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     1212 <main+0xb2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0xfc0(%rbp),%rdi
lea    -0x1f60(%rbp),%rsi
lea    -0x2f00(%rbp),%rdx
call   1030 <mcmove@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11da <main+0x7a>
movl   $0xb,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jg     12b2 <main+0x152>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0xfc0(%rbp),%rdi
lea    -0x1f60(%rbp),%rsi
lea    -0x2f00(%rbp),%rdx
call   1030 <mcmove@plt>
mov    -0x2f10(%rbp),%eax
mov    %eax,-0x2f28(%rbp)
lea    -0xfc0(%rbp),%rdi
call   1070 <total_mag@plt>
mov    %eax,%ecx
mov    -0x2f28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2f10(%rbp)
mov    -0x2f0c(%rbp),%eax
mov    %eax,-0x2f24(%rbp)
lea    -0xfc0(%rbp),%rdi
lea    -0x1f60(%rbp),%rsi
lea    -0x2f00(%rbp),%rdx
call   1080 <total_energy@plt>
mov    %eax,%ecx
mov    -0x2f24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2f0c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1219 <main+0xb9>
cvtsi2sdl -0x2f10(%rbp),%xmm0
ff
movsd  %xmm0,-0x2f20(%rbp)
ff
movsd  -0x2f20(%rbp),%xmm0
ff
movsd  0xd3e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x2f20(%rbp)
ff
cvtsi2sdl -0x2f0c(%rbp),%xmm0
ff
movsd  %xmm0,-0x2f18(%rbp)
ff
movsd  -0x2f18(%rbp),%xmm0
ff
movsd  0xd12(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x2f18(%rbp)
ff
cvttsd2si -0x2f20(%rbp),%esi
ff
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cvttsd2si -0x2f18(%rbp),%esi
ff
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cvttsd2si -0x2f08(%rbp),%esi
ff
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd00(%rip),%rdi
mov    $0x2,%esi
mov    $0x3e8,%edx
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcfa(%rip),%rdi
mov    $0xa,%esi
mov    $0x3e8,%edx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x2f30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2ef8,%rsp
movsd  0xe87(%rip),%xmm0
call   1040 <tanh@plt>
lea    0x1f50(%rsp),%r12
lea    0xfb0(%rsp),%r14
lea    0x10(%rsp),%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <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>
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    $0x3de,%ebx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mcmove@plt>
mov    %r12,%rdi
call   1070 <total_mag@plt>
add    %eax,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <total_energy@plt>
add    %eax,%r13d
add    $0xffffffff,%ebx
jne    1240 <main+0xe0>
cvtsi2sd %ebp,%xmm0
movsd  0xd8e(%rip),%xmm1
cvtsi2sd %r13d,%xmm2
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
cvttsd2si %xmm0,%esi
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cvttsd2si 0x8(%rsp),%esi
lea    0xd6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd6e(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd81(%rip),%rdi
mov    $0x2,%esi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd7b(%rip),%rdi
mov    $0xa,%esi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x2ef8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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