#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 */
scalar_t__ endsWith(char *, char *);
int /*<<< orphan*/ errAbort(char *, ...);
scalar_t__ startsWith(char *, char *);
scalar_t__ strstr(char *, char *);
char *assertLocalUrl(char *url) {
  if (startsWith("local:", url))
    url += 6;
  if (url[0] != '/')
    errAbort("Local urls must start at /");
  if (strstr(url, "..") || strstr(url, "~") || strstr(url, "//") ||
      strstr(url, "/./") || endsWith("/.", url)) {
    errAbort("relative paths not allowed in local urls (%s)", url);
  }
  return url;
}


x86 assembly (clang, -O0):
<assertLocalUrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <startsWith@plt>
cmp    $0x0,%rax
je     1172 <assertLocalUrl+0x32>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1190 <assertLocalUrl+0x50>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <errAbort@plt>
mov    -0x8(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    1212 <assertLocalUrl+0xd2>
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    1212 <assertLocalUrl+0xd2>
mov    -0x8(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    1212 <assertLocalUrl+0xd2>
mov    -0x8(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    1212 <assertLocalUrl+0xd2>
mov    -0x8(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1050 <endsWith@plt>
cmp    $0x0,%rax
je     1224 <assertLocalUrl+0xe4>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <errAbort@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assertLocalUrl>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
call   1030 <startsWith@plt>
test   %rax,%rax
mov    $0x6,%ecx
cmove  %rax,%rcx
lea    (%rbx,%rcx,1),%r14
cmpb   $0x2f,(%rbx,%rcx,1)
je     117a <assertLocalUrl+0x3a>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <errAbort@plt>
lea    0xea1(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11de <assertLocalUrl+0x9e>
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11de <assertLocalUrl+0x9e>
lea    0xe7e(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11de <assertLocalUrl+0x9e>
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11de <assertLocalUrl+0x9e>
lea    0xe5d(%rip),%rdi
mov    %r14,%rsi
call   1050 <endsWith@plt>
test   %rax,%rax
je     11ef <assertLocalUrl+0xaf>
lea    0xe4c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <errAbort@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"local:\00"
@.str.1 = [27 x i8] c"Local urls must start at /\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"~\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [4 x i8] c"/./\00"
@.str.6 = [3 x i8] c"/.\00"
@.str.7 = [46 x i8] c"relative paths not allowed in local urls (%s)\00"
define i8* @assertLocalUrl(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = call i64 @startsWith(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 6
store i8* %8, i8** %2
br label %9
9: ; preds = %6, %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 47
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @errAbort(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = load i8*, i8** %2
%19 = call i64 @strstr(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i64 @strstr(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %37, label %25
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8*, i8** %2
%31 = call i64 @strstr(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8*, i8** %2
%35 = call i64 @endsWith(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33, %29, %25, %21, %17
%38 = load i8*, i8** %2
%39 = call i32 (i8*, ...) @errAbort(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %33
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [7 x i8] c"local:\00"
@.str.1 = [27 x i8] c"Local urls must start at /\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"~\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [4 x i8] c"/./\00"
@.str.6 = [3 x i8] c"/.\00"
@.str.7 = [46 x i8] c"relative paths not allowed in local urls (%s)\00"
define i8* @assertLocalUrl(i8* %0) {
%2 = tail call i64 @startsWith(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i64 0, i64 6
%5 = getelementptr i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @errAbort(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = tail call i64 @strstr(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = tail call i64 @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = tail call i64 @strstr(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = tail call i64 @strstr(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i64 @endsWith(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22, %19, %16, %13, %10
%26 = tail call i32 (i8*, ...) @errAbort(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i8* %5)
br label %27
27: ; preds = %25, %22
ret i8* %5
}