#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*/ COLOR_BLACK;
int /*<<< orphan*/ COLOR_GREEN;
int /*<<< orphan*/ COLOR_RED;
int ERR;
#define KEY_DOWN 129
#define KEY_UP 128
int /*<<< orphan*/ TRUE;
float atof(char *);
int /*<<< orphan*/ draw(int **, int, float);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int);
int flip(int **, float);
int getch();
int /*<<< orphan*/ init(int **);
int /*<<< orphan*/ init_pair(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ nodelay(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, float *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  srand(time(NULL));
  float T = 90;
  if (argc == 1) {
    printf("Ising Model simulator\n");
    printf("enter temperature:");
    scanf("%f", &T);
  } else
    T = atof(argv[1]);
  if (T <= 0) {
    printf("ising: can't operate at absolute Zero or negative temperatures. "
           "sorry!\n");
    exit(1);
  }
  int m[40][40];
  init(m);
  initscr();
  int flips = 0;
  start_color();
  noecho();
  init_pair(1, COLOR_RED, COLOR_BLACK);
  init_pair(2, COLOR_GREEN, COLOR_BLACK);
  draw(m, flips, T);
  int ch;
  keypad(stdscr, TRUE);
  nodelay(stdscr, TRUE);
  for (;;) {
    if ((ch = getch()) == ERR) {
      usleep(100);
      if (flip(m, T) == 1) {
        flips++;
        draw(m, flips, T);
      }
    } else {
      switch (ch) {
      case 'Q':
      case 'q':
        endwin();
        exit(0);
        break;
      case KEY_DOWN:
        if (T > 10)
          T -= 5.0;
        draw(m, flips, T);
        break;
      case KEY_UP:
        T += 5.0;
        draw(m, flips, T);
        break;
      defaults:
        break;
      }
    }
  }
  endwin();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1930,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
movss  0xdaf(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    128d <main+0x6d>
lea    0xda9(%rip),%rdi
call   1060 <printf@plt>
lea    0xdb4(%rip),%rdi
call   1060 <printf@plt>
lea    0xdbb(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10f0 <scanf@plt>
jmp    129f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jb     12c2 <main+0xa2>
lea    0xd8a(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x1920(%rbp),%rdi
call   10c0 <init@plt>
mov    $0x0,%al
call   1080 <initscr@plt>
movl   $0x0,-0x1924(%rbp)
mov    $0x0,%al
call   1090 <start_color@plt>
mov    $0x0,%al
call   1120 <noecho@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%esi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1050 <init_pair@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    0x2cb7(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%edi
call   1050 <init_pair@plt>
lea    -0x1920(%rbp),%rdi
mov    -0x1924(%rbp),%esi
movss  -0x14(%rbp),%xmm0
call   1030 <draw@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
mov    0x2c8c(%rip),%rax
mov    (%rax),%esi
call   1070 <keypad@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
mov    0x2c75(%rip),%rax
mov    (%rax),%esi
call   10e0 <nodelay@plt>
mov    $0x0,%al
call   1100 <getch@plt>
mov    %eax,-0x1928(%rbp)
mov    0x2c6a(%rip),%rcx
cmp    (%rcx),%eax
jne    13d5 <main+0x1b5>
mov    $0x64,%edi
call   1140 <usleep@plt>
lea    -0x1920(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
call   10b0 <flip@plt>
cmp    $0x1,%eax
jne    13d0 <main+0x1b0>
mov    -0x1924(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1924(%rbp)
lea    -0x1920(%rbp),%rdi
mov    -0x1924(%rbp),%esi
movss  -0x14(%rbp),%xmm0
call   1030 <draw@plt>
jmp    14c7 <main+0x2a7>
mov    -0x1928(%rbp),%eax
mov    %eax,-0x192c(%rbp)
sub    $0x51,%eax
je     142f <main+0x20f>
jmp    13ef <main+0x1cf>
mov    -0x192c(%rbp),%eax
sub    $0x71,%eax
je     142f <main+0x20f>
jmp    1403 <main+0x1e3>
mov    -0x192c(%rbp),%eax
sub    $0x80,%eax
je     148d <main+0x26d>
jmp    1419 <main+0x1f9>
mov    -0x192c(%rbp),%eax
sub    $0x81,%eax
je     143d <main+0x21d>
jmp    14c2 <main+0x2a2>
mov    $0x0,%al
call   1110 <endwin@plt>
xor    %edi,%edi
call   1130 <exit@plt>
movss  -0x14(%rbp),%xmm0
movss  0xbba(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1471 <main+0x251>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xba4(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    -0x1920(%rbp),%rdi
mov    -0x1924(%rbp),%esi
movss  -0x14(%rbp),%xmm0
call   1030 <draw@plt>
jmp    14c2 <main+0x2a2>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xb6a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    -0x1920(%rbp),%rdi
mov    -0x1924(%rbp),%esi
movss  -0x14(%rbp),%xmm0
call   1030 <draw@plt>
jmp    14c7 <main+0x2a7>
jmp    136a <main+0x14a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1910,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   10e0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
movl   $0x42b40000,0xc(%rsp)
42
cmp    $0x1,%ebp
jne    128c <main+0x5c>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
lea    0xd9e(%rip),%rdi
call   1070 <printf@plt>
lea    0xda5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1100 <scanf@plt>
movss  0xc(%rsp),%xmm0
jmp    129b <main+0x6b>
mov    0x8(%rbx),%rdi
call   1050 <atof@plt>
movss  %xmm0,0xc(%rsp)
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jae    13d8 <main+0x1a8>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   10d0 <init@plt>
xor    %eax,%eax
call   1090 <initscr@plt>
xor    %eax,%eax
call   10a0 <start_color@plt>
xor    %eax,%eax
call   1130 <noecho@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
mov    0x2cf7(%rip),%rbx
mov    (%rbx),%edx
mov    $0x1,%edi
call   1060 <init_pair@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
mov    $0x2,%edi
call   1060 <init_pair@plt>
movss  0xc(%rsp),%xmm0
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <draw@plt>
mov    0x2ccf(%rip),%rbx
mov    (%rbx),%edi
mov    0x2cbe(%rip),%rbp
mov    0x0(%rbp),%esi
call   1080 <keypad@plt>
mov    (%rbx),%edi
mov    0x0(%rbp),%esi
call   10f0 <nodelay@plt>
mov    0x2cb5(%rip),%rbx
xor    %ebp,%ebp
jmp    1367 <main+0x137>
nopw   0x0(%rax,%rax,1)
cmp    $0x80,%eax
jg     13a0 <main+0x170>
jne    13c0 <main+0x190>
movss  0xc(%rsp),%xmm0
addss  0xca9(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <draw@plt>
xor    %eax,%eax
call   1110 <getch@plt>
cmp    (%rbx),%eax
jne    1340 <main+0x110>
mov    $0x64,%edi
call   1150 <usleep@plt>
movss  0xc(%rsp),%xmm0
mov    %r14,%rdi
call   10c0 <flip@plt>
cmp    $0x1,%eax
jne    1367 <main+0x137>
add    $0x1,%ebp
movss  0xc(%rsp),%xmm0
jmp    135d <main+0x12d>
nopw   0x0(%rax,%rax,1)
cmp    $0x81,%eax
jne    1367 <main+0x137>
movss  0xc(%rsp),%xmm0
ucomiss 0xc50(%rip),%xmm0
jbe    135d <main+0x12d>
addss  0xc4a(%rip),%xmm0
jmp    1357 <main+0x127>
cmp    $0x51,%eax
je     13ca <main+0x19a>
cmp    $0x71,%eax
jne    1367 <main+0x137>
xor    %eax,%eax
call   1120 <endwin@plt>
xor    %edi,%edi
call   1140 <exit@plt>
lea    0xc43(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Ising Model simulator\0A\00"
@.str.1 = [19 x i8] c"enter temperature:\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [72 x i8] c"ising: can't operate at absolute Zero or negative temperatures. sorry!\0A\00"
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@COLOR_GREEN = global i32 0
@stdscr = global i32 0
@TRUE = global i32 0
@ERR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca [40 x [40 x i32]]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store float 9.000000e+01, float* %6
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %6)
br label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call float @atof(i8* %21)
store float %22, float* %6
br label %23
23: ; preds = %18, %14
%24 = load float, float* %6
%25 = fcmp ole float %24, 0.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23
%30 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%31 = bitcast [40 x i32]* %30 to i32**
%32 = call i32 @init(i32** %31)
%33 = call i32 (...) @initscr()
store i32 0, i32* %8
%34 = call i32 (...) @start_color()
%35 = call i32 (...) @noecho()
%36 = load i32, i32* @COLOR_RED
%37 = load i32, i32* @COLOR_BLACK
%38 = call i32 @init_pair(i32 1, i32 %36, i32 %37)
%39 = load i32, i32* @COLOR_GREEN
%40 = load i32, i32* @COLOR_BLACK
%41 = call i32 @init_pair(i32 2, i32 %39, i32 %40)
%42 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%43 = bitcast [40 x i32]* %42 to i32**
%44 = load i32, i32* %8
%45 = load float, float* %6
%46 = call i32 @draw(i32** %43, i32 %44, float %45)
%47 = load i32, i32* @stdscr
%48 = load i32, i32* @TRUE
%49 = call i32 @keypad(i32 %47, i32 %48)
%50 = load i32, i32* @stdscr
%51 = load i32, i32* @TRUE
%52 = call i32 @nodelay(i32 %50, i32 %51)
br label %53
53: ; preds = %104, %29
%54 = call i32 (...) @getch()
store i32 %54, i32* %9
%55 = load i32, i32* @ERR
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %73
57: ; preds = %53
%58 = call i32 @usleep(i32 100)
%59 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%60 = bitcast [40 x i32]* %59 to i32**
%61 = load float, float* %6
%62 = call i32 @flip(i32** %60, float %61)
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %72
64: ; preds = %57
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
%67 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%68 = bitcast [40 x i32]* %67 to i32**
%69 = load i32, i32* %8
%70 = load float, float* %6
%71 = call i32 @draw(i32** %68, i32 %69, float %70)
br label %72
72: ; preds = %64, %57
br label %104
73: ; preds = %53
%74 = load i32, i32* %9
switch i32 %74, label %103 [
i32 81, label %75
i32 113, label %75
i32 129, label %78
i32 128, label %92
]
75: ; preds = %73, %73
%76 = call i32 (...) @endwin()
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %73
%79 = load float, float* %6
%80 = fcmp ogt float %79, 1.000000e+01
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load float, float* %6
%83 = fpext float %82 to double
%84 = fsub double %83, 5.000000e+00
%85 = fptrunc double %84 to float
store float %85, float* %6
br label %86
86: ; preds = %81, %78
%87 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%88 = bitcast [40 x i32]* %87 to i32**
%89 = load i32, i32* %8
%90 = load float, float* %6
%91 = call i32 @draw(i32** %88, i32 %89, float %90)
br label %103
92: ; preds = %73
%93 = load float, float* %6
%94 = fpext float %93 to double
%95 = fadd double %94, 5.000000e+00
%96 = fptrunc double %95 to float
store float %96, float* %6
%97 = getelementptr inbounds [40 x [40 x i32]], [40 x [40 x i32]]* %7, i64 0, i64 0
%98 = bitcast [40 x i32]* %97 to i32**
%99 = load i32, i32* %8
%100 = load float, float* %6
%101 = call i32 @draw(i32** %98, i32 %99, float %100)
br label %103
102: ; No predecessors!
br label %103
103: ; preds = %73, %102, %92, %86
br label %104
104: ; preds = %103, %72
br label %53
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"enter temperature:\00"
@.str.2 = [3 x i8] c"%f\00"
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@COLOR_GREEN = global i32 0
@stdscr = global i32 0
@TRUE = global i32 0
@ERR = global i32 0
@str = [71 x i8] c"ising: can't operate at absolute Zero or negative temperatures. sorry!\00"
@str.4 = [22 x i8] c"Ising Model simulator\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca float
%4 = alloca [40 x [40 x i32]]
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = bitcast float* %3 to i8*
store float 9.000000e+01, float* %3
%8 = icmp eq i32 %0, 1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
%13 = load float, float* %3
br label %18
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call float @atof(i8* %16)
store float %17, float* %3
br label %18
18: ; preds = %14, %9
%19 = phi float [ %17, %14 ], [ %13, %9 ]
%20 = fcmp ugt float %19, 0.000000e+00
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = bitcast [40 x [40 x i32]]* %4 to i8*
%26 = bitcast [40 x [40 x i32]]* %4 to i32**
%27 = call i32 @init(i32** %26)
%28 = call i32 (...) @initscr()
%29 = call i32 (...) @start_color()
%30 = call i32 (...) @noecho()
%31 = load i32, i32* @COLOR_RED
%32 = load i32, i32* @COLOR_BLACK
%33 = call i32 @init_pair(i32 1, i32 %31, i32 %32)
%34 = load i32, i32* @COLOR_GREEN
%35 = load i32, i32* @COLOR_BLACK
%36 = call i32 @init_pair(i32 2, i32 %34, i32 %35)
%37 = load float, float* %3
%38 = call i32 @draw(i32** %26, i32 0, float %37)
%39 = load i32, i32* @stdscr
%40 = load i32, i32* @TRUE
%41 = call i32 @keypad(i32 %39, i32 %40)
%42 = load i32, i32* @stdscr
%43 = load i32, i32* @TRUE
%44 = call i32 @nodelay(i32 %42, i32 %43)
br label %45
45: ; preds = %56, %24
%46 = phi i32 [ %57, %56 ], [ 0, %24 ]
br label %47
47: ; preds = %72, %45
%48 = call i32 (...) @getch()
%49 = load i32, i32* @ERR
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = call i32 @usleep(i32 100)
%53 = load float, float* %3
%54 = call i32 @flip(i32** %26, float %53)
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %72
56: ; preds = %51
%57 = add nuw nsw i32 %46, 1
%58 = load float, float* %3
%59 = call i32 @draw(i32** %26, i32 %57, float %58)
br label %45
60: ; preds = %47
switch i32 %48, label %72 [
i32 81, label %61
i32 113, label %61
i32 129, label %64
i32 128, label %73
]
61: ; preds = %60, %60
%62 = call i32 (...) @endwin()
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %60
%65 = load float, float* %3
%66 = fcmp ogt float %65, 1.000000e+01
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = fadd float %65, -5.000000e+00
store float %68, float* %3
br label %69
69: ; preds = %67, %64
%70 = phi float [ %68, %67 ], [ %65, %64 ]
%71 = call i32 @draw(i32** %26, i32 %46, float %70)
br label %72
72: ; preds = %69, %73, %60, %51
br label %47
73: ; preds = %60
%74 = load float, float* %3
%75 = fadd float %74, 5.000000e+00
store float %75, float* %3
%76 = call i32 @draw(i32** %26, i32 %46, float %75)
br label %72
}