#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 uint8_t;

/* Variables and functions */
int ACS_CKBOARD;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ addch(int);
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int /*<<< orphan*/ move(int, int);
void draw_selection(uint8_t map[], int selectedX, int selectedY,
                    int selectedWidth, int selectedHeight) {
  int i, j;
  attron(COLOR_PAIR(2));
  for (i = 0; i < selectedHeight; i++) {
    for (j = 0; j < selectedWidth; j++) {
      move(2 + ((i + selectedY) % 19), 1 + ((j + selectedX) % 78));
      uint8_t val = map[((i + selectedY) % 19) * 78 + ((j + selectedX) % 78)];
      if (val == 0) {
        addch('.');
      } else if (val == 1) {
        addch('x');
      } else if (val == 2) {
        addch(ACS_CKBOARD);
      } else {
        addch(val);
      }
    }
  }
  attroff(COLOR_PAIR(2));
}


x86 assembly (clang, -O0):
<draw_selection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    $0x2,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1040 <attron@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1288 <draw_selection+0x138>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1275 <draw_selection+0x125>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x13,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x2,%edi
mov    -0x20(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x4e,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
call   1070 <move@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x13,%ecx
cltd
idiv   %ecx
imul   $0x4e,%edx,%ecx
mov    -0x20(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x4e,%esi
cltd
idiv   %esi
mov    -0x30(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    121a <draw_selection+0xca>
mov    $0x2e,%edi
call   1060 <addch@plt>
jmp    1262 <draw_selection+0x112>
cmpl   $0x1,-0x24(%rbp)
jne    1233 <draw_selection+0xe3>
mov    $0x78,%edi
call   1060 <addch@plt>
jmp    125d <draw_selection+0x10d>
cmpl   $0x2,-0x24(%rbp)
jne    1250 <draw_selection+0x100>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1060 <addch@plt>
jmp    1258 <draw_selection+0x108>
mov    -0x24(%rbp),%edi
call   1060 <addch@plt>
jmp    125d <draw_selection+0x10d>
jmp    1262 <draw_selection+0x112>
jmp    1267 <draw_selection+0x117>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1194 <draw_selection+0x44>
jmp    127a <draw_selection+0x12a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <draw_selection+0x31>
mov    $0x2,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_selection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebp
mov    %ecx,0xc(%rsp)
mov    %rdx,0x20(%rsp)
mov    %esi,0x18(%rsp)
mov    %rdi,%rbx
mov    $0x2,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1040 <attron@plt>
mov    %ebp,0x1c(%rsp)
test   %ebp,%ebp
jle    1277 <draw_selection+0x127>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    11b7 <draw_selection+0x67>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x10(%rsp)
cmp    0x1c(%rsp),%eax
je     1277 <draw_selection+0x127>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <draw_selection+0x50>
mov    0x20(%rsp),%rax
mov    0x10(%rsp),%rcx
add    %ecx,%eax
movslq %eax,%rbp
imul   $0x6bca1af3,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,8),%ecx
lea    (%rax,%rcx,2),%eax
sub    %eax,%ebp
imul   $0x4e,%ebp,%r12d
add    $0x2,%ebp
mov    0x18(%rsp),%r13d
mov    0xc(%rsp),%r15d
jmp    1218 <draw_selection+0xc8>
nopl   0x0(%rax)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <addch@plt>
add    $0x1,%r13d
add    $0xffffffff,%r15d
je     11a0 <draw_selection+0x50>
movslq %r13d,%rax
imul   $0xffffffffd20d20d3,%rax,%rcx
shr    $0x20,%rcx
add    %r13d,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x4e,%ecx,%ecx
mov    %eax,%r14d
sub    %ecx,%r14d
add    %r12d,%r14d
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x1,%esi
mov    %ebp,%edi
call   1070 <move@plt>
movslq %r14d,%rax
mov    (%rbx,%rax,4),%edi
test   %edi,%edi
je     1270 <draw_selection+0x120>
cmp    $0x2,%edi
je     1200 <draw_selection+0xb0>
cmp    $0x1,%edi
jne    1209 <draw_selection+0xb9>
mov    $0x78,%edi
jmp    1209 <draw_selection+0xb9>
nopl   0x0(%rax)
mov    $0x2e,%edi
jmp    1209 <draw_selection+0xb9>
mov    $0x2,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <attroff@plt>

LLVM IR (-O0):
@ACS_CKBOARD = global i32 0
define void @draw_selection(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = call i32 @COLOR_PAIR(i32 2)
%15 = call i32 @attron(i32 %14)
store i32 0, i32* %11
br label %16
16: ; preds = %76, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %10
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %79
20: ; preds = %16
store i32 0, i32* %12
br label %21
21: ; preds = %72, %20
%22 = load i32, i32* %12
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %75
25: ; preds = %21
%26 = load i32, i32* %11
%27 = load i32, i32* %8
%28 = add nsw i32 %26, %27
%29 = srem i32 %28, 19
%30 = add nsw i32 2, %29
%31 = load i32, i32* %12
%32 = load i32, i32* %7
%33 = add nsw i32 %31, %32
%34 = srem i32 %33, 78
%35 = add nsw i32 1, %34
%36 = call i32 @move(i32 %30, i32 %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* %11
%39 = load i32, i32* %8
%40 = add nsw i32 %38, %39
%41 = srem i32 %40, 19
%42 = mul nsw i32 %41, 78
%43 = load i32, i32* %12
%44 = load i32, i32* %7
%45 = add nsw i32 %43, %44
%46 = srem i32 %45, 78
%47 = add nsw i32 %42, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %37, i64 %48
%50 = load i32, i32* %49
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %25
%54 = call i32 @addch(i32 46)
br label %71
55: ; preds = %25
%56 = load i32, i32* %13
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @addch(i32 120)
br label %70
60: ; preds = %55
%61 = load i32, i32* %13
%62 = icmp eq i32 %61, 2
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @ACS_CKBOARD
%65 = call i32 @addch(i32 %64)
br label %69
66: ; preds = %60
%67 = load i32, i32* %13
%68 = call i32 @addch(i32 %67)
br label %69
69: ; preds = %66, %63
br label %70
70: ; preds = %69, %58
br label %71
71: ; preds = %70, %53
br label %72
72: ; preds = %71
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %21
75: ; preds = %21
br label %76
76: ; preds = %75
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %16
79: ; preds = %16
%80 = call i32 @COLOR_PAIR(i32 2)
%81 = call i32 @attroff(i32 %80)
ret void
}

LLVM IR (-O2):
@ACS_CKBOARD = global i32 0
define void @draw_selection(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @COLOR_PAIR(i32 2)
%7 = tail call i32 @attron(i32 %6)
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %40
9: ; preds = %5
%10 = icmp sgt i32 %3, 0
br label %11
11: ; preds = %9, %37
%12 = phi i32 [ 0, %9 ], [ %38, %37 ]
br i1 %10, label %13, label %37
13: ; preds = %11
%14 = add nsw i32 %12, %2
%15 = srem i32 %14, 19
%16 = add nsw i32 %15, 2
%17 = mul nsw i32 %15, 78
br label %18
18: ; preds = %13, %32
%19 = phi i32 [ 0, %13 ], [ %35, %32 ]
%20 = add nsw i32 %19, %1
%21 = srem i32 %20, 78
%22 = add nsw i32 %21, 1
%23 = tail call i32 @move(i32 %16, i32 %22)
%24 = add nsw i32 %21, %17
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %0, i64 %25
%27 = load i32, i32* %26
switch i32 %27, label %31 [
i32 0, label %32
i32 1, label %28
i32 2, label %29
]
28: ; preds = %18
br label %32
29: ; preds = %18
%30 = load i32, i32* @ACS_CKBOARD
br label %32
31: ; preds = %18
br label %32
32: ; preds = %18, %28, %31, %29
%33 = phi i32 [ 120, %28 ], [ %27, %31 ], [ %30, %29 ], [ 46, %18 ]
%34 = tail call i32 @addch(i32 %33)
%35 = add nuw nsw i32 %19, 1
%36 = icmp eq i32 %35, %3
br i1 %36, label %37, label %18
37: ; preds = %32, %11
%38 = add nuw nsw i32 %12, 1
%39 = icmp eq i32 %38, %4
br i1 %39, label %40, label %11
40: ; preds = %37, %5
%41 = tail call i32 @COLOR_PAIR(i32 2)
%42 = tail call i32 @attroff(i32 %41)
ret void
}