#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*/ *);
int /*<<< orphan*/ ibufclean(int /*<<< orphan*/ *);
char *strchr(char *, char);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
char *fgetline(char *line, int len, FILE *in) {
  char *tempp1, *tempp2;
  tempp1 = fgets(line, len, in);
  if ((tempp1 != NULL) && ((tempp2 = strchr(line, '\n')) != NULL)) {
    *tempp2 = (char)0;
    ungetc('\n', in);
  }
  ibufclean(in);
  return tempp1;
}


x86 assembly (clang, -O0):
<fgetline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a3 <fgetline+0x63>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11a3 <fgetline+0x63>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1060 <ungetc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ibufclean@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetline>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rdi,%rbx
call   1050 <fgets@plt>
mov    %rax,%r14
test   %rax,%rax
je     117a <fgetline+0x3a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117a <fgetline+0x3a>
movb   $0x0,(%rax)
mov    $0xa,%edi
mov    %r15,%rsi
call   1060 <ungetc@plt>
mov    %r15,%rdi
call   1030 <ibufclean@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @fgetline(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = load i32*, i32** %6
%12 = call i8* @fgets(i8* %9, i32 %10, i32* %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i8* @strchr(i8* %16, i8 signext 10)
store i8* %17, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8*, i8** %8
store i8 0, i8* %20
%21 = load i32*, i32** %6
%22 = call i32 @ungetc(i8 signext 10, i32* %21)
br label %23
23: ; preds = %19, %15, %3
%24 = load i32*, i32** %6
%25 = call i32 @ibufclean(i32* %24)
%26 = load i8*, i8** %7
ret i8* %26
}

LLVM IR (-O2):
define i8* @fgetline(i8* %0, i32 %1, i32* %2) {
%4 = tail call i8* @fgets(i8* %0, i32 %1, i32* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
store i8 0, i8* %7
%10 = tail call i32 @ungetc(i8 signext 10, i32* %2)
br label %11
11: ; preds = %9, %6, %3
%12 = tail call i32 @ibufclean(i32* %2)
ret i8* %4
}