#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*/ memset(char *, char, int);
char *strchr(char *, char);
int remove_comment(char *p_data, size_t len) {
  char *p_cursor = p_data;
  while ((p_cursor = strchr(p_cursor, '%')) && p_cursor != NULL) {
    if (p_cursor - p_data + 1 < len) {
      if (*(p_cursor + 1) == '%') {
        char *p_end = strchr(p_cursor, '\n');
        memset(p_cursor, ' ', p_end - p_cursor + 1);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<remove_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     1167 <remove_comment+0x47>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1177 <remove_comment+0x57>
jmp    11dc <remove_comment+0xbc>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
cmp    -0x10(%rbp),%rax
jae    11d7 <remove_comment+0xb7>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    11d2 <remove_comment+0xb2>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
jmp    11d7 <remove_comment+0xb7>
jmp    1138 <remove_comment+0x18>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_comment>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x25,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1195 <remove_comment+0x75>
mov    %rax,%rbx
mov    $0x1,%r12d
sub    %r15,%r12
jmp    1165 <remove_comment+0x45>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1195 <remove_comment+0x75>
lea    (%r12,%rbx,1),%rax
cmp    %r14,%rax
jae    1150 <remove_comment+0x30>
cmpb   $0x25,0x1(%rbx)
jne    1150 <remove_comment+0x30>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
sub    %ebx,%eax
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <memset@plt>
jmp    1150 <remove_comment+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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