#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*/ ACS_BTEE;
int /*<<< orphan*/ ACS_HLINE;
int /*<<< orphan*/ ACS_LLCORNER;
int /*<<< orphan*/ ACS_LRCORNER;
int /*<<< orphan*/ ACS_PLUS;
int /*<<< orphan*/ ACS_TTEE;
int /*<<< orphan*/ ACS_ULCORNER;
int /*<<< orphan*/ ACS_URCORNER;
int /*<<< orphan*/ ACS_VLINE;
int /*<<< orphan*/ addch(int /*<<< orphan*/);
int /*<<< orphan*/ hline(int /*<<< orphan*/, int);
int /*<<< orphan*/ mvaddch(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printw(char *, char *);
void draw_grid(void) {
  char a[] = "   |   |   ";
  char b[] = "---|---|---";
  int r = 0, row;
  int i;
  addch(ACS_ULCORNER);
  hline(ACS_HLINE, (3 * (3 * 3 + 2) + 2));
  mvaddch(r, (3 * 3 + 2) + 1, ACS_TTEE);
  mvaddch(r, 2 * (3 * 3 + 2) + 2, ACS_TTEE);
  mvaddch(r, (3 * (3 * 3 + 2) + 2) + 1, ACS_URCORNER);
  for (r = 1; r <= 9; r++) {
    row = 2 * r - 1;
    mvaddch(row, 0, ACS_VLINE);
    for (i = 0; i < 3; i++) {
      printw("%s", a);
      addch(ACS_VLINE);
    }
    row++;
    if (r % 3) {
      mvaddch(row, 0, ACS_VLINE);
      for (i = 0; i < 3; i++) {
        printw("%s", b);
        addch(ACS_VLINE);
      }
    } else if (r < 9) {
      mvaddch(row, 0, ACS_VLINE);
      hline(ACS_HLINE, (3 * (3 * 3 + 2) + 2));
      mvaddch(row, (3 * 3 + 2) + 1, ACS_PLUS);
      mvaddch(row, 2 * (3 * 3 + 2) + 2, ACS_PLUS);
      mvaddch(row, (3 * (3 * 3 + 2) + 2) + 1, ACS_VLINE);
    } else {
      mvaddch(row, 0, ACS_LLCORNER);
      hline(ACS_HLINE, (3 * (3 * 3 + 2) + 2));
      mvaddch(row, (3 * 3 + 2) + 1, ACS_BTEE);
      mvaddch(row, 2 * (3 * 3 + 2) + 2, ACS_BTEE);
      mvaddch(row, (3 * (3 * 3 + 2) + 2) + 1, ACS_LRCORNER);
    }
  }
}


x86 assembly (clang, -O0):
<draw_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xeaf(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    0xea9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea7(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1040 <addch@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    -0x1c(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    -0x1c(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%esi
call   1050 <mvaddch@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jg     13b0 <draw_grid+0x270>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <mvaddch@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1247 <draw_grid+0x107>
lea    -0xc(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printw@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1040 <addch@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1211 <draw_grid+0xd1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12b9 <draw_grid+0x179>
mov    -0x20(%rbp),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <mvaddch@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    12b4 <draw_grid+0x174>
lea    -0x18(%rbp),%rsi
lea    0xd85(%rip),%rdi
call   1030 <printw@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   1040 <addch@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127e <draw_grid+0x13e>
jmp    139d <draw_grid+0x25d>
cmpl   $0x9,-0x1c(%rbp)
jge    1330 <draw_grid+0x1f0>
mov    -0x20(%rbp),%edi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    -0x20(%rbp),%edi
mov    0x2cbd(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    -0x20(%rbp),%edi
mov    0x2ca7(%rip),%rax
mov    (%rax),%edx
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    -0x20(%rbp),%edi
mov    0x2c89(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%esi
call   1050 <mvaddch@plt>
jmp    1398 <draw_grid+0x258>
mov    -0x20(%rbp),%edi
mov    0x2c5e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    -0x20(%rbp),%edi
mov    0x2c80(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    -0x20(%rbp),%edi
mov    0x2c6a(%rip),%rax
mov    (%rax),%edx
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    -0x20(%rbp),%edi
mov    0x2c4c(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%esi
call   1050 <mvaddch@plt>
jmp    139d <draw_grid+0x25d>
jmp    13a2 <draw_grid+0x262>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e1 <draw_grid+0xa1>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movabs $0x7c2020207c202020,%rax
20 20 7c
mov    %rax,0x18(%rsp)
movl   $0x202020,0x20(%rsp)
movabs $0x7c2d2d2d7c2d2d2d,%rax
2d 2d 7c
mov    %rax,0x8(%rsp)
movl   $0x2d2d2d,0x10(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1040 <addch@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    0x2e14(%rip),%rbx
mov    (%rbx),%edx
xor    %edi,%edi
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    (%rbx),%edx
xor    %edi,%edi
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
mov    $0x24,%esi
call   1050 <mvaddch@plt>
mov    $0x1,%ebp
mov    $0x2,%ebx
mov    0x2dc2(%rip),%r13
lea    0xe2b(%rip),%r14
lea    0x18(%rsp),%r15
jmp    125d <draw_grid+0x11d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    %r14,%rdi
lea    0x8(%rsp),%r12
mov    %r12,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
add    $0x1,%ebp
add    $0x2,%ebx
cmp    $0x14,%ebx
je     1386 <draw_grid+0x246>
mov    %ebp,%eax
mov    $0xaaaaaaab,%ecx
imul   %rcx,%rax
shr    $0x21,%rax
add    %eax,%eax
lea    (%rax,%rax,2),%r12d
lea    -0x1(%rbx),%edi
mov    0x0(%r13),%edx
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printw@plt>
mov    0x0(%r13),%edi
call   1040 <addch@plt>
cmp    %ebx,%r12d
jne    1200 <draw_grid+0xc0>
cmp    $0x8,%ebp
ja     1320 <draw_grid+0x1e0>
mov    0x0(%r13),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    0x2cbf(%rip),%r12
mov    (%r12),%edx
mov    %ebx,%edi
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    (%r12),%edx
mov    %ebx,%edi
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    0x0(%r13),%edx
jmp    1375 <draw_grid+0x235>
nopw   0x0(%rax,%rax,1)
mov    0x2c71(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <mvaddch@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
mov    $0x23,%esi
call   1060 <hline@plt>
mov    0x2c94(%rip),%r12
mov    (%r12),%edx
mov    %ebx,%edi
mov    $0xc,%esi
call   1050 <mvaddch@plt>
mov    (%r12),%edx
mov    %ebx,%edi
mov    $0x18,%esi
call   1050 <mvaddch@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x24,%esi
call   1050 <mvaddch@plt>
jmp    124e <draw_grid+0x10e>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.draw_grid.a = [12 x i8] c" | | \00"
@__const.draw_grid.b = [12 x i8] c"---|---|---\00"
@ACS_ULCORNER = global i32 0
@ACS_HLINE = global i32 0
@ACS_TTEE = global i32 0
@ACS_URCORNER = global i32 0
@ACS_VLINE = global i32 0
@.str = [3 x i8] c"%s\00"
@ACS_PLUS = global i32 0
@ACS_LLCORNER = global i32 0
@ACS_BTEE = global i32 0
@ACS_LRCORNER = global i32 0
define void @draw_grid() {
%1 = alloca [12 x i8]
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [12 x i8]* %1 to i8*
%7 = bitcast [12 x i8]* %2 to i8*
store i32 0, i32* %3
%8 = load i32, i32* @ACS_ULCORNER
%9 = call i32 @addch(i32 %8)
%10 = load i32, i32* @ACS_HLINE
%11 = call i32 @hline(i32 %10, i32 35)
%12 = load i32, i32* %3
%13 = load i32, i32* @ACS_TTEE
%14 = call i32 @mvaddch(i32 %12, i32 12, i32 %13)
%15 = load i32, i32* %3
%16 = load i32, i32* @ACS_TTEE
%17 = call i32 @mvaddch(i32 %15, i32 24, i32 %16)
%18 = load i32, i32* %3
%19 = load i32, i32* @ACS_URCORNER
%20 = call i32 @mvaddch(i32 %18, i32 36, i32 %19)
store i32 1, i32* %3
br label %21
21: ; preds = %99, %0
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 9
br i1 %23, label %24, label %102
24: ; preds = %21
%25 = load i32, i32* %3
%26 = mul nsw i32 2, %25
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = load i32, i32* @ACS_VLINE
%30 = call i32 @mvaddch(i32 %28, i32 0, i32 %29)
store i32 0, i32* %5
br label %31
31: ; preds = %39, %24
%32 = load i32, i32* %5
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%36 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @ACS_VLINE
%38 = call i32 @addch(i32 %37)
br label %39
39: ; preds = %34
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %31
42: ; preds = %31
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = load i32, i32* %3
%46 = srem i32 %45, 3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %64
48: ; preds = %42
%49 = load i32, i32* %4
%50 = load i32, i32* @ACS_VLINE
%51 = call i32 @mvaddch(i32 %49, i32 0, i32 %50)
store i32 0, i32* %5
br label %52
52: ; preds = %60, %48
%53 = load i32, i32* %5
%54 = icmp slt i32 %53, 3
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%57 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @ACS_VLINE
%59 = call i32 @addch(i32 %58)
br label %60
60: ; preds = %55
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %52
63: ; preds = %52
br label %98
64: ; preds = %42
%65 = load i32, i32* %3
%66 = icmp slt i32 %65, 9
br i1 %66, label %67, label %82
67: ; preds = %64
%68 = load i32, i32* %4
%69 = load i32, i32* @ACS_VLINE
%70 = call i32 @mvaddch(i32 %68, i32 0, i32 %69)
%71 = load i32, i32* @ACS_HLINE
%72 = call i32 @hline(i32 %71, i32 35)
%73 = load i32, i32* %4
%74 = load i32, i32* @ACS_PLUS
%75 = call i32 @mvaddch(i32 %73, i32 12, i32 %74)
%76 = load i32, i32* %4
%77 = load i32, i32* @ACS_PLUS
%78 = call i32 @mvaddch(i32 %76, i32 24, i32 %77)
%79 = load i32, i32* %4
%80 = load i32, i32* @ACS_VLINE
%81 = call i32 @mvaddch(i32 %79, i32 36, i32 %80)
br label %97
82: ; preds = %64
%83 = load i32, i32* %4
%84 = load i32, i32* @ACS_LLCORNER
%85 = call i32 @mvaddch(i32 %83, i32 0, i32 %84)
%86 = load i32, i32* @ACS_HLINE
%87 = call i32 @hline(i32 %86, i32 35)
%88 = load i32, i32* %4
%89 = load i32, i32* @ACS_BTEE
%90 = call i32 @mvaddch(i32 %88, i32 12, i32 %89)
%91 = load i32, i32* %4
%92 = load i32, i32* @ACS_BTEE
%93 = call i32 @mvaddch(i32 %91, i32 24, i32 %92)
%94 = load i32, i32* %4
%95 = load i32, i32* @ACS_LRCORNER
%96 = call i32 @mvaddch(i32 %94, i32 36, i32 %95)
br label %97
97: ; preds = %82, %67
br label %98
98: ; preds = %97, %63
br label %99
99: ; preds = %98
%100 = load i32, i32* %3
%101 = add nsw i32 %100, 1
store i32 %101, i32* %3
br label %21
102: ; preds = %21
ret void
}

LLVM IR (-O2):
@__const.draw_grid.a = [12 x i8] c" | | \00"
@__const.draw_grid.b = [12 x i8] c"---|---|---\00"
@ACS_ULCORNER = global i32 0
@ACS_HLINE = global i32 0
@ACS_TTEE = global i32 0
@ACS_URCORNER = global i32 0
@ACS_VLINE = global i32 0
@.str = [3 x i8] c"%s\00"
@ACS_PLUS = global i32 0
@ACS_LLCORNER = global i32 0
@ACS_BTEE = global i32 0
@ACS_LRCORNER = global i32 0
define void @draw_grid() {
%1 = alloca [12 x i8]
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @ACS_ULCORNER
%6 = tail call i32 @addch(i32 %5)
%7 = load i32, i32* @ACS_HLINE
%8 = tail call i32 @hline(i32 %7, i32 35)
%9 = load i32, i32* @ACS_TTEE
%10 = tail call i32 @mvaddch(i32 0, i32 12, i32 %9)
%11 = load i32, i32* @ACS_TTEE
%12 = tail call i32 @mvaddch(i32 0, i32 24, i32 %11)
%13 = load i32, i32* @ACS_URCORNER
%14 = tail call i32 @mvaddch(i32 0, i32 36, i32 %13)
br label %15
15: ; preds = %0, %68
%16 = phi i32 [ 1, %0 ], [ %69, %68 ]
%17 = shl nuw nsw i32 %16, 1
%18 = add nsw i32 %17, -1
%19 = load i32, i32* @ACS_VLINE
%20 = call i32 @mvaddch(i32 %18, i32 0, i32 %19)
%21 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%22 = load i32, i32* @ACS_VLINE
%23 = call i32 @addch(i32 %22)
%24 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%25 = load i32, i32* @ACS_VLINE
%26 = call i32 @addch(i32 %25)
%27 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%28 = load i32, i32* @ACS_VLINE
%29 = call i32 @addch(i32 %28)
%30 = urem i32 %16, 3
%31 = icmp eq i32 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %15
%33 = load i32, i32* @ACS_VLINE
%34 = call i32 @mvaddch(i32 %17, i32 0, i32 %33)
%35 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%36 = load i32, i32* @ACS_VLINE
%37 = call i32 @addch(i32 %36)
%38 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%39 = load i32, i32* @ACS_VLINE
%40 = call i32 @addch(i32 %39)
%41 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%42 = load i32, i32* @ACS_VLINE
%43 = call i32 @addch(i32 %42)
br label %68
44: ; preds = %15
%45 = icmp ult i32 %16, 9
br i1 %45, label %46, label %57
46: ; preds = %44
%47 = load i32, i32* @ACS_VLINE
%48 = call i32 @mvaddch(i32 %17, i32 0, i32 %47)
%49 = load i32, i32* @ACS_HLINE
%50 = call i32 @hline(i32 %49, i32 35)
%51 = load i32, i32* @ACS_PLUS
%52 = call i32 @mvaddch(i32 %17, i32 12, i32 %51)
%53 = load i32, i32* @ACS_PLUS
%54 = call i32 @mvaddch(i32 %17, i32 24, i32 %53)
%55 = load i32, i32* @ACS_VLINE
%56 = call i32 @mvaddch(i32 %17, i32 36, i32 %55)
br label %68
57: ; preds = %44
%58 = load i32, i32* @ACS_LLCORNER
%59 = call i32 @mvaddch(i32 %17, i32 0, i32 %58)
%60 = load i32, i32* @ACS_HLINE
%61 = call i32 @hline(i32 %60, i32 35)
%62 = load i32, i32* @ACS_BTEE
%63 = call i32 @mvaddch(i32 %17, i32 12, i32 %62)
%64 = load i32, i32* @ACS_BTEE
%65 = call i32 @mvaddch(i32 %17, i32 24, i32 %64)
%66 = load i32, i32* @ACS_LRCORNER
%67 = call i32 @mvaddch(i32 %17, i32 36, i32 %66)
br label %68
68: ; preds = %32, %57, %46
%69 = add nuw nsw i32 %16, 1
%70 = icmp eq i32 %69, 10
br i1 %70, label %71, label %15
71: ; preds = %68
ret void
}