#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 *, size_t, int /*<<< orphan*/ *);
char *strchr(char *, char);
bool aux_readline(FILE *f, char *buffer_ptr, size_t buffer_size,
                  unsigned int *line_idx) {
  if (fgets(buffer_ptr, buffer_size, f) == NULL)
    return false;
  if (strchr(buffer_ptr, '\n'))
    *(strchr(buffer_ptr, '\n')) = '\0';
  if (strchr(buffer_ptr, '\r'))
    *(strchr(buffer_ptr, '\n')) = '\0';
  (*line_idx)++;
  return true;
}


x86 assembly (clang, -O0):
<aux_readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    115f <aux_readline+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <aux_readline+0xa3>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1188 <aux_readline+0x68>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11b1 <aux_readline+0x91>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aux_readline>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1182 <aux_readline+0x62>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1155 <aux_readline+0x35>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <aux_readline+0x57>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
addl   $0x1,(%r14)
mov    $0x1,%eax
jmp    1184 <aux_readline+0x64>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @aux_readline(i32* nocapture %0, i8* %1, i64 %2, i32* nocapture %3) {
%5 = tail call i32* @fgets(i8* %1, i64 %2, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i8 0, i8* %8
br label %11
11: ; preds = %10, %7
%12 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 13)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
store i8 0, i8* %15
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %3
%18 = add i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %4, %16
%20 = phi i32 [ 1, %16 ], [ 0, %4 ]
ret i32 %20
}