#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int string_match_regex(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int whole_string_match_regex(const char *text, const char *pattern) {
  char *new_pattern;
  int result;
  if (!pattern || !text)
    return 0;
  new_pattern = (char *)malloc(sizeof(char) * (strlen(pattern) + 3));
  if (!new_pattern)
    return 0;
  new_pattern[0] = '\0';
  if (*pattern != '^')
    strncat(new_pattern, "^", 1);
  strncat(new_pattern, pattern, strlen(pattern));
  if (pattern[strlen(pattern) - 1] != '$')
    strncat(new_pattern, "$", 1);
  result = string_match_regex(text, new_pattern);
  free(new_pattern);
  return result;
}


x86 assembly (clang, -O0):
<whole_string_match_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1176 <whole_string_match_regex+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <whole_string_match_regex+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1268 <whole_string_match_regex+0x118>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <whole_string_match_regex+0x66>
movl   $0x0,-0x4(%rbp)
jmp    1268 <whole_string_match_regex+0x118>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
je     11e2 <whole_string_match_regex+0x92>
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
je     1249 <whole_string_match_regex+0xf9>
mov    -0x20(%rbp),%rdi
lea    0xdc3(%rip),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <string_match_regex@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whole_string_match_regex>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11f4 <whole_string_match_regex+0xa4>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11f4 <whole_string_match_regex+0xa4>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f4 <whole_string_match_regex+0xa4>
mov    %rax,%r15
movb   $0x0,(%rax)
cmpb   $0x5e,(%rbx)
je     11a1 <whole_string_match_regex+0x51>
lea    0xe6c(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x24,-0x1(%rax,%rbx,1)
je     11db <whole_string_match_regex+0x8b>
lea    0xe34(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <string_match_regex@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11f6 <whole_string_match_regex+0xa6>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"^\00"
@.str.1 = [2 x i8] c"$\00"
define i32 @whole_string_match_regex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %61
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 3
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %14
store i32 0, i32* %3
br label %61
26: ; preds = %14
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 0, i8* %28
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 94
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i8*, i8** %6
%35 = call i32 @strncat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %36
36: ; preds = %33, %26
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = load i8*, i8** %5
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @strncat(i8* %37, i8* %38, i32 %40)
%42 = load i8*, i8** %5
%43 = load i8*, i8** %5
%44 = call i32 @strlen(i8* %43)
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %42, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 36
br i1 %50, label %51, label %54
51: ; preds = %36
%52 = load i8*, i8** %6
%53 = call i32 @strncat(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %54
54: ; preds = %51, %36
%55 = load i8*, i8** %4
%56 = load i8*, i8** %6
%57 = call i32 @string_match_regex(i8* %55, i8* %56)
store i32 %57, i32* %7
%58 = load i8*, i8** %6
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %7
store i32 %60, i32* %3
br label %61
61: ; preds = %54, %25, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"^\00"
@.str.1 = [2 x i8] c"$\00"
define i32 @whole_string_match_regex(i8* %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = icmp ne i8* %0, null
%5 = and i1 %4, %3
br i1 %5, label %6, label %31
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 3
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %31, label %12
12: ; preds = %6
store i8 0, i8* %10
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 94
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @strncat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %17
17: ; preds = %15, %12
%18 = tail call i32 @strlen(i8* %1)
%19 = tail call i32 @strncat(i8* %10, i8* %1, i32 %18)
%20 = tail call i32 @strlen(i8* %1)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 36
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = tail call i32 @strncat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %28
28: ; preds = %26, %17
%29 = tail call i32 @string_match_regex(i8* %0, i8* %10)
%30 = tail call i32 @free(i8* %10)
br label %31
31: ; preds = %6, %2, %28
%32 = phi i32 [ %29, %28 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %32
}