#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 */

/* Variables and functions */
int asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ mem_alloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcspn(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int /*<<< orphan*/ strspn(char const *, char *);
size_t _parse_comments(const char *s, char **comments) {
  const char *ptr = s, *prev;
  char *new_comments, *tmp;
  size_t len;
  do {
    prev = ptr;
    ptr += strspn(ptr, " \t\r\n");
    if (*ptr == '#' || *ptr == ';')
      ptr += strcspn(ptr, "\r\n");
  } while (*ptr && ptr != prev);
  len = ptr - s;
  if (len) {
    new_comments = (char *)mem_alloc(len + 1);
    strncpy(new_comments, s, len);
    new_comments[len] = 0;
    if (*comments) {
      if (asprintf(&tmp, "%s%s", *comments, new_comments) == -1) {
        perror("asprintf");
        exit(255);
      }
      if (!tmp) {
        perror("asprintf");
        exit(255);
      }
      free(*comments);
      free(new_comments);
      *comments = tmp;
    } else {
      *comments = new_comments;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<_parse_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     11e0 <_parse_comments+0x60>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    1200 <_parse_comments+0x80>
mov    -0x18(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1205 <_parse_comments+0x85>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     1228 <_parse_comments+0xa8>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1198 <_parse_comments+0x18>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1319 <_parse_comments+0x199>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1080 <mem_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1309 <_parse_comments+0x189>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    12c3 <_parse_comments+0x143>
lea    0xd56(%rip),%rdi
call   1090 <perror@plt>
mov    $0xff,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    12e4 <_parse_comments+0x164>
lea    0xd35(%rip),%rdi
call   1090 <perror@plt>
mov    $0xff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1314 <_parse_comments+0x194>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1319 <_parse_comments+0x199>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_comments>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe68(%rip),%r12
lea    0xe63(%rip),%r13
mov    %rdi,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <strspn@plt>
cltq
lea    (%rax,%rbp,1),%rbx
movzbl 0x0(%rbp,%rax,1),%eax
cmp    $0x3b,%al
je     11ce <_parse_comments+0x4e>
cmp    $0x23,%al
jne    11e3 <_parse_comments+0x63>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcspn@plt>
movslq %eax,%rcx
movzbl (%rbx,%rcx,1),%eax
add    %rcx,%rbx
cmp    %rbp,%rbx
je     11ef <_parse_comments+0x6f>
mov    %rbx,%rbp
test   %al,%al
jne    11b0 <_parse_comments+0x30>
sub    %r15,%rbx
je     1250 <_parse_comments+0xd0>
lea    0x1(%rbx),%rdi
call   1080 <mem_alloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%r12,%rbx,1)
mov    (%r14),%rdx
test   %rdx,%rdx
je     124d <_parse_comments+0xcd>
lea    0xde3(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rcx
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1262 <_parse_comments+0xe2>
cmpq   $0x0,(%rsp)
je     1262 <_parse_comments+0xe2>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%rsp),%r12
mov    %r12,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda1(%rip),%rdi
call   1090 <perror@plt>
mov    $0xff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [9 x i8] c"asprintf\00"
define i64 @_parse_comments(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
%10 = load i8*, i8** %3
store i8* %10, i8** %5
br label %11
11: ; preds = %43, %2
%12 = load i8*, i8** %5
store i8* %12, i8** %6
%13 = load i8*, i8** %5
%14 = call i32 @strspn(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %5
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 35
br i1 %21, label %27, label %22
22: ; preds = %11
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 59
br i1 %26, label %27, label %33
27: ; preds = %22, %11
%28 = load i8*, i8** %5
%29 = call i32 @strcspn(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %5
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %5
br label %33
33: ; preds = %27, %22
br label %34
34: ; preds = %33
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = load i8*, i8** %6
%42 = icmp ne i8* %40, %41
br label %43
43: ; preds = %39, %34
%44 = phi i1 [ false, %34 ], [ %42, %39 ]
br i1 %44, label %11, label %45
45: ; preds = %43
%46 = load i8*, i8** %5
%47 = load i8*, i8** %3
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %95
53: ; preds = %45
%54 = load i64, i64* %9
%55 = add i64 %54, 1
%56 = call i64 @mem_alloc(i64 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %7
%58 = load i8*, i8** %7
%59 = load i8*, i8** %3
%60 = load i64, i64* %9
%61 = call i32 @strncpy(i8* %58, i8* %59, i64 %60)
%62 = load i8*, i8** %7
%63 = load i64, i64* %9
%64 = getelementptr inbounds i8, i8* %62, i64 %63
store i8 0, i8* %64
%65 = load i8**, i8*** %4
%66 = load i8*, i8** %65
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %91
68: ; preds = %53
%69 = load i8**, i8*** %4
%70 = load i8*, i8** %69
%71 = load i8*, i8** %7
%72 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %70, i8* %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %68
%75 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%76 = call i32 @exit(i32 255)
unreachable
77: ; preds = %68
%78 = load i8*, i8** %8
%79 = icmp ne i8* %78, null
br i1 %79, label %83, label %80
80: ; preds = %77
%81 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @exit(i32 255)
unreachable
83: ; preds = %77
%84 = load i8**, i8*** %4
%85 = load i8*, i8** %84
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %7
%88 = call i32 @free(i8* %87)
%89 = load i8*, i8** %8
%90 = load i8**, i8*** %4
store i8* %89, i8** %90
br label %94
91: ; preds = %53
%92 = load i8*, i8** %7
%93 = load i8**, i8*** %4
store i8* %92, i8** %93
br label %94
94: ; preds = %91, %83
br label %95
95: ; preds = %94, %45
%96 = load i64, i64* %9
ret i64 %96
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [9 x i8] c"asprintf\00"
define i64 @_parse_comments(i8* %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
br label %5
5: ; preds = %16, %2
%6 = phi i8* [ %0, %2 ], [ %18, %16 ]
%7 = tail call i32 @strspn(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %16 [
i8 35, label %11
i8 59, label %11
]
11: ; preds = %5, %5
%12 = tail call i32 @strcspn(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = load i8, i8* %14
br label %16
16: ; preds = %5, %11
%17 = phi i8 [ %15, %11 ], [ %10, %5 ]
%18 = phi i8* [ %14, %11 ], [ %9, %5 ]
%19 = icmp ne i8 %17, 0
%20 = icmp ne i8* %18, %6
%21 = and i1 %20, %19
br i1 %21, label %5, label %22
22: ; preds = %16
%23 = ptrtoint i8* %18 to i64
%24 = ptrtoint i8* %0 to i64
%25 = sub i64 %23, %24
%26 = icmp eq i64 %25, 0
br i1 %26, label %54, label %27
27: ; preds = %22
%28 = add i64 %25, 1
%29 = tail call i64 @mem_alloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 @strncpy(i8* %30, i8* %0, i64 %25)
%32 = getelementptr inbounds i8, i8* %30, i64 %25
store i8 0, i8* %32
%33 = load i8*, i8** %1
%34 = icmp eq i8* %33, null
br i1 %34, label %52, label %35
35: ; preds = %27
%36 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %30)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 255)
unreachable
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 255)
unreachable
47: ; preds = %41
%48 = load i8*, i8** %1
%49 = call i32 @free(i8* %48)
%50 = call i32 @free(i8* %30)
%51 = load i8*, i8** %3
br label %52
52: ; preds = %27, %47
%53 = phi i8* [ %51, %47 ], [ %30, %27 ]
store i8* %53, i8** %1
br label %54
54: ; preds = %52, %22
ret i64 %25
}