#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 */
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ regmatch_t;
struct TYPE_6__ {
  scalar_t__ re_nsub;
};
typedef TYPE_1__ regex_t;

/* Variables and functions */
#define REG_NOMATCH 128
int /*<<< orphan*/ add_replace(char const *, TYPE_1__ *, char const *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ exit_regerror(int, TYPE_1__ *);
int /*<<< orphan*/ getstring();
int /*<<< orphan*/ pbstr(int /*<<< orphan*/);
int regexec(TYPE_1__ *, char const *, scalar_t__, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
void do_regexp(const char *string, regex_t *re, const char *replace,
               regmatch_t *pm) {
  int error;
  switch (error = regexec(re, string, re->re_nsub + 1, pm, 0)) {
  case 0:
    add_replace(string, re, replace, pm);
    pbstr(getstring());
    break;
  case REG_NOMATCH:
    break;
  default:
    exit_regerror(error, re);
  }
}


x86 assembly (clang, -O0):
<do_regexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    (%rdi),%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x24(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
test   %eax,%eax
je     11ab <do_regexp+0x5b>
jmp    1198 <do_regexp+0x48>
mov    -0x28(%rbp),%eax
sub    $0x80,%eax
je     11d3 <do_regexp+0x83>
jmp    11d8 <do_regexp+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <add_replace@plt>
mov    $0x0,%al
call   1040 <getstring@plt>
mov    %eax,%edi
call   1070 <pbstr@plt>
jmp    11e4 <do_regexp+0x94>
jmp    11e4 <do_regexp+0x94>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <exit_regerror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_regexp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    (%rsi),%rdx
add    $0x1,%rdx
mov    %rsi,%rdi
mov    %r12,%rsi
xor    %r8d,%r8d
call   1060 <regexec@plt>
cmp    $0x80,%eax
je     11ae <do_regexp+0x5e>
test   %eax,%eax
jne    11ba <do_regexp+0x6a>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <add_replace@plt>
xor    %eax,%eax
call   1040 <getstring@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <pbstr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %eax,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <exit_regerror@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64 }
define void @do_regexp(i8* %0, %struct.TYPE_6__* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca %struct.TYPE_6__*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%10 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%11 = load i8*, i8** %5
%12 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = add nsw i64 %14, 1
%16 = load i32*, i32** %8
%17 = call i32 @regexec(%struct.TYPE_6__* %10, i8* %11, i64 %15, i32* %16, i32 0)
store i32 %17, i32* %9
switch i32 %17, label %27 [
i32 0, label %18
i32 128, label %26
]
18: ; preds = %4
%19 = load i8*, i8** %5
%20 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%21 = load i8*, i8** %7
%22 = load i32*, i32** %8
%23 = call i32 @add_replace(i8* %19, %struct.TYPE_6__* %20, i8* %21, i32* %22)
%24 = call i32 (...) @getstring()
%25 = call i32 @pbstr(i32 %24)
br label %31
26: ; preds = %4
br label %31
27: ; preds = %4
%28 = load i32, i32* %9
%29 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
%30 = call i32 @exit_regerror(i32 %28, %struct.TYPE_6__* %29)
br label %31
31: ; preds = %27, %26, %18
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64 }
define void @do_regexp(i8* %0, %struct.TYPE_6__* %1, i8* %2, i32* %3) {
%5 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = add nsw i64 %6, 1
%8 = tail call i32 @regexec(%struct.TYPE_6__* %1, i8* %0, i64 %7, i32* %3, i32 0)
switch i32 %8, label %13 [
i32 0, label %9
i32 128, label %15
]
9: ; preds = %4
%10 = tail call i32 @add_replace(i8* %0, %struct.TYPE_6__* %1, i8* %2, i32* %3)
%11 = tail call i32 (...) @getstring()
%12 = tail call i32 @pbstr(i32 %11)
br label %15
13: ; preds = %4
%14 = tail call i32 @exit_regerror(i32 %8, %struct.TYPE_6__* %1)
br label %15
15: ; preds = %13, %4, %9
ret void
}