#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*/ memsetw(void *, int, int);
void putchar(char ch) {
  short *vga;
  static int y;
  static int x;
  if (x >= 160 || ch == '\n') {
    x = 0;
    y++;
  }
  if (y >= 25)
    y = 0;
  if (ch == '\n') {
    memsetw((void *)(0xB8000 + (y * 160)), 0x0720, 0x50);
    return;
  }
  vga = (short *)(0xB8000 + (y * 160) + x);
  *vga = 0x0700 | ch;
  x += 2;
  return;
}


x86 assembly (clang, -O0):
<putchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
cmpl   $0xa0,0x2f08(%rip)
jge    113b <putchar+0x2b>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    1154 <putchar+0x44>
movl   $0x0,0x2eeb(%rip)
mov    0x2ee1(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ed8(%rip)
cmpl   $0x19,0x2ed1(%rip)
jl     116b <putchar+0x5b>
movl   $0x0,0x2ec1(%rip)
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    119e <putchar+0x8e>
imul   $0xa0,0x2eaa(%rip),%eax
add    $0xb8000,%eax
movslq %eax,%rdi
mov    $0x720,%esi
mov    $0x50,%edx
call   1030 <memsetw@plt>
jmp    11db <putchar+0xcb>
imul   $0xa0,0x2e84(%rip),%eax
add    $0xb8000,%eax
add    0x2e7d(%rip),%eax
cltq
mov    %rax,-0x10(%rbp)
movsbl -0x1(%rbp),%eax
or     $0x700,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    0x2e5e(%rip),%eax
add    $0x2,%eax
mov    %eax,0x2e55(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putchar>:
cmp    $0xa,%dil
je     1130 <putchar+0x20>
mov    0x2f14(%rip),%eax
cmp    $0xa0,%eax
jge    1130 <putchar+0x20>
mov    0x2f03(%rip),%ecx
cmp    $0x19,%ecx
jge    1150 <putchar+0x40>
jmp    115c <putchar+0x4c>
movl   $0x0,0x2ef6(%rip)
mov    0x2eec(%rip),%ecx
add    $0x1,%ecx
mov    %ecx,0x2ee3(%rip)
xor    %eax,%eax
cmp    $0x19,%ecx
jl     115c <putchar+0x4c>
movl   $0x0,0x2ed2(%rip)
xor    %ecx,%ecx
shl    $0x5,%ecx
lea    (%rcx,%rcx,4),%ecx
movslq %ecx,%rcx
add    $0xb8000,%rcx
cmp    $0xa,%dil
jne    1184 <putchar+0x74>
movslq %ecx,%rdi
mov    $0x720,%esi
mov    $0x50,%edx
jmp    1030 <memsetw@plt>
cltq
movswl %di,%edx
or     $0x700,%edx
mov    %dx,(%rcx,%rax,1)
add    $0x2,%eax
mov    %eax,0x2e94(%rip)
ret

LLVM IR (-O0):
@putchar.y = internal global i32 0
@putchar.x = internal global i32 0
define void @putchar(i8 signext %0) {
%2 = alloca i8
%3 = alloca i16*
store i8 %0, i8* %2
%4 = load i32, i32* @putchar.x
%5 = icmp sge i32 %4, 160
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 10
br i1 %9, label %10, label %13
10: ; preds = %6, %1
store i32 0, i32* @putchar.x
%11 = load i32, i32* @putchar.y
%12 = add nsw i32 %11, 1
store i32 %12, i32* @putchar.y
br label %13
13: ; preds = %10, %6
%14 = load i32, i32* @putchar.y
%15 = icmp sge i32 %14, 25
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* @putchar.y
br label %17
17: ; preds = %16, %13
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i32, i32* @putchar.y
%23 = mul nsw i32 %22, 160
%24 = add nsw i32 753664, %23
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = call i32 @memsetw(i8* %26, i32 1824, i32 80)
br label %43
28: ; preds = %17
%29 = load i32, i32* @putchar.y
%30 = mul nsw i32 %29, 160
%31 = add nsw i32 753664, %30
%32 = load i32, i32* @putchar.x
%33 = add nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i16*
store i16* %35, i16** %3
%36 = load i8, i8* %2
%37 = sext i8 %36 to i32
%38 = or i32 1792, %37
%39 = trunc i32 %38 to i16
%40 = load i16*, i16** %3
store i16 %39, i16* %40
%41 = load i32, i32* @putchar.x
%42 = add nsw i32 %41, 2
store i32 %42, i32* @putchar.x
br label %43
43: ; preds = %28, %21
ret void
}

LLVM IR (-O2):
@putchar.y = internal unnamed_addr global i32 0
@putchar.x = internal unnamed_addr global i32 0
define void @putchar(i8 signext %0) {
%2 = load i32, i32* @putchar.x
%3 = icmp sgt i32 %2, 159
%4 = sext i8 %0 to i16
%5 = icmp eq i8 %0, 10
%6 = or i1 %5, %3
br i1 %6, label %7, label %10
7: ; preds = %1
store i32 0, i32* @putchar.x
%8 = load i32, i32* @putchar.y
%9 = add nsw i32 %8, 1
store i32 %9, i32* @putchar.y
br label %12
10: ; preds = %1
%11 = load i32, i32* @putchar.y
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ %2, %10 ], [ 0, %7 ]
%14 = phi i32 [ %11, %10 ], [ %9, %7 ]
%15 = icmp sgt i32 %14, 24
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 0, i32* @putchar.y
br label %17
17: ; preds = %16, %12
%18 = phi i32 [ 0, %16 ], [ %14, %12 ]
%19 = mul nsw i32 %18, 160
%20 = add nsw i32 %19, 753664
br i1 %5, label %21, label %25
21: ; preds = %17
%22 = sext i32 %20 to i64
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @memsetw(i8* %23, i32 1824, i32 80)
br label %31
25: ; preds = %17
%26 = add nsw i32 %20, %13
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i16*
%29 = or i16 %4, 1792
store i16 %29, i16* %28
%30 = add nsw i32 %13, 2
store i32 %30, i32* @putchar.x
br label %31
31: ; preds = %25, %21
ret void
}