#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 tohandle(struct skynet_context *context, const char *param) {
  uint32_t handle = 0;
  if (param[0] == ':') {
    handle = strtoul(param + 1, NULL, 16);
  } else if (param[0] == '.') {
    handle = skynet_handle_findname(param + 1);
  } else {
    skynet_error(context, "Can't convert %s to handle", param);
  }
  return handle;
}


x86 assembly (clang, -O0):
<tohandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1175 <tohandle+0x45>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x14(%rbp)
jmp    11b3 <tohandle+0x83>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    119a <tohandle+0x6a>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <skynet_handle_findname@plt>
mov    %eax,-0x14(%rbp)
jmp    11ae <tohandle+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe57(%rip),%rsi
call   1040 <skynet_error@plt>
jmp    11b3 <tohandle+0x83>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tohandle>:
push   %rax
mov    %rsi,%rdx
mov    (%rsi),%al
cmp    $0x2e,%al
je     1152 <tohandle+0x22>
cmp    $0x3a,%al
jne    115f <tohandle+0x2f>
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    0xe9a(%rip),%rsi
call   1040 <skynet_error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.skynet_context = type { i32 }
@.str = [27 x i8] c"Can't convert %s to handle\00"
define i32 @tohandle(%struct.skynet_context* %0, i8* %1) {
%3 = alloca %struct.skynet_context*
%4 = alloca i8*
%5 = alloca i32
store %struct.skynet_context* %0, %struct.skynet_context** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 58
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = call i32 @strtoul(i8* %13, i32* null, i32 16)
store i32 %14, i32* %5
br label %30
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i32 @skynet_handle_findname(i8* %23)
store i32 %24, i32* %5
br label %29
25: ; preds = %15
%26 = load %struct.skynet_context*, %struct.skynet_context** %3
%27 = load i8*, i8** %4
%28 = call i32 @skynet_error(%struct.skynet_context* %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %25, %21
br label %30
30: ; preds = %29, %11
%31 = load i32, i32* %5
ret i32 %31
}

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