#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*/ uart_putc(char);
int /*<<< orphan*/ uart_puts(char *);
unsigned char uart_getc(void) {
  char buffer[80];
  int i = 0;
  while (1) {
    while (1) {
      if ((*(volatile unsigned int *)(0x7F005010)) & 1)
        break;
    }
    buffer[i] = (*(volatile unsigned int *)(0x7F005024));
    if (buffer[i] == 8 && i > 0) {
      uart_putc(buffer[i--]);
      buffer[i] = ' ';
      uart_putc(buffer[i]);
      uart_putc(8);
      continue;
    } else if (buffer[i] == 8 && i == 0) {
      continue;
    }
    if (i != 79) {
      uart_putc(buffer[i]);
    } else if (i == 79 && buffer[i] == 0xD) {
      uart_puts("");
      return buffer[0];
    }
    if (i == 0 && buffer[i] == 0xD) {
      uart_puts("");
      return '\0';
    }
    if (i > 0 && buffer[i] == 0xD) {
      uart_puts("");
      return buffer[0];
    }
    if (++i == 80)
      i = 79;
  }
}


x86 assembly (clang, -O0):
<uart_getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x64(%rbp)
jmp    1134 <uart_getc+0x14>
mov    $0x7f005010,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     114c <uart_getc+0x2c>
jmp    1151 <uart_getc+0x31>
jmp    1134 <uart_getc+0x14>
mov    $0x7f005024,%eax
mov    (%rax),%eax
mov    %al,%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x60(%rbp,%rax,1)
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x8,%eax
jne    11bb <uart_getc+0x9b>
cmpl   $0x0,-0x64(%rbp)
jle    11bb <uart_getc+0x9b>
mov    -0x64(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x64(%rbp)
cltq
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <uart_putc@plt>
movslq -0x64(%rbp),%rax
movb   $0x20,-0x60(%rbp,%rax,1)
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <uart_putc@plt>
mov    $0x8,%edi
call   1030 <uart_putc@plt>
jmp    112f <uart_getc+0xf>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x8,%eax
jne    11dc <uart_getc+0xbc>
cmpl   $0x0,-0x64(%rbp)
jne    11dc <uart_getc+0xbc>
jmp    112f <uart_getc+0xf>
jmp    11e1 <uart_getc+0xc1>
cmpl   $0x4f,-0x64(%rbp)
je     11fe <uart_getc+0xde>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <uart_putc@plt>
jmp    1236 <uart_getc+0x116>
cmpl   $0x4f,-0x64(%rbp)
jne    1231 <uart_getc+0x111>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0xd,%eax
jne    1231 <uart_getc+0x111>
lea    0xddf(%rip),%rdi
call   1040 <uart_puts@plt>
mov    -0x60(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    12b8 <uart_getc+0x198>
jmp    1236 <uart_getc+0x116>
cmpl   $0x0,-0x64(%rbp)
jne    1267 <uart_getc+0x147>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0xd,%eax
jne    1267 <uart_getc+0x147>
lea    0xda7(%rip),%rdi
call   1040 <uart_puts@plt>
movb   $0x0,-0x1(%rbp)
jmp    12b8 <uart_getc+0x198>
cmpl   $0x0,-0x64(%rbp)
jle    129a <uart_getc+0x17a>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0xd,%eax
jne    129a <uart_getc+0x17a>
lea    0xd76(%rip),%rdi
call   1040 <uart_puts@plt>
mov    -0x60(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    12b8 <uart_getc+0x198>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
cmp    $0x50,%eax
jne    12b3 <uart_getc+0x193>
movl   $0x4f,-0x64(%rbp)
jmp    112f <uart_getc+0xf>
movzbl -0x1(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_getc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
xor    %ecx,%ecx
mov    $0x4f,%r14d
jmp    1166 <uart_getc+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebx
movsbl %bpl,%edi
call   1030 <uart_putc@plt>
movb   $0x20,(%rsp,%rbx,1)
mov    $0x20,%edi
call   1030 <uart_putc@plt>
mov    $0x8,%edi
call   1030 <uart_putc@plt>
mov    %ebx,%ecx
mov    %ecx,%ebx
nopl   0x0(%rax,%rax,1)
testl  $0x1,0x7f005010
je     1170 <uart_getc+0x50>
mov    0x7f005024,%ebp
movslq %ebx,%rax
mov    %bpl,(%rsp,%rax,1)
mov    %ebp,%eax
shl    $0x18,%eax
cmp    $0x8000000,%eax
jne    119b <uart_getc+0x7b>
test   %ebx,%ebx
jg     1140 <uart_getc+0x20>
cmp    $0x8000000,%eax
jne    11ab <uart_getc+0x8b>
mov    $0x0,%ecx
test   %ebx,%ebx
je     1166 <uart_getc+0x46>
cmp    $0x4f,%ebx
jne    11bd <uart_getc+0x9d>
cmp    $0xd000000,%eax
je     11eb <uart_getc+0xcb>
test   %ebx,%ebx
je     11ca <uart_getc+0xaa>
jmp    11d0 <uart_getc+0xb0>
movsbl %bpl,%edi
call   1030 <uart_putc@plt>
test   %ebx,%ebx
jne    11d0 <uart_getc+0xb0>
cmp    $0xd,%bpl
je     11fc <uart_getc+0xdc>
test   %ebx,%ebx
jle    11da <uart_getc+0xba>
cmp    $0xd,%bpl
je     11eb <uart_getc+0xcb>
add    $0x1,%ebx
cmp    $0x50,%ebx
cmove  %r14d,%ebx
mov    %ebx,%ecx
jmp    1166 <uart_getc+0x46>
lea    0xe0e(%rip),%rdi
call   1040 <uart_puts@plt>
mov    (%rsp),%al
jmp    120a <uart_getc+0xea>
lea    0xdfd(%rip),%rdi
call   1040 <uart_puts@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define zeroext i8 @uart_getc() {
%1 = alloca i8
%2 = alloca [80 x i8]
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %0, %26, %52, %109
br label %5
5: ; preds = %4, %10
%6 = load volatile i32, i32* inttoptr (i64 2130726928 to i32*)
%7 = and i32 %6, 1
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %5
br label %11
10: ; preds = %5
br label %5
11: ; preds = %9
%12 = load volatile i32, i32* inttoptr (i64 2130726948 to i32*)
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %15
store i8 %13, i8* %16
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 8
br i1 %22, label %23, label %42
23: ; preds = %11
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load i32, i32* %3
%28 = add nsw i32 %27, -1
store i32 %28, i32* %3
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @uart_putc(i8 signext %31)
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %34
store i8 32, i8* %35
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @uart_putc(i8 signext %39)
%41 = call i32 @uart_putc(i8 signext 8)
br label %4
42: ; preds = %23, %11
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 8
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* %3
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
br label %4
53: ; preds = %49, %42
br label %54
54: ; preds = %53
%55 = load i32, i32* %3
%56 = icmp ne i32 %55, 79
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i32, i32* %3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @uart_putc(i8 signext %61)
br label %78
63: ; preds = %54
%64 = load i32, i32* %3
%65 = icmp eq i32 %64, 79
br i1 %65, label %66, label %77
66: ; preds = %63
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 13
br i1 %72, label %73, label %77
73: ; preds = %66
%74 = call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%75 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%76 = load i8, i8* %75
store i8 %76, i8* %1
br label %110
77: ; preds = %66, %63
br label %78
78: ; preds = %77, %57
%79 = load i32, i32* %3
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %90
81: ; preds = %78
%82 = load i32, i32* %3
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 13
br i1 %87, label %88, label %90
88: ; preds = %81
%89 = call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %1
br label %110
90: ; preds = %81, %78
%91 = load i32, i32* %3
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %104
93: ; preds = %90
%94 = load i32, i32* %3
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp eq i32 %98, 13
br i1 %99, label %100, label %104
100: ; preds = %93
%101 = call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%102 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%103 = load i8, i8* %102
store i8 %103, i8* %1
br label %110
104: ; preds = %93, %90
%105 = load i32, i32* %3
%106 = add nsw i32 %105, 1
store i32 %106, i32* %3
%107 = icmp eq i32 %106, 80
br i1 %107, label %108, label %109
108: ; preds = %104
store i32 79, i32* %3
br label %109
109: ; preds = %108, %104
br label %4
110: ; preds = %100, %88, %73
%111 = load i8, i8* %1
ret i8 %111
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define zeroext i8 @uart_getc() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %25, %0
%4 = phi i32 [ 0, %0 ], [ %26, %25 ]
br label %5
5: ; preds = %5, %3
%6 = load volatile i32, i32* inttoptr (i64 2130726928 to i32*)
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %5, label %9
9: ; preds = %5
%10 = load volatile i32, i32* inttoptr (i64 2130726948 to i32*)
%11 = trunc i32 %10 to i8
%12 = sext i32 %4 to i64
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %12
store i8 %11, i8* %13
%14 = shl i32 %10, 24
%15 = icmp eq i32 %14, 134217728
%16 = icmp sgt i32 %4, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %27
18: ; preds = %9
%19 = add nsw i32 %4, -1
%20 = tail call i32 @uart_putc(i8 signext %11)
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %21
store i8 32, i8* %22
%23 = tail call i32 @uart_putc(i8 signext 32)
%24 = tail call i32 @uart_putc(i8 signext 8)
br label %25
25: ; preds = %18, %49, %27
%26 = phi i32 [ %19, %18 ], [ 0, %27 ], [ %52, %49 ]
br label %3
27: ; preds = %9
%28 = icmp eq i32 %4, 0
%29 = select i1 %15, i1 %28, i1 false
br i1 %29, label %25, label %30
30: ; preds = %27
%31 = icmp eq i32 %4, 79
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = tail call i32 @uart_putc(i8 signext %11)
br label %39
34: ; preds = %30
%35 = icmp eq i32 %14, 218103808
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = tail call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%38 = load i8, i8* %2
br label %53
39: ; preds = %34, %32
%40 = icmp eq i8 %11, 13
%41 = select i1 %28, i1 %40, i1 false
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = tail call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %53
44: ; preds = %39
%45 = select i1 %16, i1 %40, i1 false
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = tail call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%48 = load i8, i8* %2
br label %53
49: ; preds = %44
%50 = add nsw i32 %4, 1
%51 = icmp eq i32 %50, 80
%52 = select i1 %51, i32 79, i32 %50
br label %25
53: ; preds = %46, %42, %36
%54 = phi i8 [ 0, %42 ], [ %48, %46 ], [ %38, %36 ]
ret i8 %54
}