#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_ICASE;
int REG_NOERROR;
int REG_NOMATCH;
int REG_NOSUB;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(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*/ stderr;
int match_buffer(regex_t *preg, char *pat, char *buf, char *errbuf,
                 int errbuflen) {
  int r;
  r = regcomp(preg, pat, REG_EXTENDED | REG_ICASE | REG_NOSUB);
  if (r) {
    regerror(r, preg, errbuf, errbuflen);
    fprintf(stderr, "error in regcomp: %s\n", errbuf);
    exit(1);
  }
  r = regexec(preg, buf, 0, 0, 0);
  if (r == REG_NOMATCH) {
    fprintf(stderr, "no match\n");
  } else if (r != REG_NOERROR) {
    regerror(r, preg, errbuf, errbuflen);
    fprintf(stderr, "error in regexec: %s\n", errbuf);
    return (-1);
  }
  printf("match\n");
  return (0);
}


x86 assembly (clang, -O0):
<match_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    0x2e54(%rip),%rax
or     (%rax),%edx
mov    0x2e2b(%rip),%rax
or     (%rax),%edx
call   1040 <regcomp@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11e9 <match_buffer+0x89>
mov    -0x30(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1060 <regerror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1070 <regexec@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%eax
jne    1230 <match_buffer+0xd0>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1281 <match_buffer+0x121>
mov    -0x30(%rbp),%eax
mov    0x2da6(%rip),%rcx
cmp    (%rcx),%eax
je     127c <match_buffer+0x11c>
mov    -0x30(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1060 <regerror@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <match_buffer+0x134>
jmp    1281 <match_buffer+0x121>
lea    0xd91(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e4a(%rip),%rbp
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
or     0x0(%rbp),%eax
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rdi,%rbx
mov    0x2e3b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%edx
call   1040 <regcomp@plt>
test   %eax,%eax
jne    1229 <match_buffer+0xc9>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <regexec@plt>
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
jne    11d4 <match_buffer+0x74>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11df <match_buffer+0x7f>
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%eax
jne    11ef <match_buffer+0x8f>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    121e <match_buffer+0xbe>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <regerror@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <regerror@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"error in regcomp: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [10 x i8] c"no match\0A\00"
@REG_NOERROR = global i32 0
@.str.2 = [22 x i8] c"error in regexec: %s\0A\00"
@.str.3 = [7 x i8] c"match\0A\00"
define i32 @match_buffer(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i32*, i32** %7
%14 = load i8*, i8** %8
%15 = load i32, i32* @REG_EXTENDED
%16 = load i32, i32* @REG_ICASE
%17 = or i32 %15, %16
%18 = load i32, i32* @REG_NOSUB
%19 = or i32 %17, %18
%20 = call i32 @regcomp(i32* %13, i8* %14, i32 %19)
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %5
%24 = load i32, i32* %12
%25 = load i32*, i32** %7
%26 = load i8*, i8** %10
%27 = load i32, i32* %11
%28 = call i32 @regerror(i32 %24, i32* %25, i8* %26, i32 %27)
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %10
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %5
%34 = load i32*, i32** %7
%35 = load i8*, i8** %9
%36 = call i32 @regexec(i32* %34, i8* %35, i32 0, i32 0, i32 0)
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = load i32, i32* @REG_NOMATCH
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %57
43: ; preds = %33
%44 = load i32, i32* %12
%45 = load i32, i32* @REG_NOERROR
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %12
%49 = load i32*, i32** %7
%50 = load i8*, i8** %10
%51 = load i32, i32* %11
%52 = call i32 @regerror(i32 %48, i32* %49, i8* %50, i32 %51)
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %10
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %54)
store i32 -1, i32* %6
br label %59
56: ; preds = %43
br label %57
57: ; preds = %56, %40
%58 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %59
59: ; preds = %57, %47
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"error in regcomp: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [10 x i8] c"no match\0A\00"
@REG_NOERROR = global i32 0
@.str.2 = [22 x i8] c"error in regexec: %s\0A\00"
@str = [6 x i8] c"match\00"
define i32 @match_buffer(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = load i32, i32* @REG_EXTENDED
%7 = load i32, i32* @REG_ICASE
%8 = or i32 %7, %6
%9 = load i32, i32* @REG_NOSUB
%10 = or i32 %8, %9
%11 = tail call i32 @regcomp(i32* %0, i8* %1, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %5
%14 = tail call i32 @regerror(i32 %11, i32* %0, i8* %3, i32 %4)
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %3)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %5
%19 = tail call i32 @regexec(i32* %0, i8* %2, i32 0, i32 0, i32 0)
%20 = load i32, i32* @REG_NOMATCH
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %32
25: ; preds = %18
%26 = load i32, i32* @REG_NOERROR
%27 = icmp eq i32 %19, %26
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i32 @regerror(i32 %19, i32* %0, i8* %3, i32 %4)
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %34
32: ; preds = %25, %22
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = phi i32 [ 0, %32 ], [ -1, %28 ]
ret i32 %35
}