#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*/ free(char *);
int /*<<< orphan*/ isdigit(char const);
char *malloc(scalar_t__);
scalar_t__ strlen(char const *);
char *cut_pattern_match(const char *src, const char *pattern,
                        const char *replace) {
  char *res = malloc(strlen(src) + 1 + strlen(replace));
  int echomode = 1;
  const char *srctail = src;
  const char *patterntail;
  char *restail = res;
  for (patterntail = pattern; '\0' != patterntail[0]; patterntail++) {
    switch (patterntail[0]) {
    case '(':
      echomode = 0;
      continue;
    case ')':
      echomode = 1;
      continue;
    case '9':
      if (!isdigit(srctail[0]))
        goto fail;
      do
        srctail++;
      while (isdigit(srctail[0]));
      continue;
    }
  }
fail:
  free(res);
  return NULL;
}


x86 assembly (clang, -O0):
<cut_pattern_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     125b <cut_pattern_match+0x11b>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x28,%eax
je     11e8 <cut_pattern_match+0xa8>
jmp    11c6 <cut_pattern_match+0x86>
mov    -0x4c(%rbp),%eax
sub    $0x29,%eax
je     11f4 <cut_pattern_match+0xb4>
jmp    11d7 <cut_pattern_match+0x97>
mov    -0x4c(%rbp),%eax
sub    $0x39,%eax
je     1200 <cut_pattern_match+0xc0>
jmp    1245 <cut_pattern_match+0x105>
movl   $0x0,-0x24(%rbp)
jmp    124a <cut_pattern_match+0x10a>
movl   $0x1,-0x24(%rbp)
jmp    124a <cut_pattern_match+0x10a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    121a <cut_pattern_match+0xda>
jmp    1260 <cut_pattern_match+0x120>
jmp    121f <cut_pattern_match+0xdf>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    121f <cut_pattern_match+0xdf>
jmp    124a <cut_pattern_match+0x10a>
jmp    124a <cut_pattern_match+0x10a>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    119d <cut_pattern_match+0x5d>
jmp    1260 <cut_pattern_match+0x120>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_pattern_match>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
jmp    1188 <cut_pattern_match+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %al,%al
je     11b3 <cut_pattern_match+0x73>
add    $0x1,%r14
mov    (%r14),%al
cmp    $0x39,%al
jne    1180 <cut_pattern_match+0x40>
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     11b3 <cut_pattern_match+0x73>
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isdigit@plt>
test   %eax,%eax
jne    11a0 <cut_pattern_match+0x60>
jmp    1184 <cut_pattern_match+0x44>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @cut_pattern_match(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 1
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = add nsw i64 %5, %6
%8 = tail call i8* @malloc(i64 %7)
br label %9
9: ; preds = %23, %3
%10 = phi i8* [ %0, %3 ], [ %24, %23 ]
%11 = phi i8* [ %1, %3 ], [ %25, %23 ]
%12 = load i8, i8* %11
switch i8 %12, label %23 [
i8 0, label %26
i8 57, label %13
]
13: ; preds = %9
%14 = load i8, i8* %10
%15 = tail call i32 @isdigit(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13, %17
%18 = phi i8* [ %19, %17 ], [ %10, %13 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = tail call i32 @isdigit(i8 signext %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %9
%24 = phi i8* [ %10, %9 ], [ %19, %17 ]
%25 = getelementptr inbounds i8, i8* %11, i64 1
br label %9
26: ; preds = %9, %13
%27 = tail call i32 @free(i8* %8)
ret i8* null
}