#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*/ TCIFLUSH;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
void get_line(int ro_fd, char *type, char *line) {
  memset(line, 0, strlen(line));
  char c = '\0';
  int type_length = strlen(type);
  int i = 0;
  int n = 1;
  int reading_line = 0;
  for (n = 1; n >= 1; n = read(ro_fd, &c, 1)) {
    if (c == '$') {
      reading_line = 1;
    } else if (c == '\n' && reading_line) {
      break;
    } else if (reading_line) {
      if (i < type_length) {
        if (type[i] != c) {
          i = -1;
          reading_line = 0;
        }
      }
      line[i] = c;
      i++;
    }
  }
  tcflush(ro_fd, TCIFLUSH);
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jl     125c <get_line+0x11c>
movsbl -0x19(%rbp),%eax
cmp    $0x24,%eax
jne    11c0 <get_line+0x80>
movl   $0x1,-0x2c(%rbp)
jmp    123e <get_line+0xfe>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11dc <get_line+0x9c>
cmpl   $0x0,-0x2c(%rbp)
je     11dc <get_line+0x9c>
jmp    125c <get_line+0x11c>
cmpl   $0x0,-0x2c(%rbp)
je     1234 <get_line+0xf4>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    121d <get_line+0xdd>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     1218 <get_line+0xd8>
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    121d <get_line+0xdd>
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1239 <get_line+0xf9>
jmp    123e <get_line+0xfe>
jmp    1243 <get_line+0x103>
mov    -0x4(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
jmp    119d <get_line+0x5d>
mov    -0x4(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%ebx
mov    %rdx,%rdi
call   1030 <strlen@plt>
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
movb   $0x0,0xb(%rsp)
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xb(%rsp),%r13
xor    %r15d,%r15d
xor    %ebp,%ebp
cmp    $0x24,%r12b
jne    11b0 <get_line+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%r15d
jmp    1210 <get_line+0xd0>
nopl   0x0(%rax,%rax,1)
test   %r15d,%r15d
je     11bb <get_line+0x7b>
cmp    $0xa,%r12b
je     1233 <get_line+0xf3>
test   %r15d,%r15d
je     1200 <get_line+0xc0>
mov    $0x1,%r15d
cmp    0xc(%rsp),%ebp
jge    11e8 <get_line+0xa8>
movslq %ebp,%rax
xor    %r15d,%r15d
mov    0x10(%rsp),%rcx
cmp    %r12b,(%rcx,%rax,1)
sete   %al
je     11e5 <get_line+0xa5>
mov    $0xffffffff,%ebp
mov    %al,%r15b
movslq %ebp,%rbp
mov    %r12b,(%r14,%rbp,1)
add    $0x1,%ebp
jmp    1210 <get_line+0xd0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1233 <get_line+0xf3>
mov    0xb(%rsp),%r12b
cmp    $0x24,%r12b
jne    11b0 <get_line+0x70>
jmp    11a0 <get_line+0x60>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <tcflush@plt>

LLVM IR (-O0):
@TCIFLUSH = global i32 0
define void @get_line(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @memset(i8* %12, i32 0, i32 %14)
store i8 0, i8* %7
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
store i32 0, i32* %11
store i32 1, i32* %10
br label %18
18: ; preds = %64, %3
%19 = load i32, i32* %10
%20 = icmp sge i32 %19, 1
br i1 %20, label %21, label %67
21: ; preds = %18
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 36
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %11
br label %63
26: ; preds = %21
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
br label %67
34: ; preds = %30, %26
%35 = load i32, i32* %11
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %61
37: ; preds = %34
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %47, %49
br i1 %50, label %51, label %52
51: ; preds = %41
store i32 -1, i32* %9
store i32 0, i32* %11
br label %52
52: ; preds = %51, %41
br label %53
53: ; preds = %52, %37
%54 = load i8, i8* %7
%55 = load i8*, i8** %6
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 %54, i8* %58
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %61
61: ; preds = %53, %34
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62, %25
br label %64
64: ; preds = %63
%65 = load i32, i32* %4
%66 = call i32 @read(i32 %65, i8* %7, i32 1)
store i32 %66, i32* %10
br label %18
67: ; preds = %33, %18
%68 = load i32, i32* %4
%69 = load i32, i32* @TCIFLUSH
%70 = call i32 @tcflush(i32 %68, i32 %69)
ret void
}

LLVM IR (-O2):
@TCIFLUSH = global i32 0
define void @get_line(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8
%5 = tail call i32 @strlen(i8* %2)
%6 = tail call i32 @memset(i8* %2, i32 0, i32 %5)
store i8 0, i8* %4
%7 = tail call i32 @strlen(i8* %1)
br label %8
8: ; preds = %38, %3
%9 = phi i8 [ 0, %3 ], [ %39, %38 ]
%10 = phi i32 [ 0, %3 ], [ %35, %38 ]
%11 = phi i32 [ 0, %3 ], [ %34, %38 ]
%12 = icmp eq i8 %9, 36
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = icmp eq i8 %9, 10
%15 = icmp ne i32 %10, 0
%16 = and i1 %15, %14
br i1 %16, label %40, label %17
17: ; preds = %13
br i1 %15, label %18, label %33
18: ; preds = %17
%19 = icmp slt i32 %11, %7
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = sext i32 %11 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, %9
%25 = select i1 %24, i32 %11, i32 -1
%26 = zext i1 %24 to i32
br label %27
27: ; preds = %20, %18
%28 = phi i32 [ %11, %18 ], [ %25, %20 ]
%29 = phi i32 [ 1, %18 ], [ %26, %20 ]
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 %9, i8* %31
%32 = add nsw i32 %28, 1
br label %33
33: ; preds = %8, %17, %27
%34 = phi i32 [ %32, %27 ], [ %11, %17 ], [ %11, %8 ]
%35 = phi i32 [ %29, %27 ], [ 0, %17 ], [ 1, %8 ]
%36 = call i32 @read(i32 %0, i8* %4, i32 1)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i8, i8* %4
br label %8
40: ; preds = %13, %33
%41 = load i32, i32* @TCIFLUSH
%42 = tail call i32 @tcflush(i32 %0, i32 %41)
ret void
}