#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__ strncasecmp(char *, char *, int);
int xtov(char const);
void scan_local_address(char *s, char const **path_s) {
  char *w;
  char const *r;
  if (strncasecmp(s, "local:", 6) == 0)
    s += 6;
  else if (strncasecmp(s, "unix:", 5) == 0)
    s += 5;
  while (*s == '/' && (s[1] == '/'))
    s++;
  for (r = w = s; *r != '\0';) {
    int a, b;
    if (*r == '%' && (a = xtov(r[1])) != -1 && (b = xtov(r[2])) != -1) {
      *w++ = (a << 4) | b;
      r += 3;
    } else
      *w++ = *r++;
  }
  *w = '\0';
  *path_s = s;
}


x86 assembly (clang, -O0):
<scan_local_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec5(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1160 <scan_local_address+0x40>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <scan_local_address+0x70>
mov    -0x8(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    118b <scan_local_address+0x6b>
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <scan_local_address+0x70>
jmp    1195 <scan_local_address+0x75>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x29(%rbp)
jne    11bb <scan_local_address+0x9b>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11cb <scan_local_address+0xab>
jmp    11dc <scan_local_address+0xbc>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <scan_local_address+0x75>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     128e <scan_local_address+0x16e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1267 <scan_local_address+0x147>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <xtov@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1267 <scan_local_address+0x147>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <xtov@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     1267 <scan_local_address+0x147>
mov    -0x24(%rbp),%eax
shl    $0x4,%eax
or     -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    1289 <scan_local_address+0x169>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11e8 <scan_local_address+0xc8>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_local_address>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecb(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     1166 <scan_local_address+0x46>
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1040 <strncasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%rcx
jmp    116b <scan_local_address+0x4b>
mov    $0x6,%ecx
lea    (%rbx,%rcx,1),%rax
cmpb   $0x2f,(%rbx,%rcx,1)
sete   %cl
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%r15
test   $0x1,%cl
je     1195 <scan_local_address+0x75>
lea    0x1(%r15),%rax
mov    $0x1,%cl
cmpb   $0x2f,0x1(%r15)
je     1180 <scan_local_address+0x60>
mov    %r15,%rbp
mov    %r15,%rbx
jmp    11b2 <scan_local_address+0x92>
nopl   (%rax)
test   %al,%al
je     11ec <scan_local_address+0xcc>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl 0x0(%rbp),%eax
cmp    $0x25,%al
jne    11a0 <scan_local_address+0x80>
movsbl 0x1(%rbp),%edi
call   1030 <xtov@plt>
cmp    $0xffffffff,%eax
je     11a4 <scan_local_address+0x84>
mov    %eax,%r12d
movsbl 0x2(%rbp),%edi
call   1030 <xtov@plt>
cmp    $0xffffffff,%eax
je     11a4 <scan_local_address+0x84>
shl    $0x4,%r12d
or     %r12d,%eax
mov    %al,(%rbx)
add    $0x3,%rbp
add    $0x1,%rbx
jmp    11b2 <scan_local_address+0x92>
movb   $0x0,(%rbx)
mov    %r15,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"local:\00"
@.str.1 = [6 x i8] c"unix:\00"
define void @scan_local_address(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%9 = load i8*, i8** %3
%10 = call i64 @strncasecmp(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 6
store i8* %14, i8** %3
br label %23
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i64 @strncasecmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 5
store i8* %21, i8** %3
br label %22
22: ; preds = %19, %15
br label %23
23: ; preds = %22, %12
br label %24
24: ; preds = %37, %23
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 47
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br label %35
35: ; preds = %29, %24
%36 = phi i1 [ false, %24 ], [ %34, %29 ]
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
br label %24
40: ; preds = %35
%41 = load i8*, i8** %3
store i8* %41, i8** %5
store i8* %41, i8** %6
br label %42
42: ; preds = %80, %40
%43 = load i8*, i8** %6
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %81
47: ; preds = %42
%48 = load i8*, i8** %6
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 37
br i1 %51, label %52, label %74
52: ; preds = %47
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = call i32 @xtov(i8 signext %55)
store i32 %56, i32* %7
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %74
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 2
%61 = load i8, i8* %60
%62 = call i32 @xtov(i8 signext %61)
store i32 %62, i32* %8
%63 = icmp ne i32 %62, -1
br i1 %63, label %64, label %74
64: ; preds = %58
%65 = load i32, i32* %7
%66 = shl i32 %65, 4
%67 = load i32, i32* %8
%68 = or i32 %66, %67
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %5
store i8 %69, i8* %70
%72 = load i8*, i8** %6
%73 = getelementptr inbounds i8, i8* %72, i64 3
store i8* %73, i8** %6
br label %80
74: ; preds = %58, %52, %47
%75 = load i8*, i8** %6
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %6
%77 = load i8, i8* %75
%78 = load i8*, i8** %5
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %5
store i8 %77, i8* %78
br label %80
80: ; preds = %74, %64
br label %42
81: ; preds = %42
%82 = load i8*, i8** %5
store i8 0, i8* %82
%83 = load i8*, i8** %3
%84 = load i8**, i8*** %4
store i8* %83, i8** %84
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"local:\00"
@.str.1 = [6 x i8] c"unix:\00"
define void @scan_local_address(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i64 5, i64 0
br label %9
9: ; preds = %2, %5
%10 = phi i64 [ %8, %5 ], [ 6, %2 ]
%11 = getelementptr i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br label %14
14: ; preds = %17, %9
%15 = phi i1 [ %13, %9 ], [ true, %17 ]
%16 = phi i8* [ %11, %9 ], [ %18, %17 ]
br i1 %15, label %17, label %21
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %16, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %14, label %21
21: ; preds = %14, %17
br label %22
22: ; preds = %21, %44
%23 = phi i8* [ %45, %44 ], [ %16, %21 ]
%24 = phi i8* [ %46, %44 ], [ %16, %21 ]
%25 = load i8, i8* %23
switch i8 %25, label %41 [
i8 0, label %47
i8 37, label %26
]
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %23, i64 1
%28 = load i8, i8* %27
%29 = tail call i32 @xtov(i8 signext %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %23, i64 2
%33 = load i8, i8* %32
%34 = tail call i32 @xtov(i8 signext %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = shl i32 %29, 4
%38 = or i32 %34, %37
%39 = trunc i32 %38 to i8
store i8 %39, i8* %24
%40 = getelementptr inbounds i8, i8* %23, i64 3
br label %44
41: ; preds = %22, %31, %26
%42 = getelementptr inbounds i8, i8* %23, i64 1
%43 = load i8, i8* %23
store i8 %43, i8* %24
br label %44
44: ; preds = %41, %36
%45 = phi i8* [ %40, %36 ], [ %42, %41 ]
%46 = getelementptr inbounds i8, i8* %24, i64 1
br label %22
47: ; preds = %22
store i8 0, i8* %24
store i8* %16, i8** %1
ret void
}