#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 */
char *fgets(char *, int, int /*<<< orphan*/ *);
char *fgetsnolfs(char *buf, int n, FILE *fh) {
  char *in;
  char *tmp;
  in = fgets(buf, n, fh);
  if (!in)
    return 0;
  tmp = buf;
  while (*tmp) {
    if ((*tmp == '\n') || (*tmp == '\r')) {
      *tmp = 0;
      break;
    }
    tmp++;
  }
  return in;
}


x86 assembly (clang, -O0):
<fgetsnolfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    114f <fgetsnolfs+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <fgetsnolfs+0x99>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a1 <fgetsnolfs+0x91>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1184 <fgetsnolfs+0x74>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    1190 <fgetsnolfs+0x80>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a1 <fgetsnolfs+0x91>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <fgetsnolfs+0x47>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetsnolfs>:
push   %rbx
mov    %rdi,%rbx
call   1030 <fgets@plt>
test   %rax,%rax
je     113a <fgetsnolfs+0x2a>
xchg   %ax,%ax
movzbl (%rbx),%ecx
test   %cl,%cl
je     113a <fgetsnolfs+0x2a>
cmp    $0xd,%cl
je     1137 <fgetsnolfs+0x27>
cmp    $0xa,%cl
je     1137 <fgetsnolfs+0x27>
add    $0x1,%rbx
jmp    1120 <fgetsnolfs+0x10>
movb   $0x0,(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @fgetsnolfs(i8* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i8* @fgets(i8* %0, i32 %1, i32* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3, %10
%7 = phi i8* [ %11, %10 ], [ %0, %3 ]
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 0, label %12
i8 10, label %9
i8 13, label %9
]
9: ; preds = %6, %6
store i8 0, i8* %7
br label %12
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
12: ; preds = %6, %9, %3
ret i8* %4
}