#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 (!is_windows_path(uri) && serd_uri_string_has_scheme(uri)) {
    if (strncmp((const char *)uri, "file:", 5)) {
      fprintf(stderr, "Non-file URI `%s'\n", uri);
      return NULL;
    }
    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),%rdi
call   1040 <is_windows_path@plt>
cmp    $0x0,%rax
jne    1272 <serd_uri_to_path+0x132>
mov    -0x10(%rbp),%rdi
call   1060 <serd_uri_string_has_scheme@plt>
cmp    $0x0,%rax
je     1272 <serd_uri_to_path+0x132>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bf <serd_uri_to_path+0x7f>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <serd_uri_to_path+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x11,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ef <serd_uri_to_path+0xaf>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    124a <serd_uri_to_path+0x10a>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121f <serd_uri_to_path+0xdf>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
jmp    1245 <serd_uri_to_path+0x105>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <serd_uri_to_path+0x13a>
jmp    124a <serd_uri_to_path+0x10a>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <is_windows_path@plt>
cmp    $0x0,%rax
je     126d <serd_uri_to_path+0x12d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <serd_uri_to_path+0x132>
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
call   1040 <is_windows_path@plt>
test   %rax,%rax
jne    1208 <serd_uri_to_path+0xc8>
mov    %rbx,%rdi
call   1060 <serd_uri_string_has_scheme@plt>
test   %rax,%rax
je     1208 <serd_uri_to_path+0xc8>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     119b <serd_uri_to_path+0x5b>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    1208 <serd_uri_to_path+0xc8>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
mov    $0x11,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11df <serd_uri_to_path+0x9f>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e6 <serd_uri_to_path+0xa6>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
jmp    118f <serd_uri_to_path+0x4f>
mov    $0x10,%eax
jmp    11eb <serd_uri_to_path+0xab>
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 = call i64 @is_windows_path(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %49, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @serd_uri_string_has_scheme(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i8* null, i8** %2
br label %51
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%24 = icmp ne i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 16
store i8* %27, i8** %4
br label %40
28: ; preds = %21
%29 = load i8*, i8** %3
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%31 = icmp ne i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 7
store i8* %34, i8** %4
br label %39
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %3
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %37)
store i8* null, i8** %2
br label %51
39: ; preds = %32
br label %40
40: ; preds = %39, %25
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i64 @is_windows_path(i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
br label %48
48: ; preds = %45, %40
br label %49
49: ; preds = %48, %9, %1
%50 = load i8*, i8** %4
store i8* %50, i8** %2
br label %51
51: ; preds = %49, %35, %17
%52 = load i8*, i8** %2
ret i8* %52
}

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 = tail call i64 @is_windows_path(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %29
4: ; preds = %1
%5 = tail call i64 @serd_uri_string_has_scheme(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %4
%8 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %29
13: ; preds = %7
%14 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 17)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %29
22: ; preds = %16, %13
%23 = phi i64 [ 16, %13 ], [ 7, %16 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = tail call i64 @is_windows_path(i8* %25)
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i8* %24, i8* %25
br label %29
29: ; preds = %22, %1, %4, %19, %10
%30 = phi i8* [ null, %10 ], [ null, %19 ], [ %0, %1 ], [ %0, %4 ], [ %28, %22 ]
ret i8* %30
}