#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 EOF;
int getch();
scalar_t__ isspace(int);
int /*<<< orphan*/ ungetch(int);
void get_rest_of_line(char *s, int lim) {
  int c;
  while ((c = getch()) != '\n' && isspace(c))
    ;
  while (--lim > 0 && c != '\n' && c != '\r' && c != EOF) {
    *s++ = c;
    c = getch();
  }
  *s = '\0';
  ungetch(c);
}


x86 assembly (clang, -O0):
<get_rest_of_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x11(%rbp)
je     116b <get_rest_of_line+0x3b>
mov    -0x10(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117b <get_rest_of_line+0x4b>
jmp    1180 <get_rest_of_line+0x50>
jmp    113f <get_rest_of_line+0xf>
jmp    1185 <get_rest_of_line+0x55>
mov    -0xc(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
jle    11cc <get_rest_of_line+0x9c>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x12(%rbp)
je     11cc <get_rest_of_line+0x9c>
xor    %eax,%eax
cmpl   $0xd,-0x10(%rbp)
mov    %al,-0x12(%rbp)
je     11cc <get_rest_of_line+0x9c>
mov    -0x10(%rbp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11dc <get_rest_of_line+0xac>
jmp    1201 <get_rest_of_line+0xd1>
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0x10(%rbp)
jmp    1185 <get_rest_of_line+0x55>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%edi
call   1040 <ungetch@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rest_of_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
cmp    $0xa,%eax
je     115a <get_rest_of_line+0x2a>
mov    %ebx,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    1140 <get_rest_of_line+0x10>
cmp    $0x2,%ebp
jl     1197 <get_rest_of_line+0x67>
add    $0x1,%ebp
mov    0x2e7f(%rip),%r15
nopl   0x0(%rax)
cmp    $0xa,%ebx
je     1197 <get_rest_of_line+0x67>
cmp    $0xd,%ebx
je     1197 <get_rest_of_line+0x67>
cmp    (%r15),%ebx
je     1197 <get_rest_of_line+0x67>
mov    %bl,(%r14)
add    $0x1,%r14
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1170 <get_rest_of_line+0x40>
movb   $0x0,(%r14)
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ungetch@plt>

LLVM IR (-O0):
@EOF = global i32 0
define void @get_rest_of_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %15, %2
%7 = call i32 (...) @getch()
store i32 %7, i32* %5
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %5
%11 = call i64 @isspace(i32 %10)
%12 = icmp ne i64 %11, 0
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %16
15: ; preds = %13
br label %6
16: ; preds = %13
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, -1
store i32 %19, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 10
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 13
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %5
%29 = load i32, i32* @EOF
%30 = icmp ne i32 %28, %29
br label %31
31: ; preds = %27, %24, %21, %17
%32 = phi i1 [ false, %24 ], [ false, %21 ], [ false, %17 ], [ %30, %27 ]
br i1 %32, label %33, label %39
33: ; preds = %31
%34 = load i32, i32* %5
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
store i8 %35, i8* %36
%38 = call i32 (...) @getch()
store i32 %38, i32* %5
br label %17
39: ; preds = %31
%40 = load i8*, i8** %3
store i8 0, i8* %40
%41 = load i32, i32* %5
%42 = call i32 @ungetch(i32 %41)
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @get_rest_of_line(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %6, %2
%4 = tail call i32 (...) @getch()
%5 = icmp eq i32 %4, 10
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i64 @isspace(i32 %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %3
9: ; preds = %3, %6
%10 = icmp sgt i32 %1, 1
br i1 %10, label %11, label %24
11: ; preds = %9, %19
%12 = phi i32 [ %15, %19 ], [ %1, %9 ]
%13 = phi i32 [ %22, %19 ], [ %4, %9 ]
%14 = phi i8* [ %21, %19 ], [ %0, %9 ]
%15 = add nsw i32 %12, -1
switch i32 %13, label %16 [
i32 13, label %24
i32 10, label %24
]
16: ; preds = %11
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %13, %17
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = trunc i32 %13 to i8
%21 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %20, i8* %14
%22 = tail call i32 (...) @getch()
%23 = icmp ugt i32 %12, 2
br i1 %23, label %11, label %24
24: ; preds = %16, %19, %11, %11, %9
%25 = phi i8* [ %0, %9 ], [ %14, %11 ], [ %14, %11 ], [ %21, %19 ], [ %14, %16 ]
%26 = phi i32 [ %4, %9 ], [ %13, %11 ], [ %13, %11 ], [ %22, %19 ], [ %13, %16 ]
store i8 0, i8* %25
%27 = tail call i32 @ungetch(i32 %26)
ret void
}