#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 */
char SER_GetChar();
int /*<<< orphan*/ putchar(char);
void getline(char *line, int n) {
  int cnt = 0;
  char c;
  do {
    if ((c = SER_GetChar()) == 0x0D)
      c = 0x0A;
    if (c == 0x08 || c == 0x7F) {
      if (cnt != 0) {
        cnt--;
        line--;
        putchar(0x08);
        putchar(' ');
        putchar(0x08);
      }
    } else if (c != 0x11 && c != 0x13) {
      putchar(*line = c);
      line++;
      cnt++;
    }
  } while (cnt < n - 1 && c != 0x0A);
  *(line - 1) = 0;
}


x86 assembly (clang, -O0):
<getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <SER_GetChar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xd,%eax
jne    1150 <getline+0x30>
movb   $0xa,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x8,%eax
je     116a <getline+0x4a>
movsbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
jne    11ac <getline+0x8c>
cmpl   $0x0,-0x10(%rbp)
je     11a7 <getline+0x87>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11f1 <getline+0xd1>
movsbl -0x11(%rbp),%eax
cmp    $0x11,%eax
je     11ec <getline+0xcc>
movsbl -0x11(%rbp),%eax
cmp    $0x13,%eax
je     11ec <getline+0xcc>
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f1 <getline+0xd1>
jmp    11f6 <getline+0xd6>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x12(%rbp)
jge    1219 <getline+0xf9>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1136 <getline+0x16>
mov    -0x8(%rbp),%rax
movb   $0x0,-0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
add    $0xffffffff,%r15d
mov    $0xa,%r14d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <SER_GetChar@plt>
cmp    $0xd,%al
movzbl %al,%ebx
cmove  %r14d,%ebx
cmp    $0x7f,%bl
je     115a <getline+0x3a>
cmp    $0x8,%bl
jne    1190 <getline+0x70>
test   %ebp,%ebp
je     11b0 <getline+0x90>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%r12
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11b2 <getline+0x92>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
and    $0xfd,%al
cmp    $0x11,%al
je     11b2 <getline+0x92>
mov    %bl,(%r12)
movsbl %bl,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    $0x1,%ebp
jmp    11b2 <getline+0x92>
nopl   (%rax)
xor    %ebp,%ebp
cmp    %r15d,%ebp
jge    11bc <getline+0x9c>
cmp    $0xa,%bl
jne    1140 <getline+0x20>
movb   $0x0,-0x1(%r12)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @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
store i32 0, i32* %5
br label %7
7: ; preds = %59, %2
%8 = call signext i8 (...) @SER_GetChar()
store i8 %8, i8* %6
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 13
br i1 %10, label %11, label %12
11: ; preds = %7
store i8 10, i8* %6
br label %12
12: ; preds = %11, %7
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 8
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 127
br i1 %19, label %20, label %32
20: ; preds = %16, %12
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
store i32 %25, i32* %5
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %3
%28 = call i32 @putchar(i8 signext 8)
%29 = call i32 @putchar(i8 signext 32)
%30 = call i32 @putchar(i8 signext 8)
br label %31
31: ; preds = %23, %20
br label %49
32: ; preds = %16
%33 = load i8, i8* %6
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 17
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 19
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load i8, i8* %6
%42 = load i8*, i8** %3
store i8 %41, i8* %42
%43 = call i32 @putchar(i8 signext %41)
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %3
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %48
48: ; preds = %40, %36, %32
br label %49
49: ; preds = %48, %31
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = load i32, i32* %4
%53 = sub nsw i32 %52, 1
%54 = icmp slt i32 %51, %53
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i8, i8* %6
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 10
br label %59
59: ; preds = %55, %50
%60 = phi i1 [ false, %50 ], [ %58, %55 ]
br i1 %60, label %7, label %61
61: ; preds = %59
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i64 -1
store i8 0, i8* %63
ret void
}

LLVM IR (-O2):
define void @getline(i8* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
br label %4
4: ; preds = %25, %2
%5 = phi i8* [ %0, %2 ], [ %26, %25 ]
%6 = phi i32 [ 0, %2 ], [ %27, %25 ]
%7 = tail call signext i8 (...) @SER_GetChar()
%8 = icmp eq i8 %7, 13
%9 = select i1 %8, i8 10, i8 %7
switch i8 %9, label %18 [
i8 127, label %10
i8 8, label %10
]
10: ; preds = %4, %4
%11 = icmp eq i32 %6, 0
br i1 %11, label %25, label %12
12: ; preds = %10
%13 = add nsw i32 %6, -1
%14 = getelementptr inbounds i8, i8* %5, i64 -1
%15 = tail call i32 @putchar(i8 signext 8)
%16 = tail call i32 @putchar(i8 signext 32)
%17 = tail call i32 @putchar(i8 signext 8)
br label %25
18: ; preds = %4
%19 = and i8 %9, -3
%20 = icmp eq i8 %19, 17
br i1 %20, label %25, label %21
21: ; preds = %18
store i8 %9, i8* %5
%22 = tail call i32 @putchar(i8 signext %9)
%23 = getelementptr inbounds i8, i8* %5, i64 1
%24 = add nsw i32 %6, 1
br label %25
25: ; preds = %12, %10, %21, %18
%26 = phi i8* [ %14, %12 ], [ %5, %10 ], [ %23, %21 ], [ %5, %18 ]
%27 = phi i32 [ %13, %12 ], [ 0, %10 ], [ %24, %21 ], [ %6, %18 ]
%28 = icmp slt i32 %27, %3
%29 = icmp ne i8 %9, 10
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %4, label %31
31: ; preds = %25
%32 = getelementptr inbounds i8, i8* %26, i64 -1
store i8 0, i8* %32
ret void
}