#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 */
scalar_t__ isalpha(int);
char *strstr(char *, char const *);
void SearchRep(char *A, const char *sub, unsigned int L) {
  char *p, *q;
  p = strstr(A, sub);
  if (p) {
    if (isalpha((int)*(p + L)))
      SearchRep(A + L, sub, L);
    else {
      q = p + L;
      *p++ = ' ';
      while ((*p++ = *q++))
        ;
    }
  }
}


x86 assembly (clang, -O0):
<SearchRep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ed <SearchRep+0xbd>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <isalpha@plt>
cmp    $0x0,%rax
je     1194 <SearchRep+0x64>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <SearchRep@plt>
jmp    11e8 <SearchRep+0xb8>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     11e3 <SearchRep+0xb3>
jmp    11b4 <SearchRep+0x84>
jmp    11e8 <SearchRep+0xb8>
jmp    11ed <SearchRep+0xbd>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SearchRep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strstr@plt>
test   %rax,%rax
je     118f <SearchRep+0x6f>
mov    %rax,%rbx
mov    %ebp,%ebp
add    %rbp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1030 <isalpha@plt>
test   %rax,%rax
je     1176 <SearchRep+0x56>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
mov    %rax,%rbx
add    %rbp,%r15
test   %rax,%rax
jne    1150 <SearchRep+0x30>
jmp    118f <SearchRep+0x6f>
movb   $0x20,(%rbx)
add    $0x1,%rbx
nopl   (%rax)
movzbl -0x1(%rbx,%rbp,1),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
test   %al,%al
jne    1180 <SearchRep+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @SearchRep(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %16
%9 = phi i8* [ %4, %6 ], [ %18, %16 ]
%10 = phi i8* [ %0, %6 ], [ %17, %16 ]
%11 = getelementptr inbounds i8, i8* %9, i64 %7
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = tail call i64 @isalpha(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %10, i64 %7
%18 = tail call i8* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) %1)
%19 = icmp eq i8* %18, null
br i1 %19, label %29, label %8
20: ; preds = %8
%21 = getelementptr inbounds i8, i8* %9, i64 %7
store i8 32, i8* %9
br label %22
22: ; preds = %22, %20
%23 = phi i8* [ %9, %20 ], [ %25, %22 ]
%24 = phi i8* [ %21, %20 ], [ %26, %22 ]
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %24
store i8 %27, i8* %25
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %22
29: ; preds = %16, %22, %3
ret void
}