#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 */
scalar_t__ read(int, char *, int);
int get_line(int fd, char *buff) {
  int i = 0;
  char ch = 'a';
  while (read(fd, &ch, 1) > 0) {
    if (!ch || ch == '\n' || ch == '\r')
      break;
    buff[i++] = ch;
  }
  buff[i] = 0;
  return i - 1;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x61,-0x15(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jle    118b <get_line+0x7b>
cmpb   $0x0,-0x15(%rbp)
je     1169 <get_line+0x59>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     1169 <get_line+0x59>
movsbl -0x15(%rbp),%eax
cmp    $0xd,%eax
jne    116e <get_line+0x5e>
jmp    118b <get_line+0x7b>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    112a <get_line+0x1a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0x61,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    117d <get_line+0x6d>
lea    0xf(%rsp),%r15
mov    $0x2401,%r12d
jmp    116c <get_line+0x5c>
nopl   0x0(%rax)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jle    117d <get_line+0x6d>
movzbl 0xf(%rsp),%eax
cmp    $0xd,%rax
ja     1150 <get_line+0x40>
bt     %rax,%r12
jae    1150 <get_line+0x40>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
add    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_line(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i8 97, i8* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %3
%9 = call i64 @read(i32 %8, i8* %6, i32 1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i8, i8* %6
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 13
br i1 %21, label %22, label %23
22: ; preds = %18, %14, %11
br label %30
23: ; preds = %18
%24 = load i8, i8* %6
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
br label %7
30: ; preds = %22, %7
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 1
ret i32 %36
}

LLVM IR (-O2):
define i32 @get_line(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i8
store i8 97, i8* %3
%4 = call i64 @read(i32 %0, i8* %3, i32 1)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %2, %9
%7 = phi i64 [ %10, %9 ], [ 0, %2 ]
%8 = load i8, i8* %3
switch i8 %8, label %9 [
i8 13, label %14
i8 10, label %14
i8 0, label %14
]
9: ; preds = %6
%10 = add nuw i64 %7, 1
%11 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %8, i8* %11
%12 = call i64 @read(i32 %0, i8* %3, i32 1)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %6, %6, %9
%15 = phi i64 [ %10, %9 ], [ %7, %6 ], [ %7, %6 ], [ %7, %6 ]
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %14, %2
%18 = phi i32 [ 0, %2 ], [ %16, %14 ]
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 0, i8* %20
%21 = add nsw i32 %18, -1
ret i32 %21
}