#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;
typedef int /*<<< orphan*/ match;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char *);
int /*<<< orphan*/ printf(char *, char const *, char const *, char const *,
                          int);
int regcomp(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, int, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int _regex_regexec(char const *progname, char const *pattern,
                   char const *string, int flags) {
  int ret;
  regex_t reg;
  char buf[80];
  int r;
  regmatch_t match[1];
  printf("%s: Testing regexec(): \"%s\" \"%s\" (%d)\n", progname, pattern,
         string, flags);
  if ((r = regcomp(&reg, pattern, flags)) != 0) {
    regerror(r, &reg, buf, sizeof(buf));
    fprintf(stderr, "%s: %s: %s\n", progname, pattern, buf);
    return 4;
  }
  if ((ret = regexec(&reg, string, sizeof(match) / sizeof(*match), match, 0)) !=
      0) {
    regerror(ret, &reg, buf, sizeof(buf));
    fprintf(stderr, "%s: %s: %s\n", progname, pattern, buf);
    ret = 8;
  }
  regfree(&reg);
  return ret;
}


x86 assembly (clang, -O0):
<_regex_regexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x2c(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
je     11fa <_regex_regexec+0x9a>
mov    -0x84(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x2c(%rbp),%rsi
mov    $0x50,%ecx
call   1070 <regerror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x80(%rbp),%r8
lea    0xe3e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    126e <_regex_regexec+0x10e>
mov    -0x20(%rbp),%rsi
lea    -0x88(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     125f <_regex_regexec+0xff>
mov    -0x28(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x2c(%rbp),%rsi
mov    $0x50,%ecx
call   1070 <regerror@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x80(%rbp),%r8
lea    0xdd4(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x8,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_regex_regexec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe84(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %ebp,%r8d
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <regcomp@plt>
test   %eax,%eax
je     11de <_regex_regexec+0x7e>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x50,%ecx
call   1070 <regerror@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1060 <fprintf@plt>
mov    $0x4,%ebp
jmp    1244 <_regex_regexec+0xe4>
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rcx
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     123a <_regex_regexec+0xda>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x50,%ecx
call   1070 <regerror@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1060 <fprintf@plt>
mov    $0x8,%ebp
lea    0x8(%rsp),%rdi
call   1030 <regfree@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%s: Testing regexec(): \22%s\22 \22%s\22 (%d)\0A\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
define i32 @_regex_regexec(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [80 x i8]
%13 = alloca i32
%14 = alloca [1 x i32]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16, i8* %17, i32 %18)
%20 = load i8*, i8** %7
%21 = load i32, i32* %9
%22 = call i32 @regcomp(i32* %11, i8* %20, i32 %21)
store i32 %22, i32* %13
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %4
%25 = load i32, i32* %13
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%27 = call i32 @regerror(i32 %25, i32* %11, i8* %26, i32 80)
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %6
%30 = load i8*, i8** %7
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30, i8* %31)
store i32 4, i32* %5
br label %50
33: ; preds = %4
%34 = load i8*, i8** %8
%35 = getelementptr inbounds [1 x i32], [1 x i32]* %14, i64 0, i64 0
%36 = call i32 @regexec(i32* %11, i8* %34, i32 1, i32* %35, i32 0)
store i32 %36, i32* %10
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %33
%39 = load i32, i32* %10
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%41 = call i32 @regerror(i32 %39, i32* %11, i8* %40, i32 80)
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%46 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %44, i8* %45)
store i32 8, i32* %10
br label %47
47: ; preds = %38, %33
%48 = call i32 @regfree(i32* %11)
%49 = load i32, i32* %10
store i32 %49, i32* %5
br label %50
50: ; preds = %47, %24
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
@.str = [39 x i8] c"%s: Testing regexec(): \22%s\22 \22%s\22 (%d)\0A\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
define i32 @_regex_regexec(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = alloca [1 x i32]
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = bitcast [1 x i32]* %7 to i8*
%11 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i32 %3)
%12 = call i32 @regcomp(i32* %5, i8* %1, i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = call i32 @regerror(i32 %12, i32* %5, i8* %9, i32 80)
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %9)
br label %29
18: ; preds = %4
%19 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%20 = call i32 @regexec(i32* %5, i8* %2, i32 1, i32* %19, i32 0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = call i32 @regerror(i32 %20, i32* %5, i8* %9, i32 80)
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %9)
br label %26
26: ; preds = %22, %18
%27 = phi i32 [ 8, %22 ], [ 0, %18 ]
%28 = call i32 @regfree(i32* %5)
br label %29
29: ; preds = %26, %14
%30 = phi i32 [ 4, %14 ], [ %27, %26 ]
ret i32 %30
}