#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 */
int /*<<< orphan*/ my_snprintf(char *, int, char *, char *);
int /*<<< orphan*/ sg_get_opcode_sa_name(unsigned char const, int, int, int,
                                         char *);
void sg_get_command_name(const unsigned char *cmdp, int peri_type, int buff_len,
                         char *buff) {
  int service_action;
  if ((NULL == buff) || (buff_len < 1))
    return;
  else if (1 == buff_len) {
    buff[0] = '\0';
    return;
  }
  if (NULL == cmdp) {
    my_snprintf(buff, buff_len, "%s", "<null> command pointer");
    return;
  }
  service_action =
      (0x7f == cmdp[0]) ? ((cmdp[8] << 8) | cmdp[9]) : (cmdp[1] & 0x1f);
  sg_get_opcode_sa_name(cmdp[0], service_action, peri_type, buff_len, buff);
}


x86 assembly (clang, -O0):
<sg_get_command_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     114c <sg_get_command_name+0x2c>
cmpl   $0x1,-0x10(%rbp)
jge    1151 <sg_get_command_name+0x31>
jmp    11fb <sg_get_command_name+0xdb>
mov    $0x1,%eax
cmp    -0x10(%rbp),%eax
jne    116b <sg_get_command_name+0x4b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11fb <sg_get_command_name+0xdb>
jmp    1170 <sg_get_command_name+0x50>
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    119b <sg_get_command_name+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdx
lea    0xe72(%rip),%rcx
call   1040 <my_snprintf@plt>
jmp    11fb <sg_get_command_name+0xdb>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x7f,%eax
cmp    %ecx,%eax
jne    11cc <sg_get_command_name+0xac>
mov    -0x8(%rbp),%rax
movzbl 0x8(%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x9(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
jmp    11da <sg_get_command_name+0xba>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x1f,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
movzbl %al,%edi
call   1030 <sg_get_opcode_sa_name@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sg_get_command_name>:
mov    %edx,%eax
test   %edx,%edx
jle    1137 <sg_get_command_name+0x17>
mov    %rcx,%r8
test   %rcx,%rcx
je     1137 <sg_get_command_name+0x17>
cmp    $0x1,%eax
jne    1138 <sg_get_command_name+0x18>
movb   $0x0,(%r8)
ret
test   %rdi,%rdi
je     1151 <sg_get_command_name+0x31>
mov    %esi,%edx
mov    (%rdi),%cl
cmp    $0x7f,%cl
jne    1169 <sg_get_command_name+0x49>
movzwl 0x8(%rdi),%esi
shl    $0x10,%esi
bswap  %esi
jmp    1170 <sg_get_command_name+0x50>
lea    0xea8(%rip),%rdx
lea    0xea4(%rip),%rcx
mov    %r8,%rdi
mov    %eax,%esi
jmp    1040 <my_snprintf@plt>
movzbl 0x1(%rdi),%esi
and    $0x1f,%esi
movzbl %cl,%edi
mov    %eax,%ecx
jmp    1030 <sg_get_opcode_sa_name@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"<null> command pointer\00"
define void @sg_get_command_name(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = icmp eq i8* null, %10
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12, %4
br label %63
16: ; preds = %12
%17 = load i32, i32* %7
%18 = icmp eq i32 1, %17
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
br label %63
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i8*, i8** %5
%25 = icmp eq i8* null, %24
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = call i32 @my_snprintf(i8* %27, i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %63
30: ; preds = %23
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp eq i32 127, %34
br i1 %35, label %36, label %47
36: ; preds = %30
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 8
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 8
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 9
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = or i32 %41, %45
br label %53
47: ; preds = %30
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = and i32 %51, 31
br label %53
53: ; preds = %47, %36
%54 = phi i32 [ %46, %36 ], [ %52, %47 ]
store i32 %54, i32* %9
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 0
%57 = load i8, i8* %56
%58 = load i32, i32* %9
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = load i8*, i8** %8
%62 = call i32 @sg_get_opcode_sa_name(i8 zeroext %57, i32 %58, i32 %59, i32 %60, i8* %61)
br label %63
63: ; preds = %53, %26, %19, %15
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"<null> command pointer\00"
define void @sg_get_command_name(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp eq i8* %3, null
%6 = icmp slt i32 %2, 1
%7 = or i1 %6, %5
br i1 %7, label %35, label %8
8: ; preds = %4
%9 = icmp eq i32 %2, 1
br i1 %9, label %10, label %11
10: ; preds = %8
store i8 0, i8* %3
br label %35
11: ; preds = %8
%12 = icmp eq i8* %0, null
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @my_snprintf(i8* %3, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %35
15: ; preds = %11
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 127
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %0, i64 8
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl nuw nsw i32 %21, 8
%23 = getelementptr inbounds i8, i8* %0, i64 9
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = or i32 %22, %25
br label %32
27: ; preds = %15
%28 = getelementptr inbounds i8, i8* %0, i64 1
%29 = load i8, i8* %28
%30 = and i8 %29, 31
%31 = zext i8 %30 to i32
br label %32
32: ; preds = %27, %18
%33 = phi i32 [ %26, %18 ], [ %31, %27 ]
%34 = tail call i32 @sg_get_opcode_sa_name(i8 zeroext %16, i32 %33, i32 %1, i32 %2, i8* %3)
br label %35
35: ; preds = %4, %32, %13, %10
ret void
}