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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
int /*<<< orphan*/ printf(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 validateURLAnon(char *, int);
int validateURL(char *url, int size) {
  regex_t regex;
  char *regex_auth =
      "ftp://[A-Za-z0-9]+:[A-Za-z0-9]+@[A-Za-z0-9._~:?#!$&'()*+,:;=-]+/"
      "[A-Za-z0-9._~:/?#@!$&'()*+,:;=-]+";
  char regcomp_err[255];
  int reti = regcomp(&regex, regex_auth, REG_EXTENDED);
  if (reti) {
    regerror(reti, &regex, regcomp_err, sizeof(regcomp_err));
    printf("Error while validating URL\n");
    printf("Error while compiling regex: %s\n", regcomp_err);
    return -1;
  }
  reti = regexec(&regex, url, 0, NULL, 0);
  if (!reti) {
    return 0;
  } else if (reti == REG_NOMATCH) {
    return validateURLAnon(url, size);
  } else {
    regerror(reti, &regex, regcomp_err, sizeof(regcomp_err));
    printf("Error while validating URL: %s\n", regcomp_err);
    return -1;
  }
}


x86 assembly (clang, -O0):
<validateURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     11e0 <validateURL+0x90>
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0xff,%ecx
call   1060 <regerror@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <validateURL+0x126>
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,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jne    1216 <validateURL+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    1276 <validateURL+0x126>
mov    -0x124(%rbp),%eax
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
jne    123f <validateURL+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <validateURLAnon@plt>
mov    %eax,-0x4(%rbp)
jmp    1276 <validateURL+0x126>
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0xff,%ecx
call   1060 <regerror@plt>
lea    -0x120(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateURL>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1060 <regcomp@plt>
test   %eax,%eax
je     11d8 <validateURL+0x78>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1070 <regerror@plt>
lea    0xef4(%rip),%rdi
call   1040 <puts@plt>
lea    0xea7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11ca <validateURL+0x6a>
mov    0x2def(%rip),%rcx
cmp    (%rcx),%eax
jne    120c <validateURL+0xac>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <validateURLAnon@plt>
mov    %eax,%ebp
jmp    11ca <validateURL+0x6a>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1070 <regerror@plt>
lea    0xe57(%rip),%rdi
jmp    11bb <validateURL+0x5b>

LLVM IR (-O0):
@.str = [98 x i8] c"ftp://[A-Za-z0-9]+:[A-Za-z0-9]+@[A-Za-z0-9._~:?#!$&'()*+,:;=-]+/[A-Za-z0-9._~:/?#@!$&'()*+,:;=-]+\00"
@REG_EXTENDED = global i32 0
@.str.1 = [28 x i8] c"Error while validating URL\0A\00"
@.str.2 = [33 x i8] c"Error while compiling regex: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.3 = [32 x i8] c"Error while validating URL: %s\0A\00"
define i32 @validateURL(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [255 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = load i8*, i8** %7
%11 = load i32, i32* @REG_EXTENDED
%12 = call i32 @regcomp(i32* %6, i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* %9
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%18 = call i32 @regerror(i32 %16, i32* %6, i8* %17, i32 255)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %42
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = call i32 @regexec(i32* %6, i8* %23, i32 0, i32* null, i32 0)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 0, i32* %3
br label %42
28: ; preds = %22
%29 = load i32, i32* %9
%30 = load i32, i32* @REG_NOMATCH
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = call i32 @validateURLAnon(i8* %33, i32 %34)
store i32 %35, i32* %3
br label %42
36: ; preds = %28
%37 = load i32, i32* %9
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%39 = call i32 @regerror(i32 %37, i32* %6, i8* %38, i32 255)
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %40)
store i32 -1, i32* %3
br label %42
42: ; preds = %36, %32, %27, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [98 x i8] c"ftp://[A-Za-z0-9]+:[A-Za-z0-9]+@[A-Za-z0-9._~:?#!$&'()*+,:;=-]+/[A-Za-z0-9._~:/?#@!$&'()*+,:;=-]+\00"
@REG_EXTENDED = global i32 0
@.str.2 = [33 x i8] c"Error while compiling regex: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.3 = [32 x i8] c"Error while validating URL: %s\0A\00"
@str = [27 x i8] c"Error while validating URL\00"
define i32 @validateURL(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @REG_EXTENDED
%8 = call i32 @regcomp(i32* %3, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i32 @regerror(i32 %8, i32* %3, i8* %6, i32 255)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %25
14: ; preds = %2
%15 = call i32 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = load i32, i32* @REG_NOMATCH
%19 = icmp eq i32 %15, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @validateURLAnon(i8* %0, i32 %1)
br label %25
22: ; preds = %17
%23 = call i32 @regerror(i32 %15, i32* %3, i8* %6, i32 255)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %25
25: ; preds = %14, %22, %20, %10
%26 = phi i32 [ -1, %10 ], [ %21, %20 ], [ -1, %22 ], [ 0, %14 ]
ret i32 %26
}