#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;
typedef int /*<<< orphan*/ msgbuf;

/* Variables and functions */
int REG_NOMATCH;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
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 /*<<< orphan*/ stderr;
int check_string(char *str, char *regexp) {
  regex_t regex;
  int reti;
  int ret_val;
  char msgbuf[100];
  reti = regcomp(&regex, regexp, 0);
  if (reti) {
    fprintf(stderr, "Wrong regex (%s)\n", regexp);
    exit(1);
  }
  reti = regexec(&regex, str, 0, NULL, 0);
  if (!reti) {
    ret_val = 1;
  } else if (reti == REG_NOMATCH) {
    ret_val = 0;
  } else {
    regerror(reti, &regex, msgbuf, sizeof(msgbuf));
    fprintf(stderr, "Regex match failed: %s\n", msgbuf);
    exit(1);
  }
  regfree(&regex);
  return ret_val;
}


x86 assembly (clang, -O0):
<check_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %edx,%edx
call   1040 <regcomp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11b2 <check_string+0x52>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1070 <regexec@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11e2 <check_string+0x82>
movl   $0x1,-0x1c(%rbp)
jmp    123d <check_string+0xdd>
mov    -0x18(%rbp),%eax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
jne    1200 <check_string+0xa0>
movl   $0x0,-0x1c(%rbp)
jmp    1238 <check_string+0xd8>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x14(%rbp),%rsi
mov    $0x64,%ecx
call   1060 <regerror@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    123d <check_string+0xdd>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x1c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_string>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
xor    %edx,%edx
call   1040 <regcomp@plt>
test   %eax,%eax
jne    11ec <check_string+0x8c>
xor    %r14d,%r14d
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
je     11d1 <check_string+0x71>
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%eax
je     11d7 <check_string+0x77>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1060 <regerror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
mov    %rbx,%rdx
jmp    11ff <check_string+0x9f>
mov    $0x1,%r14d
lea    0xc(%rsp),%rdi
call   1030 <regfree@plt>
mov    %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Wrong regex (%s)\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @check_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @regcomp(i32* %5, i8* %9, i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = call i32 @regexec(i32* %5, i8* %19, i32 0, i32* null, i32 0)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %18
store i32 1, i32* %7
br label %38
24: ; preds = %18
%25 = load i32, i32* %6
%26 = load i32, i32* @REG_NOMATCH
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 0, i32* %7
br label %37
29: ; preds = %24
%30 = load i32, i32* %6
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%32 = call i32 @regerror(i32 %30, i32* %5, i8* %31, i32 100)
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
br label %38
38: ; preds = %37, %23
%39 = call i32 @regfree(i32* %5)
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Wrong regex (%s)\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @check_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = call i32 @regcomp(i32* %3, i8* %1, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = load i32, i32* @REG_NOMATCH
%18 = icmp eq i32 %14, %17
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = call i32 @regerror(i32 %14, i32* %3, i8* %6, i32 100)
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16, %13
%25 = phi i32 [ 1, %13 ], [ 0, %16 ]
%26 = call i32 @regfree(i32* %3)
ret i32 %25
}