#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 PutString(char *);
unsigned char UartRx();
int /*<<< orphan*/ UartTx(unsigned char);
int GetLine(char *line, int size) {
  int cnt;
  unsigned char ch;
  cnt = PutString(line);
  line += cnt;
  for (;;) {
    if (cnt > size - 1)
      break;
    while ((ch = UartRx()) == 0 || ch == 32)
      ;
    if (ch == 8) {
      if (cnt) {
        UartTx(ch);
        UartTx(' ');
        UartTx(ch);
        cnt--;
        line--;
      }
    } else if (ch < 32) {
      break;
    } else {
      UartTx(ch);
      *line++ = ch;
      cnt++;
    }
  }
  *line = 0;
  PutString("\n");
  return cnt;
}


x86 assembly (clang, -O0):
<GetLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <PutString@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1172 <GetLine+0x42>
jmp    1243 <GetLine+0x113>
jmp    1177 <GetLine+0x47>
mov    $0x0,%al
call   1030 <UartRx@plt>
mov    %al,-0x11(%rbp)
movzbl %al,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
je     119f <GetLine+0x6f>
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11af <GetLine+0x7f>
jmp    11b4 <GetLine+0x84>
jmp    1177 <GetLine+0x47>
movzbl -0x11(%rbp),%eax
cmp    $0x8,%eax
jne    1201 <GetLine+0xd1>
cmpl   $0x0,-0x10(%rbp)
je     11fc <GetLine+0xcc>
movzbl -0x11(%rbp),%edi
call   1050 <UartTx@plt>
mov    $0x20,%edi
call   1050 <UartTx@plt>
movzbl -0x11(%rbp),%edi
call   1050 <UartTx@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    123e <GetLine+0x10e>
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jge    1213 <GetLine+0xe3>
jmp    1243 <GetLine+0x113>
movzbl -0x11(%rbp),%edi
call   1050 <UartTx@plt>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    123e <GetLine+0x10e>
jmp    115c <GetLine+0x2c>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
lea    0xdaf(%rip),%rdi
call   1040 <PutString@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <PutString@plt>
mov    %eax,%ebp
cltq
add    %rax,%r15
cmp    %r14d,%eax
jl     11a0 <GetLine+0x70>
movb   $0x0,(%r15)
lea    0xea7(%rip),%rdi
call   1040 <PutString@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
je     11ca <GetLine+0x9a>
mov    $0x8,%edi
call   1050 <UartTx@plt>
mov    $0x20,%edi
call   1050 <UartTx@plt>
mov    $0x8,%edi
call   1050 <UartTx@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%r15
cmp    %r14d,%ebp
jge    114e <GetLine+0x1e>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <UartRx@plt>
test   $0xdf,%al
je     11a0 <GetLine+0x70>
mov    %eax,%ebx
cmp    $0x8,%al
je     116b <GetLine+0x3b>
cmp    $0x20,%bl
jb     114e <GetLine+0x1e>
movzbl %bl,%edi
call   1050 <UartTx@plt>
mov    %bl,(%r15)
add    $0x1,%r15
add    $0x1,%ebp
jmp    1194 <GetLine+0x64>
xor    %ebp,%ebp
jmp    1194 <GetLine+0x64>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @GetLine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @PutString(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i8*, i8** %3
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %3
br label %13
13: ; preds = %63, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = icmp sgt i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %13
br label %64
19: ; preds = %13
br label %20
20: ; preds = %30, %19
%21 = call zeroext i8 (...) @UartRx()
store i8 %21, i8* %6
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br label %28
28: ; preds = %24, %20
%29 = phi i1 [ true, %20 ], [ %27, %24 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %20
31: ; preds = %28
%32 = load i8, i8* %6
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %33, 8
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i8, i8* %6
%40 = call i32 @UartTx(i8 zeroext %39)
%41 = call i32 @UartTx(i8 zeroext 32)
%42 = load i8, i8* %6
%43 = call i32 @UartTx(i8 zeroext %42)
%44 = load i32, i32* %5
%45 = add nsw i32 %44, -1
store i32 %45, i32* %5
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %3
br label %48
48: ; preds = %38, %35
br label %63
49: ; preds = %31
%50 = load i8, i8* %6
%51 = zext i8 %50 to i32
%52 = icmp slt i32 %51, 32
br i1 %52, label %53, label %54
53: ; preds = %49
br label %64
54: ; preds = %49
%55 = load i8, i8* %6
%56 = call i32 @UartTx(i8 zeroext %55)
%57 = load i8, i8* %6
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %3
store i8 %57, i8* %58
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %62
62: ; preds = %54
br label %63
63: ; preds = %62, %48
br label %13
64: ; preds = %53, %18
%65 = load i8*, i8** %3
store i8 0, i8* %65
%66 = call i32 @PutString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @GetLine(i8* %0, i32 %1) {
%3 = tail call i32 @PutString(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = icmp slt i32 %3, %1
br i1 %6, label %7, label %34
7: ; preds = %2, %30
%8 = phi i8* [ %32, %30 ], [ %5, %2 ]
%9 = phi i32 [ %31, %30 ], [ %3, %2 ]
br label %10
10: ; preds = %7, %10
%11 = tail call zeroext i8 (...) @UartRx()
%12 = and i8 %11, -33
%13 = icmp eq i8 %12, 0
br i1 %13, label %10, label %14
14: ; preds = %10
%15 = icmp eq i8 %11, 8
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = icmp eq i32 %9, 0
br i1 %17, label %30, label %18
18: ; preds = %16
%19 = tail call i32 @UartTx(i8 zeroext 8)
%20 = tail call i32 @UartTx(i8 zeroext 32)
%21 = tail call i32 @UartTx(i8 zeroext 8)
%22 = add nsw i32 %9, -1
%23 = getelementptr inbounds i8, i8* %8, i64 -1
br label %30
24: ; preds = %14
%25 = icmp ult i8 %11, 32
br i1 %25, label %34, label %26
26: ; preds = %24
%27 = tail call i32 @UartTx(i8 zeroext %11)
%28 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %11, i8* %8
%29 = add nsw i32 %9, 1
br label %30
30: ; preds = %16, %18, %26
%31 = phi i32 [ %22, %18 ], [ 0, %16 ], [ %29, %26 ]
%32 = phi i8* [ %23, %18 ], [ %8, %16 ], [ %28, %26 ]
%33 = icmp slt i32 %31, %1
br i1 %33, label %7, label %34
34: ; preds = %30, %24, %2
%35 = phi i32 [ %3, %2 ], [ %9, %24 ], [ %31, %30 ]
%36 = phi i8* [ %5, %2 ], [ %8, %24 ], [ %32, %30 ]
store i8 0, i8* %36
%37 = tail call i32 @PutString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i32 %35
}