#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*/ *);
size_t strlen(char *);
char *file_list_fgets(char *buf, int size, FILE *file) {
  char *status = fgets(buf, size, file);
  if (status) {
    size_t length = strlen(buf);
    if (buf[length - 1] == '\n')
      buf[length - 1] = '\0';
  }
  return status;
}


x86 assembly (clang, -O0):
<file_list_fgets>:
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   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118d <file_list_fgets+0x6d>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1188 <file_list_fgets+0x68>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    118d <file_list_fgets+0x6d>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_list_fgets>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <fgets@plt>
mov    %rax,%r14
test   %rax,%rax
je     1148 <file_list_fgets+0x28>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1148 <file_list_fgets+0x28>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @file_list_fgets(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
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 %31
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %8
%18 = load i8*, i8** %4
%19 = load i64, i64* %8
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = load i8*, i8** %4
%27 = load i64, i64* %8
%28 = sub i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %25, %15
br label %31
31: ; preds = %30, %3
%32 = load i8*, i8** %7
ret i8* %32
}

LLVM IR (-O2):
define i8* @file_list_fgets(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 %13, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add i64 %7, -1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %13
12: ; preds = %6
store i8 0, i8* %9
br label %13
13: ; preds = %6, %12, %3
ret i8* %4
}