#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*/ uint32_t;
struct skynet_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ skynet_error(struct skynet_context *, char *, char const *);
int /*<<< orphan*/ skynet_handle_findname(char const *);
int /*<<< orphan*/ strtoul(char const *, int /*<<< orphan*/ *, int);
uint32_t skynet_queryname(struct skynet_context *context, const char *name) {
  switch (name[0]) {
  case ':':
    return strtoul(name + 1, NULL, 16);
  case '.':
    return skynet_handle_findname(name + 1);
  }
  skynet_error(context, "Don't support query global name %s", name);
  return 0;
}


x86 assembly (clang, -O0):
<skynet_queryname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x2e,%eax
je     1187 <skynet_queryname+0x57>
jmp    1158 <skynet_queryname+0x28>
mov    -0x1c(%rbp),%eax
sub    $0x3a,%eax
jne    119c <skynet_queryname+0x6c>
jmp    1169 <skynet_queryname+0x39>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x4(%rbp)
jmp    11b7 <skynet_queryname+0x87>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1030 <skynet_handle_findname@plt>
mov    %eax,-0x4(%rbp)
jmp    11b7 <skynet_queryname+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1040 <skynet_error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skynet_queryname>:
push   %rax
mov    %rsi,%rdx
movsbl (%rsi),%eax
cmp    $0x2e,%eax
je     1155 <skynet_queryname+0x25>
cmp    $0x3a,%eax
jne    1162 <skynet_queryname+0x32>
add    $0x1,%rdx
mov    %rdx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
pop    %rax
jmp    1050 <strtoul@plt>
add    $0x1,%rdx
mov    %rdx,%rdi
pop    %rax
jmp    1030 <skynet_handle_findname@plt>
lea    0xe97(%rip),%rsi
call   1040 <skynet_error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.skynet_context = type { i32 }
@.str = [35 x i8] c"Don't support query global name %s\00"
define i32 @skynet_queryname(%struct.skynet_context* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.skynet_context*
%5 = alloca i8*
store %struct.skynet_context* %0, %struct.skynet_context** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %18 [
i32 58, label %10
i32 46, label %14
]
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i32 @strtoul(i8* %12, i32* null, i32 16)
store i32 %13, i32* %3
br label %22
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i32 @skynet_handle_findname(i8* %16)
store i32 %17, i32* %3
br label %22
18: ; preds = %2
%19 = load %struct.skynet_context*, %struct.skynet_context** %4
%20 = load i8*, i8** %5
%21 = call i32 @skynet_error(%struct.skynet_context* %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 0, i32* %3
br label %22
22: ; preds = %18, %14, %10
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.skynet_context = type { i32 }
@.str = [35 x i8] c"Don't support query global name %s\00"
define i32 @skynet_queryname(%struct.skynet_context* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
switch i32 %4, label %11 [
i32 58, label %5
i32 46, label %8
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = tail call i32 @strtoul(i8* nocapture %6, i32* null, i32 16)
br label %13
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = tail call i32 @skynet_handle_findname(i8* %9)
br label %13
11: ; preds = %2
%12 = tail call i32 @skynet_error(%struct.skynet_context* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %13
13: ; preds = %11, %8, %5
%14 = phi i32 [ 0, %11 ], [ %10, %8 ], [ %7, %5 ]
ret i32 %14
}