#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 */
typedef char uint8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, char *);
int ece391_open(char *);
int /*<<< orphan*/ ece391_read(int, int *, int);
int ece391_write(int, int *, int);
int main() {
  int32_t i = 0;
  int32_t j = 0;
  uint8_t curchar = 'A';
  uint8_t update = 1;
  int ret_val;
  int garbage;
  int rtc_fd;
  uint8_t buf[79 + 2];
  for (i = 0; i < 79 + 2; i++)
    buf[i] = ' ';
  buf[79 + 2 - 1] = '\0';
  buf[79 + 2 - 2] = '\n';
  buf[79 + 2 - 3] = '|';
  buf[1] = '|';
  rtc_fd = ece391_open((uint8_t *)"rtc");
  ret_val = 32;
  ret_val = ece391_write(rtc_fd, &ret_val, 4);
  while (1) {
    for (j = 1 + 1; j < 79 + 2 - 2 - 1; j++) {
      for (i = 1 + 1; i < 79 + 2 - 2 - 1; i++) {
        buf[i] = ' ';
      }
      buf[j] = curchar;
      ece391_fdputs(1, buf);
      ece391_read(rtc_fd, &garbage, 4);
    }
    for (j = 79 + 2 - 2 - 1 - 1; j >= 1 + 1; j--) {
      for (i = 1 + 1; i < 79 + 2 - 2 - 1; i++) {
        buf[i] = ' ';
      }
      buf[j] = curchar;
      ece391_fdputs(1, buf);
      ece391_read(rtc_fd, &garbage, 4);
    }
    if (curchar == 'Z') {
      curchar = 'A';
    } else {
      curchar = curchar + update;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x41,-0xd(%rbp)
movb   $0x1,-0xe(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x51,-0x8(%rbp)
jge    118d <main+0x4d>
movslq -0x8(%rbp),%rax
movb   $0x20,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x2c>
movb   $0x0,-0x20(%rbp)
movb   $0xa,-0x21(%rbp)
movb   $0x7c,-0x22(%rbp)
movb   $0x7c,-0x6f(%rbp)
lea    0xe5c(%rip),%rdi
call   1060 <ece391_open@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x20,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <ece391_write@plt>
mov    %eax,-0x14(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x4e,-0xc(%rbp)
jge    1238 <main+0xf8>
movl   $0x2,-0x8(%rbp)
cmpl   $0x4e,-0x8(%rbp)
jge    1200 <main+0xc0>
movslq -0x8(%rbp),%rax
movb   $0x20,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11df <main+0x9f>
mov    -0xd(%rbp),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <ece391_read@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ce <main+0x8e>
movl   $0x4d,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     12a9 <main+0x169>
movl   $0x2,-0x8(%rbp)
cmpl   $0x4e,-0x8(%rbp)
jge    1271 <main+0x131>
movslq -0x8(%rbp),%rax
movb   $0x20,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1250 <main+0x110>
mov    -0xd(%rbp),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <ece391_read@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    123f <main+0xff>
movsbl -0xd(%rbp),%eax
cmp    $0x5a,%eax
jne    12bf <main+0x17f>
movb   $0x41,-0xd(%rbp)
jmp    12cc <main+0x18c>
movsbl -0xd(%rbp),%eax
movsbl -0xe(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0xd(%rbp)
jmp    11c7 <main+0x87>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movaps 0xeab(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x60(%rsp)
movw   $0xa7c,0x5e(%rsp)
movb   $0x7c,0x11(%rsp)
lea    0xe9e(%rip),%rdi
call   1060 <ece391_open@plt>
mov    %eax,%ebp
movl   $0x20,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <ece391_write@plt>
mov    %eax,0x8(%rsp)
mov    $0x41,%r14b
lea    0x12(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%rax
mov    %r15,%r12
mov    %rax,%r15
mov    $0x2,%r13d
movaps 0xe3a(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
movups %xmm0,0x3c(%rbx)
movups %xmm0,0x30(%rbx)
movups %xmm0,0x20(%rbx)
movups %xmm0,0x10(%rbx)
movups %xmm0,(%rbx)
mov    %r14b,0x10(%rsp,%r13,1)
mov    $0x1,%edi
mov    %r15,%rsi
call   1030 <ece391_fdputs@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <ece391_read@plt>
movaps 0xdf5(%rip),%xmm0
add    $0x1,%r13
cmp    $0x4e,%r13
jne    11d0 <main+0x90>
mov    %ebp,%r13d
mov    $0x4e,%ebp
mov    %r15,%rax
mov    %r12,%r15
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
movups %xmm0,0x3c(%rbx)
movups %xmm0,0x30(%rbx)
movups %xmm0,0x20(%rbx)
movups %xmm0,0x10(%rbx)
movups %xmm0,(%rbx)
mov    %r14b,0xf(%rsp,%rbp,1)
mov    $0x1,%edi
mov    %r12,%rsi
call   1030 <ece391_fdputs@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <ece391_read@plt>
movaps 0xd94(%rip),%xmm0
add    $0xffffffffffffffff,%rbp
cmp    $0x2,%rbp
ja     1230 <main+0xf0>
lea    0x1(%r14),%eax
cmp    $0x5a,%r14b
movzbl %al,%r14d
mov    $0x41,%eax
cmove  %eax,%r14d
mov    %r13d,%ebp
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [4 x i8] c"rtc\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [81 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i8 65, i8* %4
store i8 1, i8* %5
store i32 0, i32* %2
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 81
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 %15
store i8 32, i8* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %10
20: ; preds = %10
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 80
store i8 0, i8* %21
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 79
store i8 10, i8* %22
%23 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 78
store i8 124, i8* %23
%24 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 1
store i8 124, i8* %24
%25 = call i32 @ece391_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %25, i32* %8
store i32 32, i32* %6
%26 = load i32, i32* %8
%27 = call i32 @ece391_write(i32 %26, i32* %6, i32 4)
store i32 %27, i32* %6
br label %28
28: ; preds = %20, %94
store i32 2, i32* %3
br label %29
29: ; preds = %52, %28
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 78
br i1 %31, label %32, label %55
32: ; preds = %29
store i32 2, i32* %2
br label %33
33: ; preds = %40, %32
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 78
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 %38
store i8 32, i8* %39
br label %40
40: ; preds = %36
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %33
43: ; preds = %33
%44 = load i8, i8* %4
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 %46
store i8 %44, i8* %47
%48 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%49 = call i32 @ece391_fdputs(i32 1, i8* %48)
%50 = load i32, i32* %8
%51 = call i32 @ece391_read(i32 %50, i32* %7, i32 4)
br label %52
52: ; preds = %43
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %29
55: ; preds = %29
store i32 77, i32* %3
br label %56
56: ; preds = %79, %55
%57 = load i32, i32* %3
%58 = icmp sge i32 %57, 2
br i1 %58, label %59, label %82
59: ; preds = %56
store i32 2, i32* %2
br label %60
60: ; preds = %67, %59
%61 = load i32, i32* %2
%62 = icmp slt i32 %61, 78
br i1 %62, label %63, label %70
63: ; preds = %60
%64 = load i32, i32* %2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 %65
store i8 32, i8* %66
br label %67
67: ; preds = %63
%68 = load i32, i32* %2
%69 = add nsw i32 %68, 1
store i32 %69, i32* %2
br label %60
70: ; preds = %60
%71 = load i8, i8* %4
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 %73
store i8 %71, i8* %74
%75 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%76 = call i32 @ece391_fdputs(i32 1, i8* %75)
%77 = load i32, i32* %8
%78 = call i32 @ece391_read(i32 %77, i32* %7, i32 4)
br label %79
79: ; preds = %70
%80 = load i32, i32* %3
%81 = add nsw i32 %80, -1
store i32 %81, i32* %3
br label %56
82: ; preds = %56
%83 = load i8, i8* %4
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 90
br i1 %85, label %86, label %87
86: ; preds = %82
store i8 65, i8* %4
br label %94
87: ; preds = %82
%88 = load i8, i8* %4
%89 = sext i8 %88 to i32
%90 = load i8, i8* %5
%91 = sext i8 %90 to i32
%92 = add nsw i32 %89, %91
%93 = trunc i32 %92 to i8
store i8 %93, i8* %4
br label %94
94: ; preds = %87, %86
br label %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"rtc\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 80
store i8 0, i8* %8
%9 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 79
store i8 10, i8* %9
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 78
store i8 124, i8* %10
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 1
store i8 124, i8* %11
%12 = tail call i32 @ece391_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 32, i32* %1
%13 = call i32 @ece391_write(i32 %12, i32* %1, i32 4)
store i32 %13, i32* %1
%14 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 2
br label %15
15: ; preds = %31, %0
%16 = phi i8 [ 65, %0 ], [ %34, %31 ]
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 2, %15 ], [ %22, %17 ]
%19 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %18
store i8 %16, i8* %19
%20 = call i32 @ece391_fdputs(i32 1, i8* %7)
%21 = call i32 @ece391_read(i32 %12, i32* %2, i32 4)
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, 78
br i1 %23, label %24, label %17
24: ; preds = %17, %24
%25 = phi i64 [ %29, %24 ], [ 77, %17 ]
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %25
store i8 %16, i8* %26
%27 = call i32 @ece391_fdputs(i32 1, i8* %7)
%28 = call i32 @ece391_read(i32 %12, i32* %2, i32 4)
%29 = add nsw i64 %25, -1
%30 = icmp ugt i64 %25, 2
br i1 %30, label %24, label %31
31: ; preds = %24
%32 = icmp eq i8 %16, 90
%33 = add i8 %16, 1
%34 = select i1 %32, i8 65, i8 %33
br label %15
}