#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_5__ TYPE_1__;

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

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
scalar_t__ regcomp(TYPE_1__ *, char *, int);
scalar_t__ regexec(TYPE_1__ *, char *, int, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(TYPE_1__ *);
int reg_match(char *pattern, char *string, regmatch_t *pmatch) {
  regex_t preg;
  if (regcomp(&preg, pattern, REG_EXTENDED | REG_NEWLINE)) {
    return -1;
  }
  if (preg.re_nsub > 6) {
    regfree(&preg);
    return -2;
  }
  if (regexec(&preg, string, 6, pmatch, 0)) {
    regfree(&preg);
    return -3;
  }
  regfree(&preg);
  return 0;
}


x86 assembly (clang, -O0):
<reg_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
mov    0x2e90(%rip),%rax
or     (%rax),%edx
lea    -0x28(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     1179 <reg_match+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <reg_match+0xb0>
cmpl   $0x6,-0x28(%rbp)
jle    1198 <reg_match+0x68>
lea    -0x28(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11e0 <reg_match+0xb0>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x6,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
cmp    $0x0,%rax
je     11d0 <reg_match+0xa0>
lea    -0x28(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11e0 <reg_match+0xb0>
lea    -0x28(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg_match>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    0x2e8f(%rip),%rax
mov    0x2e98(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x8(%rsp),%rdi
call   1040 <regcomp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11b4 <reg_match+0x84>
cmpl   $0x7,0x8(%rsp)
jl     1183 <reg_match+0x53>
lea    0x8(%rsp),%rdi
call   1030 <regfree@plt>
mov    $0xfffffffe,%eax
jmp    11b4 <reg_match+0x84>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %r15,%rdi
call   1030 <regfree@plt>
lea    (%rbx,%rbx,2),%eax
add    $0xfffffffd,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
define i32 @reg_match(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.TYPE_5__
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = load i32, i32* @REG_EXTENDED
%11 = load i32, i32* @REG_NEWLINE
%12 = or i32 %10, %11
%13 = call i64 @regcomp(%struct.TYPE_5__* %8, i8* %9, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %31
16: ; preds = %3
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 6
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @regfree(%struct.TYPE_5__* %8)
store i32 -2, i32* %4
br label %31
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i32*, i32** %7
%25 = call i64 @regexec(%struct.TYPE_5__* %8, i8* %23, i32 6, i32* %24, i32 0)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @regfree(%struct.TYPE_5__* %8)
store i32 -3, i32* %4
br label %31
29: ; preds = %22
%30 = call i32 @regfree(%struct.TYPE_5__* %8)
store i32 0, i32* %4
br label %31
31: ; preds = %29, %27, %20, %15
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
define i32 @reg_match(i8* %0, i8* %1, i32* %2) {
%4 = alloca %struct.TYPE_5__
%5 = bitcast %struct.TYPE_5__* %4 to i8*
%6 = load i32, i32* @REG_EXTENDED
%7 = load i32, i32* @REG_NEWLINE
%8 = or i32 %7, %6
%9 = call i64 @regcomp(%struct.TYPE_5__* %4, i8* %0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = icmp sgt i32 %13, 6
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @regfree(%struct.TYPE_5__* %4)
br label %22
17: ; preds = %11
%18 = call i64 @regexec(%struct.TYPE_5__* %4, i8* %1, i32 6, i32* %2, i32 0)
%19 = icmp eq i64 %18, 0
%20 = call i32 @regfree(%struct.TYPE_5__* %4)
%21 = select i1 %19, i32 0, i32 -3
br label %22
22: ; preds = %17, %3, %15
%23 = phi i32 [ -2, %15 ], [ -1, %3 ], [ %21, %17 ]
ret i32 %23
}