#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgetc(int /*<<< orphan*/ *);
void _read_line(char *ptr, int len, FILE *handle) {
  int i;
  char reads;
  for (i = 0; i < len; i++) {
    ptr[i] = '\0';
  }
  for (i = 0; i < len; i++) {
    reads = (char)fgetc(handle);
    if (reads == '\n') {
      ptr[i] = '\0';
      break;
    }
    ptr[i] = reads;
  }
}


x86 assembly (clang, -O0):
<_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1150 <_read_line+0x40>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <_read_line+0x1a>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <_read_line+0x99>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    118d <_read_line+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a9 <_read_line+0x99>
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <_read_line+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1170 <_read_line+0x50>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
je     116b <_read_line+0x4b>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <_read_line+0x30>
jmp    1170 <_read_line+0x50>
movb   $0x0,(%r15,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @_read_line(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %9
9: ; preds = %18, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %9
21: ; preds = %9
store i32 0, i32* %7
br label %22
22: ; preds = %44, %21
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %22
%27 = load i32*, i32** %6
%28 = call i64 @fgetc(i32* %27)
%29 = trunc i64 %28 to i8
store i8 %29, i8* %8
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
br label %47
38: ; preds = %26
%39 = load i8, i8* %8
%40 = load i8*, i8** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %38
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %22
47: ; preds = %33, %22
ret void
}

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