#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 */
unsigned long readVAC(int);
int /*<<< orphan*/ writeVAC(int, char);
int /*<<< orphan*/ writeVIC(int, int);
char c40_putchar(char ch) {
  int i;
  writeVIC(0x27, 0xa1);
  while (!(readVAC(0x25) & (unsigned long)0x100))
    ;
  while (!(readVAC(0x25) & (unsigned long)0x100))
    ;
  writeVAC(0x1E, ch << 8);
  for (i = 0; i < 100;)
    i++;
  writeVIC(0x27, 0x01);
  return (ch);
}


x86 assembly (clang, -O0):
<c40_putchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x27,%edi
mov    $0xa1,%esi
call   1050 <writeVIC@plt>
mov    $0x25,%edi
call   1030 <readVAC@plt>
and    $0x100,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1173 <c40_putchar+0x43>
jmp    1178 <c40_putchar+0x48>
jmp    114d <c40_putchar+0x1d>
jmp    117d <c40_putchar+0x4d>
mov    $0x25,%edi
call   1030 <readVAC@plt>
and    $0x100,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a3 <c40_putchar+0x73>
jmp    11a8 <c40_putchar+0x78>
jmp    117d <c40_putchar+0x4d>
movsbl -0x1(%rbp),%eax
shl    $0x8,%eax
mov    $0x1e,%edi
movsbl %al,%esi
call   1040 <writeVAC@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11db <c40_putchar+0xab>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c3 <c40_putchar+0x93>
mov    $0x27,%edi
mov    $0x1,%esi
call   1050 <writeVIC@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c40_putchar>:
push   %rbx
mov    %edi,%ebx
mov    $0x27,%edi
mov    $0xa1,%esi
call   1050 <writeVIC@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x25,%edi
call   1030 <readVAC@plt>
test   $0x100,%eax
je     1150 <c40_putchar+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x25,%edi
call   1030 <readVAC@plt>
test   $0x100,%eax
je     1170 <c40_putchar+0x40>
mov    $0x1e,%edi
xor    %esi,%esi
call   1040 <writeVAC@plt>
mov    $0x27,%edi
mov    $0x1,%esi
call   1050 <writeVIC@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @c40_putchar(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = call i32 @writeVIC(i32 39, i32 161)
br label %5
5: ; preds = %10, %1
%6 = call i64 @readVAC(i32 37)
%7 = and i64 %6, 256
%8 = icmp ne i64 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %11
10: ; preds = %5
br label %5
11: ; preds = %5
br label %12
12: ; preds = %17, %11
%13 = call i64 @readVAC(i32 37)
%14 = and i64 %13, 256
%15 = icmp ne i64 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = shl i32 %20, 8
%22 = trunc i32 %21 to i8
%23 = call i32 @writeVAC(i32 30, i8 signext %22)
store i32 0, i32* %3
br label %24
24: ; preds = %27, %18
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 100
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %24
30: ; preds = %24
%31 = call i32 @writeVIC(i32 39, i32 1)
%32 = load i8, i8* %2
ret i8 %32
}

LLVM IR (-O2):
define signext i8 @c40_putchar(i8 returned signext %0) {
%2 = tail call i32 @writeVIC(i32 39, i32 161)
br label %3
3: ; preds = %3, %1
%4 = tail call i64 @readVAC(i32 37)
%5 = and i64 %4, 256
%6 = icmp eq i64 %5, 0
br i1 %6, label %3, label %7
7: ; preds = %3, %7
%8 = tail call i64 @readVAC(i32 37)
%9 = and i64 %8, 256
%10 = icmp eq i64 %9, 0
br i1 %10, label %7, label %11
11: ; preds = %7
%12 = tail call i32 @writeVAC(i32 30, i8 signext 0)
%13 = tail call i32 @writeVIC(i32 39, i32 1)
ret i8 %0
}