#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 */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
char *get_track(FILE *input, char *bits, int bits_len) {
  int bits_end;
  if (NULL == fgets(bits, bits_len, input)) {
    return NULL;
  }
  bits_end = strlen(bits);
  if ('\n' == bits[bits_end - 1]) {
    bits[bits_end - 1] = '\0';
  }
  return bits;
}


x86 assembly (clang, -O0):
<get_track>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    115e <get_track+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    11a1 <get_track+0x81>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    1199 <get_track+0x79>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_track>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1151 <get_track+0x31>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1153 <get_track+0x33>
movb   $0x0,-0x1(%rbx,%rax,1)
jmp    1153 <get_track+0x33>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

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

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