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


x86 assembly (clang, -O0):
<validateURLAnon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     11d0 <validateURLAnon+0x90>
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0xff,%ecx
call   1050 <regerror@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126c <validateURLAnon+0x12c>
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jne    1206 <validateURLAnon+0xc6>
movl   $0x1,-0x4(%rbp)
jmp    126c <validateURLAnon+0x12c>
mov    -0x124(%rbp),%eax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
jne    1235 <validateURLAnon+0xf5>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    126c <validateURLAnon+0x12c>
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0xff,%ecx
call   1050 <regerror@plt>
lea    -0x120(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateURLAnon>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rbx
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
lea    0xe95(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11bd <validateURLAnon+0x6d>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1060 <regerror@plt>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x110,%rsp
pop    %rbx
ret
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
je     11f3 <validateURLAnon+0xa3>
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%eax
jne    11fa <validateURLAnon+0xaa>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    11b4 <validateURLAnon+0x64>
mov    $0x1,%eax
jmp    11b4 <validateURLAnon+0x64>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   1060 <regerror@plt>
lea    0xe4f(%rip),%rdi
jmp    11a5 <validateURLAnon+0x55>

LLVM IR (-O0):
@.str = [72 x i8] c"ftp://[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 = [14 x i8] c"Invalid URL!\0A\00"
@.str.4 = [32 x i8] c"Error while validating URL: %s\0A\00"
define i32 @validateURLAnon(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 ([72 x i8], [72 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 %40
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 1, i32* %3
br label %40
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 %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %40
34: ; preds = %28
%35 = load i32, i32* %9
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%37 = call i32 @regerror(i32 %35, i32* %6, i8* %36, i32 255)
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %38)
store i32 -1, i32* %3
br label %40
40: ; preds = %34, %32, %27, %15
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [72 x i8] c"ftp://[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.4 = [32 x i8] c"Error while validating URL: %s\0A\00"
@str = [13 x i8] c"Invalid URL!\00"
@str.5 = [27 x i8] c"Error while validating URL\00"
define i32 @validateURLAnon(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 ([72 x i8], [72 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.5, 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
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.4, i64 0, i64 0), i8* %6)
br label %25
25: ; preds = %14, %22, %20, %10
%26 = phi i32 [ -1, %10 ], [ 2, %20 ], [ -1, %22 ], [ 1, %14 ]
ret i32 %26
}