#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 */
char COLOR_PAIR(int);
int /*<<< orphan*/ addch(char);
int /*<<< orphan*/ addstr(char *);
int /*<<< orphan*/ move(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ sprintf(char *, char *, int, float);
void draw(int m[40][40], int flips, float T) {
  int i, j, color;
  for (i = 0; i < 40; i++) {
    for (j = 0; j < 40; j++) {
      color = (m[i][j] == 1) ? 1 : 2;
      addch('*' | COLOR_PAIR(color));
      addch(' ');
    }
    addch('\n');
  }
  char str[50];
  sprintf(str, "%d flips so far at temperature %.2f K\n", flips, T);
  addstr(str);
  addstr("Use UP/DOWN keys to change temperature\nPress q to quit simulation");
  refresh();
  move(0, 0);
}


x86 assembly (clang, -O0):
<draw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x28,-0x14(%rbp)
jge    1208 <draw+0xa8>
movl   $0x0,-0x18(%rbp)
cmpl   $0x28,-0x18(%rbp)
jge    11f0 <draw+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <COLOR_PAIR@plt>
movsbl %al,%eax
or     $0x2a,%eax
movsbl %al,%edi
call   1040 <addch@plt>
mov    $0x20,%edi
call   1040 <addch@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118c <draw+0x2c>
mov    $0xa,%edi
call   1040 <addch@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <draw+0x1b>
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%edx
movss  -0x10(%rbp),%xmm0
lea    0xde5(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1070 <addstr@plt>
lea    0xdf7(%rip),%rdi
call   1070 <addstr@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1080 <move@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movss  %xmm0,0xc(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
cmpl   $0x1,(%rbx,%rbp,4)
sete   %al
mov    $0x2,%edi
sub    %eax,%edi
call   1030 <COLOR_PAIR@plt>
or     $0x2a,%al
movsbl %al,%edi
call   1040 <addch@plt>
mov    $0x20,%edi
call   1040 <addch@plt>
add    $0x1,%rbp
cmp    $0x28,%rbp
jne    1190 <draw+0x30>
mov    $0xa,%edi
call   1040 <addch@plt>
add    $0x1,%r15
add    $0xa0,%rbx
cmp    $0x28,%r15
jne    1180 <draw+0x20>
lea    0xe1b(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
movss  0xc(%rsp),%xmm0
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <addstr@plt>
lea    0xe1d(%rip),%rdi
call   1070 <addstr@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <move@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%d flips so far at temperature %.2f K\0A\00"
@.str.1 = [66 x i8] c"Use UP/DOWN keys to change temperature\0APress q to quit simulation\00"
define void @draw([40 x i32]* %0, i32 %1, float %2) {
%4 = alloca [40 x i32]*
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [50 x i8]
store [40 x i32]* %0, [40 x i32]** %4
store i32 %1, i32* %5
store float %2, float* %6
store i32 0, i32* %7
br label %11
11: ; preds = %42, %3
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 40
br i1 %13, label %14, label %45
14: ; preds = %11
store i32 0, i32* %8
br label %15
15: ; preds = %37, %14
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 40
br i1 %17, label %18, label %40
18: ; preds = %15
%19 = load [40 x i32]*, [40 x i32]** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [40 x i32], [40 x i32]* %19, i64 %21
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [40 x i32], [40 x i32]* %22, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 1, i32 2
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = call signext i8 @COLOR_PAIR(i32 %30)
%32 = sext i8 %31 to i32
%33 = or i32 42, %32
%34 = trunc i32 %33 to i8
%35 = call i32 @addch(i8 signext %34)
%36 = call i32 @addch(i8 signext 32)
br label %37
37: ; preds = %18
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %15
40: ; preds = %15
%41 = call i32 @addch(i8 signext 10)
br label %42
42: ; preds = %40
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %11
45: ; preds = %11
%46 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%47 = load i32, i32* %5
%48 = load float, float* %6
%49 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %47, float %48)
%50 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%51 = call i32 @addstr(i8* %50)
%52 = call i32 @addstr(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 (...) @refresh()
%54 = call i32 @move(i32 0, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"%d flips so far at temperature %.2f K\0A\00"
@.str.1 = [66 x i8] c"Use UP/DOWN keys to change temperature\0APress q to quit simulation\00"
define void @draw([40 x i32]* nocapture %0, i32 %1, float %2) {
%4 = alloca [50 x i8]
br label %5
5: ; preds = %3, %19
%6 = phi i64 [ 0, %3 ], [ %21, %19 ]
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %17, %7 ]
%9 = getelementptr inbounds [40 x i32], [40 x i32]* %0, i64 %6, i64 %8
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 1
%12 = select i1 %11, i32 1, i32 2
%13 = tail call signext i8 @COLOR_PAIR(i32 %12)
%14 = or i8 %13, 42
%15 = tail call i32 @addch(i8 signext %14)
%16 = tail call i32 @addch(i8 signext 32)
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, 40
br i1 %18, label %19, label %7
19: ; preds = %7
%20 = tail call i32 @addch(i8 signext 10)
%21 = add nuw nsw i64 %6, 1
%22 = icmp eq i64 %21, 40
br i1 %22, label %23, label %5
23: ; preds = %19
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%25 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %1, float %2)
%26 = call i32 @addstr(i8* %24)
%27 = call i32 @addstr(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (...) @refresh()
%29 = call i32 @move(i32 0, i32 0)
ret void
}