#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 /*<<< orphan*/ NOEXPR;
int REG_EXTENDED;
int REG_NOSUB;
int /*<<< orphan*/ YESEXPR;
int /*<<< orphan*/ nl_langinfo(int /*<<< orphan*/);
scalar_t__ regcomp(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int rpmatch(const char *response) {
  regex_t yes, no;
  int ret;
  if (regcomp(&yes, nl_langinfo(YESEXPR), REG_EXTENDED | REG_NOSUB) != 0)
    return (-1);
  if (regcomp(&no, nl_langinfo(NOEXPR), REG_EXTENDED | REG_NOSUB) != 0) {
    regfree(&yes);
    return (-1);
  }
  if (regexec(&yes, response, 0, NULL, 0) == 0)
    ret = 1;
  else if (regexec(&no, response, 0, NULL, 0) == 0)
    ret = 0;
  else
    ret = -1;
  regfree(&yes);
  regfree(&no);
  return (ret);
}


x86 assembly (clang, -O0):
<rpmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %eax,%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    0x2e6c(%rip),%rax
or     (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     118d <rpmatch+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <rpmatch+0x115>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %eax,%esi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    0x2e2b(%rip),%rax
or     (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11d7 <rpmatch+0x97>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <rpmatch+0x115>
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
cmp    $0x0,%rax
jne    1204 <rpmatch+0xc4>
movl   $0x1,-0x1c(%rbp)
jmp    123d <rpmatch+0xfd>
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
cmp    $0x0,%rax
jne    1231 <rpmatch+0xf1>
movl   $0x0,-0x1c(%rbp)
jmp    1238 <rpmatch+0xf8>
movl   $0xffffffff,-0x1c(%rbp)
jmp    123d <rpmatch+0xfd>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
lea    -0x18(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpmatch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    0x2e64(%rip),%r14
mov    0x2e6d(%rip),%r12
mov    (%r12),%edx
or     (%r14),%edx
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <regcomp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1207 <rpmatch+0xc7>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    (%r12),%edx
or     (%r14),%edx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <regcomp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11ff <rpmatch+0xbf>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %rax,%rax
je     11ed <rpmatch+0xad>
lea    0xc(%rsp),%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
neg    %rax
sbb    %ebp,%ebp
jmp    11f2 <rpmatch+0xb2>
mov    $0x1,%ebp
lea    0x8(%rsp),%rdi
call   1030 <regfree@plt>
mov    %r14,%rbx
mov    %rbx,%rdi
call   1030 <regfree@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@YESEXPR = global i32 0
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@NOEXPR = global i32 0
define i32 @rpmatch(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i32, i32* @YESEXPR
%8 = call i32 @nl_langinfo(i32 %7)
%9 = load i32, i32* @REG_EXTENDED
%10 = load i32, i32* @REG_NOSUB
%11 = or i32 %9, %10
%12 = call i64 @regcomp(i32* %4, i32 %8, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %41
15: ; preds = %1
%16 = load i32, i32* @NOEXPR
%17 = call i32 @nl_langinfo(i32 %16)
%18 = load i32, i32* @REG_EXTENDED
%19 = load i32, i32* @REG_NOSUB
%20 = or i32 %18, %19
%21 = call i64 @regcomp(i32* %5, i32 %17, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @regfree(i32* %4)
store i32 -1, i32* %2
br label %41
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = call i64 @regexec(i32* %4, i8* %26, i32 0, i32* null, i32 0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 1, i32* %6
br label %37
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = call i64 @regexec(i32* %5, i8* %31, i32 0, i32* null, i32 0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %6
br label %36
35: ; preds = %30
store i32 -1, i32* %6
br label %36
36: ; preds = %35, %34
br label %37
37: ; preds = %36, %29
%38 = call i32 @regfree(i32* %4)
%39 = call i32 @regfree(i32* %5)
%40 = load i32, i32* %6
store i32 %40, i32* %2
br label %41
41: ; preds = %37, %23, %14
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@YESEXPR = global i32 0
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@NOEXPR = global i32 0
define i32 @rpmatch(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @YESEXPR
%7 = tail call i32 @nl_langinfo(i32 %6)
%8 = load i32, i32* @REG_EXTENDED
%9 = load i32, i32* @REG_NOSUB
%10 = or i32 %9, %8
%11 = call i64 @regcomp(i32* %2, i32 %7, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %1
%14 = load i32, i32* @NOEXPR
%15 = call i32 @nl_langinfo(i32 %14)
%16 = load i32, i32* @REG_EXTENDED
%17 = load i32, i32* @REG_NOSUB
%18 = or i32 %17, %16
%19 = call i64 @regcomp(i32* %3, i32 %15, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %13
%22 = call i64 @regexec(i32* %2, i8* %0, i32 0, i32* null, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i64 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%26 = icmp ne i64 %25, 0
%27 = sext i1 %26 to i32
br label %28
28: ; preds = %24, %21
%29 = phi i32 [ 1, %21 ], [ %27, %24 ]
%30 = call i32 @regfree(i32* %2)
br label %31
31: ; preds = %13, %28
%32 = phi i32* [ %3, %28 ], [ %2, %13 ]
%33 = phi i32 [ %29, %28 ], [ -1, %13 ]
%34 = call i32 @regfree(i32* %32)
br label %35
35: ; preds = %31, %1
%36 = phi i32 [ -1, %1 ], [ %33, %31 ]
ret i32 %36
}