#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ is_windows_path(char const *);
scalar_t__ serd_uri_string_has_scheme(char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char const *, char *, int);
const uint8_t *serd_uri_to_path(const uint8_t *uri) {
  const uint8_t *path = uri;
  if (uri[0] == '/' || is_windows_path(uri)) {
    return uri;
  } else if (serd_uri_string_has_scheme(uri)) {
    if (strncmp((const char *)uri, "file:", 5)) {
      fprintf(stderr, "Non-file URI `%s'\n", uri);
      return NULL;
    } else if (!strncmp((const char *)uri, "file://localhost/", 17)) {
      path = uri + 16;
    } else if (!strncmp((const char *)uri, "file://", 7)) {
      path = uri + 7;
    } else {
      fprintf(stderr, "Invalid file URI `%s'\n", uri);
      return NULL;
    }
    if (is_windows_path(path + 1)) {
      ++path;
    }
  }
  return path;
}


x86 assembly (clang, -O0):
<serd_uri_to_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1177 <serd_uri_to_path+0x37>
mov    -0x10(%rbp),%rdi
call   1040 <is_windows_path@plt>
cmp    $0x0,%rax
je     1184 <serd_uri_to_path+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a1 <serd_uri_to_path+0x161>
mov    -0x10(%rbp),%rdi
call   1060 <serd_uri_string_has_scheme@plt>
cmp    $0x0,%rax
je     1294 <serd_uri_to_path+0x154>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11dc <serd_uri_to_path+0x9c>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <serd_uri_to_path+0x161>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x11,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120c <serd_uri_to_path+0xcc>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    1267 <serd_uri_to_path+0x127>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    123c <serd_uri_to_path+0xfc>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
jmp    1262 <serd_uri_to_path+0x122>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <serd_uri_to_path+0x161>
jmp    1267 <serd_uri_to_path+0x127>
jmp    126c <serd_uri_to_path+0x12c>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <is_windows_path@plt>
cmp    $0x0,%rax
je     128f <serd_uri_to_path+0x14f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1294 <serd_uri_to_path+0x154>
jmp    1299 <serd_uri_to_path+0x159>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serd_uri_to_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
je     1214 <serd_uri_to_path+0xd4>
mov    %rbx,%rdi
call   1040 <is_windows_path@plt>
test   %rax,%rax
jne    1214 <serd_uri_to_path+0xd4>
mov    %rbx,%rdi
call   1060 <serd_uri_string_has_scheme@plt>
test   %rax,%rax
je     1214 <serd_uri_to_path+0xd4>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a7 <serd_uri_to_path+0x67>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    1214 <serd_uri_to_path+0xd4>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x11,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11eb <serd_uri_to_path+0xab>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11f2 <serd_uri_to_path+0xb2>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    119b <serd_uri_to_path+0x5b>
mov    $0x10,%eax
jmp    11f7 <serd_uri_to_path+0xb7>
mov    $0x7,%eax
lea    (%rbx,%rax,1),%r14
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <is_windows_path@plt>
test   %rax,%rax
cmovne %rbx,%r14
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file:\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Non-file URI `%s'\0A\00"
@.str.2 = [18 x i8] c"file://localhost/\00"
@.str.3 = [8 x i8] c"file://\00"
@.str.4 = [23 x i8] c"Invalid file URI `%s'\0A\00"
define i8* @serd_uri_to_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 47
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @is_windows_path(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11, %1
%16 = load i8*, i8** %3
store i8* %16, i8** %2
br label %61
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = call i64 @serd_uri_string_has_scheme(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %58
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %3
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i8* null, i8** %2
br label %61
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%32 = icmp ne i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 16
store i8* %35, i8** %4
br label %48
36: ; preds = %29
%37 = load i8*, i8** %3
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%39 = icmp ne i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 7
store i8* %42, i8** %4
br label %47
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %3
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %45)
store i8* null, i8** %2
br label %61
47: ; preds = %40
br label %48
48: ; preds = %47, %33
br label %49
49: ; preds = %48
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = call i64 @is_windows_path(i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
br label %57
57: ; preds = %54, %49
br label %58
58: ; preds = %57, %17
br label %59
59: ; preds = %58
%60 = load i8*, i8** %4
store i8* %60, i8** %2
br label %61
61: ; preds = %59, %43, %25, %15
%62 = load i8*, i8** %2
ret i8* %62
}

LLVM IR (-O2):
@.str = [6 x i8] c"file:\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Non-file URI `%s'\0A\00"
@.str.2 = [18 x i8] c"file://localhost/\00"
@.str.3 = [8 x i8] c"file://\00"
@.str.4 = [23 x i8] c"Invalid file URI `%s'\0A\00"
define i8* @serd_uri_to_path(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call i64 @is_windows_path(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %4
%8 = tail call i64 @serd_uri_string_has_scheme(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %7
%11 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %32
16: ; preds = %10
%17 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %32
25: ; preds = %19, %16
%26 = phi i64 [ 16, %16 ], [ 7, %19 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = tail call i64 @is_windows_path(i8* %28)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i8* %27, i8* %28
br label %32
32: ; preds = %25, %7, %1, %4, %22, %13
%33 = phi i8* [ null, %13 ], [ null, %22 ], [ %0, %4 ], [ %0, %1 ], [ %0, %7 ], [ %31, %25 ]
ret i8* %33
}