#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*/ regex_t;

/* Variables and functions */
#define REG_NOMATCH 128
int /*<<< orphan*/ perrx(int, char *);
int regexec(int /*<<< orphan*/ *, char const *, size_t, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int regmatch(const char *string, char *pattern, regex_t *re) {
  int status;
  status = regexec(re, string, (size_t)0, NULL, 0);
  regfree(re);
  switch (status) {
  case 0:
    return (1);
  case REG_NOMATCH:
    return (0);
  default:
    (void)perrx(255, "Regex execution failed");
  }
  return (255);
}


x86 assembly (clang, -O0):
<regmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%ecx
mov    %rcx,%rdx
call   1050 <regexec@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     118c <regmatch+0x5c>
jmp    1179 <regmatch+0x49>
mov    -0x28(%rbp),%eax
sub    $0x80,%eax
je     1198 <regmatch+0x68>
jmp    11a4 <regmatch+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11bc <regmatch+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    11bc <regmatch+0x8c>
mov    $0xff,%edi
lea    0xe50(%rip),%rsi
call   1030 <perrx@plt>
movl   $0xff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regmatch>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rsi
mov    %rdx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <regfree@plt>
test   %ebx,%ebx
je     1163 <regmatch+0x33>
cmp    $0x80,%ebx
jne    116a <regmatch+0x3a>
xor    %ebx,%ebx
jmp    1180 <regmatch+0x50>
mov    $0x1,%ebx
jmp    1180 <regmatch+0x50>
lea    0xe8f(%rip),%rsi
mov    $0xff,%ebx
mov    $0xff,%edi
call   1030 <perrx@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Regex execution failed\00"
define i32 @regmatch(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %7
%10 = load i8*, i8** %5
%11 = call i32 @regexec(i32* %9, i8* %10, i64 0, i32* null, i32 0)
store i32 %11, i32* %8
%12 = load i32*, i32** %7
%13 = call i32 @regfree(i32* %12)
%14 = load i32, i32* %8
switch i32 %14, label %17 [
i32 0, label %15
i32 128, label %16
]
15: ; preds = %3
store i32 1, i32* %4
br label %20
16: ; preds = %3
store i32 0, i32* %4
br label %20
17: ; preds = %3
%18 = call i32 @perrx(i32 255, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17
store i32 255, i32* %4
br label %20
20: ; preds = %19, %16, %15
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [23 x i8] c"Regex execution failed\00"
define i32 @regmatch(i8* %0, i8* nocapture readnone %1, i32* %2) {
%4 = tail call i32 @regexec(i32* %2, i8* %0, i64 0, i32* null, i32 0)
%5 = tail call i32 @regfree(i32* %2)
switch i32 %4, label %7 [
i32 0, label %9
i32 128, label %6
]
6: ; preds = %3
br label %9
7: ; preds = %3
%8 = tail call i32 @perrx(i32 255, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %3, %7, %6
%10 = phi i32 [ 255, %7 ], [ 0, %6 ], [ 1, %3 ]
ret i32 %10
}