#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 */
typedef int /*<<< orphan*/ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
int regexec(int /*<<< orphan*/ *, char const *, int, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int RunRegex(regex_t *regex, const char *string, int nMatches,
             regmatch_t *matches, const char *errorMessage) {
  int ret;
  ret = regexec(regex, string, nMatches, matches, 0);
  if (ret) {
    size_t len = regerror(ret, regex, NULL, 0);
    char errorStr[len];
    regerror(ret, regex, errorStr, len);
    fprintf(stderr, "string = '%s'\n", string);
    fprintf(stderr, "%s\n%s", errorMessage, errorStr);
    exit(-1);
  }
  return ret;
}


x86 assembly (clang, -O0):
<RunRegex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1211 <RunRegex+0xd1>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <regerror@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%rcx
call   1040 <regerror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x50(%rbp),%rcx
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x2c(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunRegex>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r8d,%r8d
call   1050 <regexec@plt>
test   %eax,%eax
jne    1174 <RunRegex+0x34>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <regerror@plt>
lea    0xf(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r13
sub    %rcx,%r13
mov    %r13,%rsp
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rax,%rcx
call   1040 <regerror@plt>
mov    0x2e34(%rip),%rbx
mov    (%rbx),%edi
lea    0xe4b(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe47(%rip),%rsi
mov    %r14,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"string = '%s'\0A\00"
@.str.1 = [6 x i8] c"%s\0A%s\00"
define i32 @RunRegex(i32* %0, i8* %1, i32 %2, i32* %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i8* %4, i8** %10
%15 = load i32*, i32** %6
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = load i32*, i32** %9
%19 = call i32 @regexec(i32* %15, i8* %16, i32 %17, i32* %18, i32 0)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %5
%23 = load i32, i32* %11
%24 = load i32*, i32** %6
%25 = call i64 @regerror(i32 %23, i32* %24, i8* null, i64 0)
store i64 %25, i64* %12
%26 = load i64, i64* %12
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %13
%28 = alloca i8, i64 %26
store i64 %26, i64* %14
%29 = load i32, i32* %11
%30 = load i32*, i32** %6
%31 = load i64, i64* %12
%32 = call i64 @regerror(i32 %29, i32* %30, i8* %28, i64 %31)
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %7
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %28)
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %5
%41 = load i32, i32* %11
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"string = '%s'\0A\00"
@.str.1 = [6 x i8] c"%s\0A%s\00"
define i32 @RunRegex(i32* %0, i8* %1, i32 %2, i32* %3, i8* %4) {
%6 = tail call i32 @regexec(i32* %0, i8* %1, i32 %2, i32* %3, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i64 @regerror(i32 %6, i32* %0, i8* null, i64 0)
%10 = alloca i8, i64 %9
%11 = call i64 @regerror(i32 %6, i32* %0, i8* %10, i64 %9)
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %1)
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %10)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %5
ret i32 0
}