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

/* Variables and functions */
int /*<<< orphan*/ skynet_error(struct skynet_context *, char *, char *);
char const *skynet_handle_namehandle(scalar_t__, char *);
int /*<<< orphan*/ sscanf(char const *, char *, char *, char *);
int strlen(char const *);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
const char *cmd_name(struct skynet_context *context, const char *param) {
  int size = strlen(param);
  char name[size + 1];
  char handle[size + 1];
  sscanf(param, "%s %s", name, handle);
  if (handle[0] != ':') {
    return NULL;
  }
  uint32_t handle_id = strtoul(handle + 1, NULL, 16);
  if (handle_id == 0) {
    return NULL;
  }
  if (name[0] == '.') {
    return skynet_handle_namehandle(handle_id, name + 1);
  } else {
    skynet_error(context, "Can't set global name %s in C", name);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<cmd_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     11eb <cmd_name+0x9b>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1278 <cmd_name+0x128>
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1224 <cmd_name+0xd4>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1278 <cmd_name+0x128>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1255 <cmd_name+0x105>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
add    $0x1,%rsi
call   1040 <skynet_handle_namehandle@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1278 <cmd_name+0x128>
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1050 <skynet_error@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_name>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe73(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1060 <sscanf@plt>
cmpb   $0x3a,(%rbx)
jne    11e8 <cmd_name+0x98>
add    $0x1,%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
test   %rax,%rax
je     11eb <cmd_name+0x9b>
cmpb   $0x2e,(%r12)
jne    11d6 <cmd_name+0x86>
add    $0x1,%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <skynet_handle_namehandle@plt>
mov    %rax,%r15
jmp    11eb <cmd_name+0x9b>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
call   1050 <skynet_error@plt>
xor    %r15d,%r15d
mov    %r15,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.skynet_context = type { i32 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [30 x i8] c"Can't set global name %s in C\00"
define i8* @cmd_name(%struct.skynet_context* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.skynet_context*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
store %struct.skynet_context* %0, %struct.skynet_context** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca i8, i64 %16
store i64 %16, i64* %8
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %9
%23 = load i8*, i8** %5
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %22)
%25 = getelementptr inbounds i8, i8* %22, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 58
br i1 %28, label %29, label %30
29: ; preds = %2
store i8* null, i8** %3
store i32 1, i32* %10
br label %49
30: ; preds = %2
%31 = getelementptr inbounds i8, i8* %22, i64 1
%32 = call i64 @strtoul(i8* %31, i32* null, i32 16)
store i64 %32, i64* %11
%33 = load i64, i64* %11
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i8* null, i8** %3
store i32 1, i32* %10
br label %49
36: ; preds = %30
%37 = getelementptr inbounds i8, i8* %18, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 46
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i64, i64* %11
%43 = getelementptr inbounds i8, i8* %18, i64 1
%44 = call i8* @skynet_handle_namehandle(i64 %42, i8* %43)
store i8* %44, i8** %3
store i32 1, i32* %10
br label %49
45: ; preds = %36
%46 = load %struct.skynet_context*, %struct.skynet_context** %4
%47 = call i32 @skynet_error(%struct.skynet_context* %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %48
48: ; preds = %45
store i8* null, i8** %3
store i32 1, i32* %10
br label %49
49: ; preds = %48, %41, %35, %29
%50 = load i8*, i8** %7
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
%struct.skynet_context = type { i32 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [30 x i8] c"Can't set global name %s in C\00"
define i8* @cmd_name(%struct.skynet_context* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, 58
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = call i64 @strtoul(i8* nocapture %12, i32* null, i32 16)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = load i8, i8* %6
%17 = icmp eq i8 %16, 46
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %6, i64 1
%20 = call i8* @skynet_handle_namehandle(i64 %13, i8* %19)
br label %23
21: ; preds = %15
%22 = call i32 @skynet_error(%struct.skynet_context* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %23
23: ; preds = %18, %21, %11, %2
%24 = phi i8* [ null, %2 ], [ %20, %18 ], [ null, %21 ], [ null, %11 ]
ret i8* %24
}