#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*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strchr(char *, char);
char *findline(FILE *stream) {
  char *line = NULL;
  size_t l;
  int status = getline(&line, &l, stream);
  if (status == -1) {
    free(line);
    return NULL;
  }
  if (line[0] == '\n') {
    free(line);
    return findline(stream);
  }
  char *comment = strchr(line, '#');
  if (comment) {
    if (comment == line) {
      free(line);
      return findline(stream);
    } else {
      *comment = '\0';
      *(--comment) = '\n';
    }
  }
  return line;
}


x86 assembly (clang, -O0):
<findline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1188 <findline+0x48>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1220 <findline+0xe0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b3 <findline+0x73>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <findline@plt>
mov    %rax,-0x8(%rbp)
jmp    1220 <findline+0xe0>
mov    -0x18(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1218 <findline+0xd8>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11f9 <findline+0xb9>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <findline@plt>
mov    %rax,-0x8(%rbp)
jmp    1220 <findline+0xe0>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0xa,-0x1(%rax)
jmp    1218 <findline+0xd8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findline>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1060 <getline@plt>
mov    0x8(%rsp),%rbx
cmp    $0xffffffff,%eax
je     1189 <findline+0x49>
cmpb   $0xa,(%rbx)
jne    1195 <findline+0x55>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <findline@plt>
mov    %rax,%rbx
jmp    11b7 <findline+0x77>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    11b7 <findline+0x77>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b7 <findline+0x77>
cmp    %rbx,%rax
je     1174 <findline+0x34>
movw   $0xa,-0x1(%rax)
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @findline(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
store i32* %0, i32** %3
store i8* null, i8** %4
%8 = load i32*, i32** %3
%9 = call i32 @getline(i8** %4, i64* %5, i32* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @free(i8* %13)
store i8* null, i8** %2
br label %47
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
%24 = load i32*, i32** %3
%25 = call i8* @findline(i32* %24)
store i8* %25, i8** %2
br label %47
26: ; preds = %15
%27 = load i8*, i8** %4
%28 = call i8* @strchr(i8* %27, i8 signext 35)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = load i8*, i8** %4
%34 = icmp eq i8* %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = call i32 @free(i8* %36)
%38 = load i32*, i32** %3
%39 = call i8* @findline(i32* %38)
store i8* %39, i8** %2
br label %47
40: ; preds = %31
%41 = load i8*, i8** %7
store i8 0, i8* %41
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %7
store i8 10, i8* %43
br label %44
44: ; preds = %40
br label %45
45: ; preds = %44, %26
%46 = load i8*, i8** %4
store i8* %46, i8** %2
br label %47
47: ; preds = %45, %35, %21, %12
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
define i8* @findline(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
%6 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%7 = icmp eq i32 %6, -1
%8 = load i8*, i8** %2
br i1 %7, label %9, label %11
9: ; preds = %1
%10 = call i32 @free(i8* %8)
br label %28
11: ; preds = %1
%12 = load i8, i8* %8
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @free(i8* %8)
%16 = call i8* @findline(i32* %0)
br label %28
17: ; preds = %11
%18 = call i8* @strchr(i8* %8, i8 signext 35)
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = icmp eq i8* %18, %8
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = call i32 @free(i8* %8)
%24 = call i8* @findline(i32* %0)
br label %28
25: ; preds = %20
store i8 0, i8* %18
%26 = getelementptr inbounds i8, i8* %18, i64 -1
store i8 10, i8* %26
%27 = load i8*, i8** %2
br label %28
28: ; preds = %17, %25, %22, %14, %9
%29 = phi i8* [ null, %9 ], [ %16, %14 ], [ %24, %22 ], [ %27, %25 ], [ %8, %17 ]
ret i8* %29
}