#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);
int c40_putchar(char ch) {
  writeVIC(0x27, 0xa1);
  while (!(readVAC(0x25) & (unsigned long)0x100))
    ;
  while (!(readVAC(0x25) & (unsigned long)0x100))
    ;
  writeVAC(0x1E, ch << 8);
  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>
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>
movsbl %bl,%ebx
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 i32 @c40_putchar(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = call i32 @writeVIC(i32 39, i32 161)
br label %4
4: ; preds = %9, %1
%5 = call i64 @readVAC(i32 37)
%6 = and i64 %5, 256
%7 = icmp ne i64 %6, 0
%8 = xor i1 %7, true
br i1 %8, label %9, label %10
9: ; preds = %4
br label %4
10: ; preds = %4
br label %11
11: ; preds = %16, %10
%12 = call i64 @readVAC(i32 37)
%13 = and i64 %12, 256
%14 = icmp ne i64 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %17
16: ; preds = %11
br label %11
17: ; preds = %11
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = shl i32 %19, 8
%21 = trunc i32 %20 to i8
%22 = call i32 @writeVAC(i32 30, i8 signext %21)
%23 = call i32 @writeVIC(i32 39, i32 1)
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
define i32 @c40_putchar(i8 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 = sext i8 %0 to i32
%13 = tail call i32 @writeVAC(i32 30, i8 signext 0)
%14 = tail call i32 @writeVIC(i32 39, i32 1)
ret i32 %12
}