#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int getdelim(char **, size_t *, char, int /*<<< orphan*/ *);
char *mlr_get_cline(FILE *fp, char irs) {
  char *line = NULL;
  size_t linecap = 0;
  ssize_t linelen = getdelim(&line, &linecap, irs, fp);
  if (linelen <= 0) {
    return NULL;
  }
  if (line[linelen - 1] == '\n') {
    line[linelen - 1] = 0;
    linelen--;
  }
  return line;
}


x86 assembly (clang, -O0):
<mlr_get_cline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
movsbl %al,%edx
call   1030 <getdelim@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     1163 <mlr_get_cline+0x53>
movq   $0x0,-0x8(%rbp)
jmp    119f <mlr_get_cline+0x8f>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1197 <mlr_get_cline+0x87>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mlr_get_cline>:
sub    $0x18,%rsp
mov    %esi,%edx
mov    %rdi,%rcx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <getdelim@plt>
test   %eax,%eax
jle    115c <mlr_get_cline+0x4c>
mov    %eax,%ecx
mov    0x8(%rsp),%rax
add    $0xffffffff,%ecx
cmpb   $0xa,(%rax,%rcx,1)
jne    1157 <mlr_get_cline+0x47>
movb   $0x0,(%rax,%rcx,1)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define i8* @mlr_get_cline(i32* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = call i32 @getdelim(i8** %3, i64* %4, i8 signext %1, i32* %0)
%8 = icmp slt i32 %7, 1
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = add nsw i32 %7, -1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %9
store i8 0, i8* %13
%17 = load i8*, i8** %3
br label %18
18: ; preds = %9, %16, %2
%19 = phi i8* [ null, %2 ], [ %17, %16 ], [ %10, %9 ]
ret i8* %19
}