#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*/ readline(char **, size_t *, int /*<<< orphan*/ *);
size_t strcspn(char *, char *);
scalar_t__ strlen(char *);
char *trim(char *);
char *next_line(char **buffer, size_t *sz, FILE *data) {
  char *line;
  readline(buffer, sz, data);
  line = *buffer;
  if (strlen(line) > 0) {
    line[strcspn(*buffer, "\n")] = '\0';
    line[strcspn(*buffer, "#")] = '\0';
  }
  return trim(line);
}


x86 assembly (clang, -O0):
<next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <readline@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    11cf <next_line+0x8f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe67(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1040 <trim@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_line>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <readline@plt>
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    1182 <next_line+0x42>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    (%r14),%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <trim@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c"#\00"
define i8* @next_line(i8** %0, i64* %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i8*
store i8** %0, i8*** %4
store i64* %1, i64** %5
store i32* %2, i32** %6
%8 = load i8**, i8*** %4
%9 = load i64*, i64** %5
%10 = load i32*, i32** %6
%11 = call i32 @readline(i8** %8, i64* %9, i32* %10)
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %3
%18 = load i8*, i8** %7
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = call i64 @strcspn(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %7
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = call i64 @strcspn(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %17, %3
%29 = load i8*, i8** %7
%30 = call i8* @trim(i8* %29)
ret i8* %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c"#\00"
define i8* @next_line(i8** %0, i64* %1, i32* %2) {
%4 = tail call i32 @readline(i8** %0, i64* %1, i32* %2)
%5 = load i8*, i8** %0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = tail call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 0, i8* %10
%11 = load i8*, i8** %0
%12 = tail call i64 @strcspn(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %8, %3
%15 = tail call i8* @trim(i8* %5)
ret i8* %15
}