#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 /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char *strchr(char *, char);
scalar_t__ strlen(char *);
void config_parser_strip_comments(char *p) {
  char *k;
  int state = 0;
  for (; *p; p++) {
    if (*p == '\n') {
      state = 0;
    } else if ((*p == '#' || *p == ';') && state == 0) {
      k = strchr(p, '\n');
      if (k) {
        memmove(p, k, strlen(k) + 1);
      } else {
        *p = 0;
        break;
      }
    } else if (*p != '\t' && *p != ' ') {
      state = 1;
    }
  }
}


x86 assembly (clang, -O0):
<config_parser_strip_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     123d <config_parser_strip_comments+0x10d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    116c <config_parser_strip_comments+0x3c>
movl   $0x0,-0x14(%rbp)
jmp    1227 <config_parser_strip_comments+0xf7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     118c <config_parser_strip_comments+0x5c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    11f6 <config_parser_strip_comments+0xc6>
cmpl   $0x0,-0x14(%rbp)
jne    11f6 <config_parser_strip_comments+0xc6>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e5 <config_parser_strip_comments+0xb5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
jmp    11f1 <config_parser_strip_comments+0xc1>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    123d <config_parser_strip_comments+0x10d>
jmp    1222 <config_parser_strip_comments+0xf2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     121d <config_parser_strip_comments+0xed>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     121d <config_parser_strip_comments+0xed>
movl   $0x1,-0x14(%rbp)
jmp    1222 <config_parser_strip_comments+0xf2>
jmp    1227 <config_parser_strip_comments+0xf7>
jmp    122c <config_parser_strip_comments+0xfc>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1143 <config_parser_strip_comments+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_parser_strip_comments>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
jmp    114f <config_parser_strip_comments+0x1f>
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
je     116f <config_parser_strip_comments+0x3f>
mov    $0x1,%edx
add    $0x1,%r14
mov    %edx,%eax
movzbl (%r14),%ecx
mov    $0x0,%edx
cmp    $0xa,%cl
je     1149 <config_parser_strip_comments+0x19>
cmp    $0x23,%cl
je     1140 <config_parser_strip_comments+0x10>
test   %cl,%cl
je     11b1 <config_parser_strip_comments+0x81>
cmp    $0x3b,%cl
jne    119f <config_parser_strip_comments+0x6f>
test   %eax,%eax
jne    119f <config_parser_strip_comments+0x6f>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ad <config_parser_strip_comments+0x7d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
xor    %edx,%edx
jmp    1149 <config_parser_strip_comments+0x19>
mov    %eax,%edx
cmp    $0x9,%cl
je     1149 <config_parser_strip_comments+0x19>
cmp    $0x20,%cl
je     1149 <config_parser_strip_comments+0x19>
jmp    1144 <config_parser_strip_comments+0x14>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @config_parser_strip_comments(i8* %0) {
br label %2
2: ; preds = %22, %1
%3 = phi i8* [ %0, %1 ], [ %24, %22 ]
%4 = phi i32 [ 0, %1 ], [ %23, %22 ]
%5 = load i8, i8* %3
switch i8 %5, label %6 [
i8 0, label %25
i8 10, label %22
i8 35, label %10
]
6: ; preds = %2
%7 = icmp eq i8 %5, 59
%8 = icmp eq i32 %4, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %12, label %20
10: ; preds = %2
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %21
12: ; preds = %6, %10
%13 = tail call i8* @strchr(i8* %3, i8 signext 10)
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i64 @strlen(i8* %13)
%17 = add nsw i64 %16, 1
%18 = tail call i32 @memmove(i8* %3, i8* %13, i64 %17)
br label %22
19: ; preds = %12
store i8 0, i8* %3
br label %25
20: ; preds = %6
switch i8 %5, label %21 [
i8 9, label %22
i8 32, label %22
]
21: ; preds = %10, %20
br label %22
22: ; preds = %20, %20, %2, %21, %15
%23 = phi i32 [ 0, %15 ], [ 1, %21 ], [ %4, %20 ], [ 0, %2 ], [ %4, %20 ]
%24 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
25: ; preds = %2, %19
ret void
}