#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 get_col();
int /*<<< orphan*/ get_color();
char get_row();
int /*<<< orphan*/ putch_color(char, int /*<<< orphan*/);
int /*<<< orphan*/ scroll();
int /*<<< orphan*/ setpos(char, char);
void putch3(char c) {
  char g_col, g_row;
  g_row = get_row();
  g_col = get_col();
  switch (c) {
  case '\r':
    g_col = 0;
    setpos(g_row, g_col);
    break;
  case '\n':
    if (g_row == 24)
      scroll();
    else {
      g_row++;
      setpos(g_row, g_col);
    }
    break;
  default:
    putch_color(c, get_color());
    g_col++;
    setpos(g_row, g_col);
  }
}


x86 assembly (clang, -O0):
<putch3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xor    %eax,%eax
mov    %al,-0x9(%rbp)
call   1030 <get_row@plt>
mov    %al,%cl
mov    -0x9(%rbp),%al
mov    %cl,-0x3(%rbp)
call   1070 <get_col@plt>
mov    %al,-0x2(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0xa,%eax
je     11c6 <putch3+0x66>
jmp    119d <putch3+0x3d>
mov    -0x8(%rbp),%eax
sub    $0xd,%eax
jne    11fb <putch3+0x9b>
jmp    11ae <putch3+0x4e>
movb   $0x0,-0x2(%rbp)
mov    -0x3(%rbp),%al
movsbl %al,%edi
movsbl -0x2(%rbp),%esi
call   1060 <setpos@plt>
jmp    122c <putch3+0xcc>
movsbl -0x3(%rbp),%eax
cmp    $0x18,%eax
jne    11df <putch3+0x7f>
mov    $0x0,%al
call   1080 <scroll@plt>
jmp    11f6 <putch3+0x96>
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
mov    -0x3(%rbp),%al
movsbl %al,%edi
movsbl -0x2(%rbp),%esi
call   1060 <setpos@plt>
jmp    122c <putch3+0xcc>
mov    -0x1(%rbp),%al
mov    %al,-0xa(%rbp)
mov    $0x0,%al
call   1040 <get_color@plt>
mov    %eax,%esi
mov    -0xa(%rbp),%al
movsbl %al,%edi
call   1050 <putch_color@plt>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
mov    -0x3(%rbp),%al
movsbl %al,%edi
movsbl -0x2(%rbp),%esi
call   1060 <setpos@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putch3>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <get_row@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <get_col@plt>
mov    %eax,%r14d
cmp    $0xa,%ebp
je     118a <putch3+0x2a>
cmp    $0xd,%ebp
jne    119a <putch3+0x3a>
movsbl %bl,%edi
xor    %esi,%esi
jmp    11c3 <putch3+0x63>
cmp    $0x18,%bl
jne    11b9 <putch3+0x59>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <scroll@plt>
xor    %eax,%eax
call   1040 <get_color@plt>
movsbl %bpl,%edi
mov    %eax,%esi
call   1050 <putch_color@plt>
add    $0x1,%r14b
movsbl %bl,%edi
movsbl %r14b,%esi
jmp    11c3 <putch3+0x63>
add    $0x1,%bl
movsbl %r14b,%esi
movsbl %bl,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <setpos@plt>

LLVM IR (-O0):
define void @putch3(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
%5 = call signext i8 (...) @get_row()
store i8 %5, i8* %4
%6 = call signext i8 (...) @get_col()
store i8 %6, i8* %3
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %26 [
i32 13, label %9
i32 10, label %13
]
9: ; preds = %1
store i8 0, i8* %3
%10 = load i8, i8* %4
%11 = load i8, i8* %3
%12 = call i32 @setpos(i8 signext %10, i8 signext %11)
br label %35
13: ; preds = %1
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 24
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (...) @scroll()
br label %25
19: ; preds = %13
%20 = load i8, i8* %4
%21 = add i8 %20, 1
store i8 %21, i8* %4
%22 = load i8, i8* %4
%23 = load i8, i8* %3
%24 = call i32 @setpos(i8 signext %22, i8 signext %23)
br label %25
25: ; preds = %19, %17
br label %35
26: ; preds = %1
%27 = load i8, i8* %2
%28 = call i32 (...) @get_color()
%29 = call i32 @putch_color(i8 signext %27, i32 %28)
%30 = load i8, i8* %3
%31 = add i8 %30, 1
store i8 %31, i8* %3
%32 = load i8, i8* %4
%33 = load i8, i8* %3
%34 = call i32 @setpos(i8 signext %32, i8 signext %33)
br label %35
35: ; preds = %26, %25, %9
ret void
}

LLVM IR (-O2):
define void @putch3(i8 signext %0) {
%2 = tail call signext i8 (...) @get_row()
%3 = tail call signext i8 (...) @get_col()
%4 = sext i8 %0 to i32
switch i32 %4, label %14 [
i32 13, label %5
i32 10, label %7
]
5: ; preds = %1
%6 = tail call i32 @setpos(i8 signext %2, i8 signext 0)
br label %19
7: ; preds = %1
%8 = icmp eq i8 %2, 24
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (...) @scroll()
br label %19
11: ; preds = %7
%12 = add i8 %2, 1
%13 = tail call i32 @setpos(i8 signext %12, i8 signext %3)
br label %19
14: ; preds = %1
%15 = tail call i32 (...) @get_color()
%16 = tail call i32 @putch_color(i8 signext %0, i32 %15)
%17 = add i8 %3, 1
%18 = tail call i32 @setpos(i8 signext %2, i8 signext %17)
br label %19
19: ; preds = %9, %11, %14, %5
ret void
}