#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 remove_comments(char *s, char *com) {
  char *p = NULL;
  char *q = NULL;
  com[0] = '\0';
  p = strchr(s, '%');
  while (p != NULL) {
    if (p == s || ((p > s) && *(p - 1) != '\\')) {
      strcpy(com, p);
      *p = '\0';
      return 1;
    }
    q = p + 1;
    if (*q == '\0')
      return 1;
    p = strchr(q, '%');
  }
  return 0;
}


x86 assembly (clang, -O0):
<remove_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f0 <remove_comments+0xd0>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1191 <remove_comments+0x71>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11b1 <remove_comments+0x91>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5c,%eax
je     11b1 <remove_comments+0x91>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11f7 <remove_comments+0xd7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d9 <remove_comments+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <remove_comments+0xd7>
mov    -0x28(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    1159 <remove_comments+0x39>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_comments>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rsi)
mov    $0x25,%esi
call   1040 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1181 <remove_comments+0x61>
xchg   %ax,%ax
cmp    %rbx,%rax
je     116e <remove_comments+0x4e>
jbe    114d <remove_comments+0x2d>
cmpb   $0x5c,-0x1(%rax)
jne    116b <remove_comments+0x4b>
cmpb   $0x0,0x1(%rax)
je     117c <remove_comments+0x5c>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1140 <remove_comments+0x20>
jmp    1181 <remove_comments+0x61>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movb   $0x0,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @remove_comments(i8* %0, i8* %1) {
store i8 0, i8* %1
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%4 = icmp eq i8* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2, %21
%6 = phi i8* [ %22, %21 ], [ %3, %2 ]
%7 = icmp eq i8* %6, %0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = icmp ugt i8* %6, %0
br i1 %9, label %10, label %17
10: ; preds = %8
%11 = getelementptr inbounds i8, i8* %6, i64 -1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 92
br i1 %13, label %17, label %14
14: ; preds = %10, %5
%15 = phi i8* [ %6, %10 ], [ %0, %5 ]
%16 = tail call i32 @strcpy(i8* %1, i8* %15)
store i8 0, i8* %15
br label %24
17: ; preds = %10, %8
%18 = getelementptr inbounds i8, i8* %6, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = tail call i8* @strchr(i8* %18, i8 signext 37)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %5
24: ; preds = %17, %21, %2, %14
%25 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 1, %17 ], [ 0, %21 ]
ret i32 %25
}