#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*/ buf;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *create_string(char const *);
int snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, int /*<<< orphan*/);
int is_unixsock_dev(const char *dev, const char *cwd, char **path_ref) {
  const char *prefix = "unix:";
  int n;
  char buf[PATH_MAX];
  assert(dev != NULL);
  if (strncasecmp(dev, prefix, strlen(prefix)) != 0) {
    return (0);
  }
  dev += strlen(prefix);
  if (dev[0] == '\0') {
    return (0);
  }
  if ((dev[0] != '/') && (cwd != NULL)) {
    n = snprintf(buf, sizeof(buf), "%s/%s", cwd, dev);
    if ((n < 0) || (n >= sizeof(buf))) {
      return (0);
    }
    dev = buf;
  }
  if (path_ref) {
    *path_ref = create_string(dev);
  }
  return (1);
}


x86 assembly (clang, -O0):
<is_unixsock_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     11f6 <is_unixsock_dev+0xa6>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12d0 <is_unixsock_dev+0x180>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1232 <is_unixsock_dev+0xe2>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12d0 <is_unixsock_dev+0x180>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12a4 <is_unixsock_dev+0x154>
cmpq   $0x0,-0x18(%rbp)
je     12a4 <is_unixsock_dev+0x154>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xda0(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1289 <is_unixsock_dev+0x139>
mov    -0x68(%rbp),%rcx
movslq -0x2c(%rbp),%rax
cmp    %rcx,%rax
jb     129c <is_unixsock_dev+0x14c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12d0 <is_unixsock_dev+0x180>
mov    -0x60(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c2 <is_unixsock_dev+0x172>
mov    -0x10(%rbp),%rdi
call   1060 <create_string@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_unixsock_dev>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r13
mov    0x2e7d(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r14
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1050 <assert@plt>
lea    0xe64(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <strncasecmp@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11cb <is_unixsock_dev+0x7b>
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x38(%rbp),%rbx
lea    0xe2a(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    0x0(%r13,%rcx,1),%al
test   %al,%al
je     11b9 <is_unixsock_dev+0x69>
add    %rcx,%r13
test   %rbx,%rbx
je     1218 <is_unixsock_dev+0xc8>
cmp    $0x2f,%al
je     1218 <is_unixsock_dev+0xc8>
lea    0xe0c(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rcx
mov    %r13,%r8
call   1040 <snprintf@plt>
test   %eax,%eax
js     11b9 <is_unixsock_dev+0x69>
cltq
cmp    %r15,%rax
jb     121b <is_unixsock_dev+0xcb>
jmp    11b9 <is_unixsock_dev+0x69>
mov    %r13,%r14
mov    $0x1,%r12d
mov    -0x30(%rbp),%rbx
test   %rbx,%rbx
je     11b9 <is_unixsock_dev+0x69>
mov    %r14,%rdi
call   1060 <create_string@plt>
mov    %rax,(%rbx)
jmp    11b9 <is_unixsock_dev+0x69>

LLVM IR (-O0):
@.str = [6 x i8] c"unix:\00"
@PATH_MAX = global i32 0
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @is_unixsock_dev(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %10
%16 = alloca i8, i64 %14
store i64 %14, i64* %11
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %5
%22 = load i8*, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = call i64 @strncasecmp(i8* %21, i8* %22, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %3
store i32 0, i32* %4
store i32 1, i32* %12
br label %70
28: ; preds = %3
%29 = load i8*, i8** %8
%30 = call i32 @strlen(i8* %29)
%31 = load i8*, i8** %5
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %28
store i32 0, i32* %4
store i32 1, i32* %12
br label %70
40: ; preds = %28
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 47
br i1 %45, label %46, label %62
46: ; preds = %40
%47 = load i8*, i8** %6
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %62
49: ; preds = %46
%50 = trunc i64 %14 to i32
%51 = load i8*, i8** %6
%52 = load i8*, i8** %5
%53 = call i32 @snprintf(i8* %16, i32 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %49
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = icmp uge i64 %58, %14
br i1 %59, label %60, label %61
60: ; preds = %56, %49
store i32 0, i32* %4
store i32 1, i32* %12
br label %70
61: ; preds = %56
store i8* %16, i8** %5
br label %62
62: ; preds = %61, %46, %40
%63 = load i8**, i8*** %7
%64 = icmp ne i8** %63, null
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i8*, i8** %5
%67 = call i8* @create_string(i8* %66)
%68 = load i8**, i8*** %7
store i8* %67, i8** %68
br label %69
69: ; preds = %65, %62
store i32 1, i32* %4
store i32 1, i32* %12
br label %70
70: ; preds = %69, %60, %39, %27
%71 = load i8*, i8** %10
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
@.str = [6 x i8] c"unix:\00"
@PATH_MAX = global i32 0
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @is_unixsock_dev(i8* %0, i8* %1, i8** writeonly %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp ne i8* %0, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %3
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %34, label %19
19: ; preds = %13
%20 = icmp ne i8 %17, 47
%21 = icmp ne i8* %1, null
%22 = and i1 %21, %20
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %16)
%25 = icmp slt i32 %24, 0
%26 = sext i32 %24 to i64
%27 = icmp uge i64 %26, %5
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %34, label %29
29: ; preds = %23, %19
%30 = phi i8* [ %16, %19 ], [ %6, %23 ]
%31 = icmp eq i8** %2, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i8* @create_string(i8* %30)
store i8* %33, i8** %2
br label %34
34: ; preds = %29, %32, %23, %13, %3
%35 = phi i32 [ 0, %3 ], [ 0, %13 ], [ 0, %23 ], [ 1, %32 ], [ 1, %29 ]
ret i32 %35
}