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

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
char *inchi_fgetsLf(char *line, int line_len, FILE *inp) {
  char *p, *q;
  memset(line, 0, line_len);
  if (NULL != (p = fgets(line, line_len, inp)) && NULL == strchr(p, '\n')) {
    char temp[64];
    while (NULL != fgets(temp, sizeof(temp), inp) && NULL == strchr(temp, '\n'))
      ;
  }
  if (p && (q = strchr(line, '\r'))) {
    q[0] = '\n';
    q[1] = '\0';
  }
  return p;
}


x86 assembly (clang, -O0):
<inchi_fgetsLf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11f2 <inchi_fgetsLf+0xc2>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11f2 <inchi_fgetsLf+0xc2>
jmp    1197 <inchi_fgetsLf+0x67>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
mov    %rax,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x71(%rbp)
je     11d8 <inchi_fgetsLf+0xa8>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    11e8 <inchi_fgetsLf+0xb8>
jmp    11ed <inchi_fgetsLf+0xbd>
jmp    1197 <inchi_fgetsLf+0x67>
jmp    11f2 <inchi_fgetsLf+0xc2>
cmpq   $0x0,-0x20(%rbp)
je     1228 <inchi_fgetsLf+0xf8>
mov    -0x8(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1228 <inchi_fgetsLf+0xf8>
mov    -0x28(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inchi_fgetsLf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,%r14
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
mov    %rax,%r15
test   %rax,%rax
je     11be <inchi_fgetsLf+0x8e>
mov    %r15,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    11a7 <inchi_fgetsLf+0x77>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a7 <inchi_fgetsLf+0x77>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1180 <inchi_fgetsLf+0x50>
mov    %r14,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11be <inchi_fgetsLf+0x8e>
movw   $0xa,(%rax)
mov    %r15,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @inchi_fgetsLf(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [64 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i32 @memset(i8* %10, i32 0, i32 %11)
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = load i32*, i32** %6
%16 = call i8* @fgets(i8* %13, i32 %14, i32* %15)
store i8* %16, i8** %7
%17 = icmp ne i8* null, %16
br i1 %17, label %18, label %36
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = call i8* @strchr(i8* %19, i8 signext 10)
%21 = icmp eq i8* null, %20
br i1 %21, label %22, label %36
22: ; preds = %18
br label %23
23: ; preds = %34, %22
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i8* @fgets(i8* %24, i32 64, i32* %25)
%27 = icmp ne i8* null, %26
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%30 = call i8* @strchr(i8* %29, i8 signext 10)
%31 = icmp eq i8* null, %30
br label %32
32: ; preds = %28, %23
%33 = phi i1 [ false, %23 ], [ %31, %28 ]
br i1 %33, label %34, label %35
34: ; preds = %32
br label %23
35: ; preds = %32
br label %36
36: ; preds = %35, %18, %3
%37 = load i8*, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = load i8*, i8** %4
%41 = call i8* @strchr(i8* %40, i8 signext 13)
store i8* %41, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 10, i8* %45
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8 0, i8* %47
br label %48
48: ; preds = %43, %39, %36
%49 = load i8*, i8** %7
ret i8* %49
}

LLVM IR (-O2):
define i8* @inchi_fgetsLf(i8* %0, i32 %1, i32* nocapture %2) {
%4 = alloca [64 x i8]
%5 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%6 = tail call i8* @fgets(i8* %0, i32 %1, i32* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %25, label %8
8: ; preds = %3
%9 = tail call i8* @strchr(i8* %6, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
br label %13
13: ; preds = %16, %11
%14 = call i8* @fgets(i8* %12, i32 64, i32* %2)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i8* @strchr(i8* %12, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %13, label %19
19: ; preds = %13, %16
br label %20
20: ; preds = %8, %19
%21 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 13)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
store i8 10, i8* %21
%24 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %24
br label %25
25: ; preds = %3, %23, %20
ret i8* %6
}