#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strip_comments(char *line) {
  static int in_comment = 0;
  char *cp1, *cp2;
  cp1 = line;
  while (1) {
    if (in_comment) {
      if ((cp2 = strchr(cp1, '}')) != NULL) {
        strcpy(cp1, cp2 + 1);
        in_comment = 0;
        continue;
      } else {
        *cp1 = '\0';
        break;
      }
    } else {
      if ((cp2 = strchr(cp1, '-')) != NULL) {
        if (*(cp2 + 1) == '-') {
          *cp2 = '\0';
          break;
        }
      }
      if ((cp2 = strchr(cp1, '{')) != NULL) {
        in_comment = 1;
        *cp2 = ' ';
        continue;
      } else
        break;
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<strip_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,0x2ef9(%rip)
je     1189 <strip_comments+0x69>
mov    -0x10(%rbp),%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117d <strip_comments+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
movl   $0x0,0x2ebc(%rip)
jmp    1134 <strip_comments+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11fe <strip_comments+0xde>
mov    -0x10(%rbp),%rdi
mov    $0x2d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c7 <strip_comments+0xa7>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
jne    11c2 <strip_comments+0xa2>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11fe <strip_comments+0xde>
jmp    11c7 <strip_comments+0xa7>
mov    -0x10(%rbp),%rdi
mov    $0x7b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f9 <strip_comments+0xd9>
movl   $0x1,0x2e47(%rip)
mov    -0x18(%rbp),%rax
movb   $0x20,(%rax)
jmp    1134 <strip_comments+0x14>
jmp    11fe <strip_comments+0xde>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_comments>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x1,0x2f09(%rip)
jne    1155 <strip_comments+0x35>
mov    %rbx,%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     118b <strip_comments+0x6b>
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
movb   $0x0,0x2edf(%rip)
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     116d <strip_comments+0x4d>
cmpb   $0x2d,0x1(%rax)
je     118e <strip_comments+0x6e>
mov    %rbx,%rdi
mov    $0x7b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1191 <strip_comments+0x71>
movb   $0x1,0x2eae(%rip)
movb   $0x20,(%rax)
jmp    112d <strip_comments+0xd>
mov    %rbx,%rax
movb   $0x0,(%rax)
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@strip_comments.in_comment = internal unnamed_addr global i1 false
define i32 @strip_comments(i8* %0) {
%2 = load i1, i1* @strip_comments.in_comment
br i1 %2, label %3, label %9
3: ; preds = %19, %1
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 125)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i32 @strcpy(i8* %0, i8* %7)
store i1 false, i1* @strip_comments.in_comment
br label %9
9: ; preds = %6, %1
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 45)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %20, label %16
16: ; preds = %12, %9
%17 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 123)
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
store i1 true, i1* @strip_comments.in_comment
store i8 32, i8* %17
br label %3
20: ; preds = %12, %3
%21 = phi i8* [ %0, %3 ], [ %10, %12 ]
store i8 0, i8* %21
br label %22
22: ; preds = %20, %16
ret i32 0
}