#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*/ REG_EXTENDED;
int REG_NOMATCH;
int /*<<< orphan*/ printf(char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int URL_is_valid(const char *str) {
  int reg_err;
  regex_t regex;
  char url_expr[] =
      "^(http|https)\\:\\/{2}.*\\.(bandcamp)\\..*\\/(album|single)\\/.*$";
  reg_err = regcomp(&regex, url_expr, REG_EXTENDED);
  if (reg_err) {
    printf("%s\n", "INVALID REGEX");
    return 0;
  }
  reg_err = regexec(&regex, str, 0, NULL, 0);
  int valid = (reg_err != REG_NOMATCH);
  regfree(&regex);
  return valid;
}


x86 assembly (clang, -O0):
<URL_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
lea    -0x60(%rbp),%rsi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b3 <URL_is_valid+0x63>
lea    0xea1(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <URL_is_valid+0xa3>
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1070 <regexec@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x64(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<URL_is_valid>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
movups 0xedb(%rip),%xmm0
movups %xmm0,0x3c(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11ad <URL_is_valid+0x6d>
lea    0xe9f(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <printf@plt>
xor    %ebx,%ebx
jmp    11da <URL_is_valid+0x9a>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    0x2e1d(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%eax
setne  %bl
mov    %r14,%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.URL_is_valid.url_expr = [60 x i8] c"^(http|https)\\:\\/{2}.*\\.(bandcamp)\\..*\\/(album|single)\\/.*$\00"
@REG_EXTENDED = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"INVALID REGEX\00"
@REG_NOMATCH = global i32 0
define i32 @URL_is_valid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [60 x i8]
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [60 x i8]* %6 to i8*
%9 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @REG_EXTENDED
%11 = call i32 @regcomp(i32* %5, i8* %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %25
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @regexec(i32* %5, i8* %17, i32 0, i32* null, i32 0)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = load i32, i32* @REG_NOMATCH
%21 = icmp ne i32 %19, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %7
%23 = call i32 @regfree(i32* %5)
%24 = load i32, i32* %7
store i32 %24, i32* %2
br label %25
25: ; preds = %16, %14
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@__const.URL_is_valid.url_expr = [60 x i8] c"^(http|https)\\:\\/{2}.*\\.(bandcamp)\\..*\\/(album|single)\\/.*$\00"
@REG_EXTENDED = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"INVALID REGEX\00"
@REG_NOMATCH = global i32 0
define i32 @URL_is_valid(i8* %0) {
%2 = alloca i32
%3 = alloca [60 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @REG_EXTENDED
%7 = call i32 @regcomp(i32* %2, i8* %5, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %17
11: ; preds = %1
%12 = call i32 @regexec(i32* %2, i8* %0, i32 0, i32* null, i32 0)
%13 = load i32, i32* @REG_NOMATCH
%14 = icmp ne i32 %12, %13
%15 = zext i1 %14 to i32
%16 = call i32 @regfree(i32* %2)
br label %17
17: ; preds = %11, %9
%18 = phi i32 [ 0, %9 ], [ %15, %11 ]
ret i32 %18
}