#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 */
int REG_EXTENDED;
int REG_NEWLINE;
int REG_NOSUB;
int /*<<< orphan*/ printf(char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int regmatch(char *regex, char *string) {
  regex_t r;
  int ret;
  if ((ret = regcomp(&r, regex, REG_EXTENDED | REG_NOSUB | REG_NEWLINE)) != 0) {
    char error[1024];
    regerror(ret, &r, error, 1024);
    printf("ERR: regex compilation error: %s\n", error);
    printf("ERR: regex used: '%s'\n", regex);
    return 1;
  }
  if ((ret = regexec(&r, string, 0, NULL, 0)) != 0) {
    char error[1024];
    regerror(ret, &r, error, 1024);
    printf("ERR: regex match error: %s\n", error);
    printf("ERR: regex used: '%s'\n", regex);
    printf("ERR: string used: '%s'\n", string);
    return 1;
  }
  regfree(&r);
  return 0;
}


x86 assembly (clang, -O0):
<regmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    0x2e61(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     11de <regmatch+0x8e>
mov    -0x20(%rbp),%edi
lea    -0x420(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0x400,%ecx
call   1060 <regerror@plt>
lea    -0x420(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <regmatch+0x118>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1070 <regexec@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1258 <regmatch+0x108>
mov    -0x20(%rbp),%edi
lea    -0x820(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0x400,%ecx
call   1060 <regerror@plt>
lea    -0x820(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <regmatch+0x118>
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regmatch>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2e6d(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
lea    0xc(%rsp),%rdi
mov    %r15,%rsi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11c2 <regmatch+0x72>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1060 <regerror@plt>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe65(%rip),%rdi
mov    %r15,%rsi
jmp    121d <regmatch+0xcd>
xor    %ebx,%ebx
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
je     1236 <regmatch+0xe6>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1060 <regerror@plt>
lea    0xe3d(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe17(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xc(%rsp),%rdi
call   1030 <regfree@plt>
jmp    1227 <regmatch+0xd7>

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@.str = [34 x i8] c"ERR: regex compilation error: %s\0A\00"
@.str.1 = [23 x i8] c"ERR: regex used: '%s'\0A\00"
@.str.2 = [28 x i8] c"ERR: regex match error: %s\0A\00"
@.str.3 = [24 x i8] c"ERR: string used: '%s'\0A\00"
define i32 @regmatch(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = load i32, i32* @REG_EXTENDED
%12 = load i32, i32* @REG_NOSUB
%13 = or i32 %11, %12
%14 = load i32, i32* @REG_NEWLINE
%15 = or i32 %13, %14
%16 = call i32 @regcomp(i32* %6, i8* %10, i32 %15)
store i32 %16, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %2
%19 = load i32, i32* %7
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = call i32 @regerror(i32 %19, i32* %6, i8* %20, i32 1024)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %42
26: ; preds = %2
%27 = load i8*, i8** %5
%28 = call i32 @regexec(i32* %6, i8* %27, i32 0, i32* null, i32 0)
store i32 %28, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i32, i32* %7
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%33 = call i32 @regerror(i32 %31, i32* %6, i8* %32, i32 1024)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %4
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %5
%39 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %38)
store i32 1, i32* %3
br label %42
40: ; preds = %26
%41 = call i32 @regfree(i32* %6)
store i32 0, i32* %3
br label %42
42: ; preds = %40, %30, %18
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@.str = [34 x i8] c"ERR: regex compilation error: %s\0A\00"
@.str.1 = [23 x i8] c"ERR: regex used: '%s'\0A\00"
@.str.2 = [28 x i8] c"ERR: regex match error: %s\0A\00"
@.str.3 = [24 x i8] c"ERR: string used: '%s'\0A\00"
define i32 @regmatch(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @REG_EXTENDED
%8 = load i32, i32* @REG_NOSUB
%9 = or i32 %8, %7
%10 = load i32, i32* @REG_NEWLINE
%11 = or i32 %9, %10
%12 = call i32 @regcomp(i32* %3, i8* %0, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i32 @regerror(i32 %12, i32* %3, i8* %15, i32 1024)
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15)
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %30
19: ; preds = %2
%20 = call i32 @regexec(i32* %3, i8* %1, i32 0, i32* null, i32 0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = call i32 @regerror(i32 %20, i32* %3, i8* %23, i32 1024)
%25 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %30
28: ; preds = %19
%29 = call i32 @regfree(i32* %3)
br label %30
30: ; preds = %28, %22, %14
%31 = phi i32 [ 1, %14 ], [ 1, %22 ], [ 0, %28 ]
ret i32 %31
}