#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__ memcmp(char const *, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int const);
long strtol(char *, char **, int /*<<< orphan*/);
void extract_type_1_socket_inode(const char lname[], long *inode_p) {
  if (strlen(lname) < (strlen("socket:[")) + 3)
    *inode_p = -1;
  else if (memcmp(lname, "socket:[", (strlen("socket:["))))
    *inode_p = -1;
  else if (lname[strlen(lname) - 1] != ']')
    *inode_p = -1;
  else {
    char inode_str[strlen(lname + 1)];
    const int inode_str_len = strlen(lname) - (strlen("socket:[")) - 1;
    char *serr;
    strncpy(inode_str, lname + (strlen("socket:[")), inode_str_len);
    inode_str[inode_str_len] = '\0';
    *inode_p = strtol(inode_str, &serr, 0);
    if (!serr || *serr || *inode_p < 0 || *inode_p > 65535)
      *inode_p = -1;
  }
}


x86 assembly (clang, -O0):
<extract_type_1_socket_inode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    0xe9d(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    $0x3,%ecx
cmp    %ecx,%eax
jge    1188 <extract_type_1_socket_inode+0x48>
mov    -0x10(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
jmp    12f9 <extract_type_1_socket_inode+0x1b9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe69(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe57(%rip),%rsi
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11c8 <extract_type_1_socket_inode+0x88>
mov    -0x10(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
jmp    12f4 <extract_type_1_socket_inode+0x1b4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
je     1202 <extract_type_1_socket_inode+0xc2>
mov    -0x10(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
jmp    12ef <extract_type_1_socket_inode+0x1af>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x5c(%rbp)
lea    0xdb9(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xd98(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rdi
movslq -0x24(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     12dd <extract_type_1_socket_inode+0x19d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12dd <extract_type_1_socket_inode+0x19d>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jl     12dd <extract_type_1_socket_inode+0x19d>
mov    -0x10(%rbp),%rax
cmpq   $0xffff,(%rax)
jle    12e8 <extract_type_1_socket_inode+0x1a8>
mov    -0x10(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    12f4 <extract_type_1_socket_inode+0x1b4>
jmp    12f9 <extract_type_1_socket_inode+0x1b9>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_type_1_socket_inode>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe9b(%rip),%rdi
call   1040 <strlen@plt>
add    $0x3,%eax
cmp    %eax,%ebx
jl     124e <extract_type_1_socket_inode+0x10e>
lea    0xe84(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    124e <extract_type_1_socket_inode+0x10e>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x5d,-0x1(%rax,%r12,1)
jne    124e <extract_type_1_socket_inode+0x10e>
lea    0x1(%r12),%rdi
call   1040 <strlen@plt>
mov    %rsp,-0x30(%rbp)
mov    %eax,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe1e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
not    %r13d
add    %ebx,%r13d
lea    0xe09(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r12,%rsi
mov    %r15,%rdi
mov    %r13d,%edx
call   1030 <strncpy@plt>
movslq %r13d,%rax
movb   $0x0,(%rax,%r15,1)
lea    -0x38(%rbp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,(%r14)
mov    -0x38(%rbp),%rcx
test   %rcx,%rcx
je     1241 <extract_type_1_socket_inode+0x101>
cmpb   $0x0,(%rcx)
jne    1241 <extract_type_1_socket_inode+0x101>
test   %rax,%rax
js     1241 <extract_type_1_socket_inode+0x101>
cmp    $0x10000,%rax
jl     1248 <extract_type_1_socket_inode+0x108>
movq   $0xffffffffffffffff,(%r14)
mov    -0x30(%rbp),%rsp
jmp    1255 <extract_type_1_socket_inode+0x115>
movq   $0xffffffffffffffff,(%r14)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"socket:[\00"
define void @extract_type_1_socket_inode(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i64* %1, i64** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = add nsw i32 %11, 3
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i64*, i64** %4
store i64 -1, i64* %15
br label %79
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i64*, i64** %4
store i64 -1, i64* %22
br label %78
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 93
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i64*, i64** %4
store i64 -1, i64* %34
br label %77
35: ; preds = %23
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i32 @strlen(i8* %37)
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
store i8* %40, i8** %5
%41 = alloca i8, i64 %39
store i64 %39, i64* %6
%42 = load i8*, i8** %3
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%45 = sub nsw i32 %43, %44
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %7
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i32, i32* %7
%52 = call i32 @strncpy(i8* %41, i8* %50, i32 %51)
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %41, i64 %54
store i8 0, i8* %55
%56 = call i64 @strtol(i8* %41, i8** %8, i32 0)
%57 = load i64*, i64** %4
store i64 %56, i64* %57
%58 = load i8*, i8** %8
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %73
60: ; preds = %35
%61 = load i8*, i8** %8
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 0
br i1 %64, label %73, label %65
65: ; preds = %60
%66 = load i64*, i64** %4
%67 = load i64, i64* %66
%68 = icmp slt i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i64*, i64** %4
%71 = load i64, i64* %70
%72 = icmp sgt i64 %71, 65535
br i1 %72, label %73, label %75
73: ; preds = %69, %65, %60, %35
%74 = load i64*, i64** %4
store i64 -1, i64* %74
br label %75
75: ; preds = %73, %69
%76 = load i8*, i8** %5
br label %77
77: ; preds = %75, %33
br label %78
78: ; preds = %77, %21
br label %79
79: ; preds = %78, %14
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"socket:[\00"
define void @extract_type_1_socket_inode(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = add nsw i32 %5, 3
%7 = icmp slt i32 %4, %6
br i1 %7, label %8, label %9
8: ; preds = %2
store i64 -1, i64* %1
br label %51
9: ; preds = %2
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i64 -1, i64* %1
br label %51
14: ; preds = %9
%15 = tail call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 93
br i1 %20, label %22, label %21
21: ; preds = %14
store i64 -1, i64* %1
br label %51
22: ; preds = %14
%23 = getelementptr inbounds i8, i8* %0, i64 1
%24 = tail call i32 @strlen(i8* %23)
%25 = zext i32 %24 to i64
%26 = tail call i8* @llvm.stacksave()
%27 = alloca i8, i64 %25
%28 = tail call i32 @strlen(i8* %0)
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%30 = xor i32 %29, -1
%31 = add i32 %28, %30
%32 = bitcast i8** %3 to i8*
%33 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = call i32 @strncpy(i8* %27, i8* %35, i32 %31)
%37 = sext i32 %31 to i64
%38 = getelementptr inbounds i8, i8* %27, i64 %37
store i8 0, i8* %38
%39 = call i64 @strtol(i8* %27, i8** %3, i32 0)
store i64 %39, i64* %1
%40 = load i8*, i8** %3
%41 = icmp eq i8* %40, null
br i1 %41, label %49, label %42
42: ; preds = %22
%43 = load i8, i8* %40
%44 = icmp ne i8 %43, 0
%45 = icmp slt i64 %39, 0
%46 = select i1 %44, i1 true, i1 %45
%47 = icmp sgt i64 %39, 65535
%48 = select i1 %46, i1 true, i1 %47
br i1 %48, label %49, label %50
49: ; preds = %42, %22
store i64 -1, i64* %1
br label %50
50: ; preds = %42, %49
br label %51
51: ; preds = %13, %50, %21, %8
ret void
}