#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*/ sg_get_opcode_sa_name(unsigned char const, int, int, int,
                                         char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
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;
  if (NULL == cmdp) {
    strncpy(buff, "<null> command pointer", buff_len);
    return;
  }
  service_action =
      (0x7f == cmdp[0]) ? (cmdp[1] & 0x1f) : ((cmdp[8] << 8) | cmdp[9]);
  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    11d5 <sg_get_command_name+0xb5>
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1175 <sg_get_command_name+0x55>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe95(%rip),%rsi
call   1030 <strncpy@plt>
jmp    11d5 <sg_get_command_name+0xb5>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x7f,%eax
cmp    %ecx,%eax
jne    119c <sg_get_command_name+0x7c>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x1f,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <sg_get_command_name+0x94>
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)
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   1040 <sg_get_opcode_sa_name@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sg_get_command_name>:
mov    %rcx,%r8
mov    %edx,%ecx
test   %edx,%edx
jle    114a <sg_get_command_name+0x2a>
test   %r8,%r8
je     114a <sg_get_command_name+0x2a>
test   %rdi,%rdi
je     114b <sg_get_command_name+0x2b>
mov    %esi,%edx
mov    (%rdi),%al
cmp    $0x7f,%al
jne    115c <sg_get_command_name+0x3c>
movzbl 0x1(%rdi),%esi
and    $0x1f,%esi
movzbl %al,%edi
jmp    1040 <sg_get_opcode_sa_name@plt>
ret
lea    0xeae(%rip),%rsi
mov    %r8,%rdi
mov    %ecx,%edx
jmp    1030 <strncpy@plt>
movzwl 0x8(%rdi),%esi
shl    $0x10,%esi
bswap  %esi
movzbl %al,%edi
jmp    1040 <sg_get_opcode_sa_name@plt>

LLVM IR (-O0):
@.str = [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 %56
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = icmp eq i8* null, %17
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = load i32, i32* %7
%22 = call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %56
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp eq i32 127, %27
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = and i32 %33, 31
br label %46
35: ; preds = %23
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 8
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = shl i32 %39, 8
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 9
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = or i32 %40, %44
br label %46
46: ; preds = %35, %29
%47 = phi i32 [ %34, %29 ], [ %45, %35 ]
store i32 %47, i32* %9
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = load i32, i32* %9
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = load i8*, i8** %8
%55 = call i32 @sg_get_opcode_sa_name(i8 zeroext %50, i32 %51, i32 %52, i32 %53, i8* %54)
br label %56
56: ; preds = %46, %19, %15
ret void
}

LLVM IR (-O2):
@.str = [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 %32, label %8
8: ; preds = %4
%9 = icmp eq i8* %0, null
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %32
12: ; preds = %8
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 127
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %16
%18 = and i8 %17, 31
%19 = zext i8 %18 to i32
br label %29
20: ; preds = %12
%21 = getelementptr inbounds i8, i8* %0, i64 8
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = shl nuw nsw i32 %23, 8
%25 = getelementptr inbounds i8, i8* %0, i64 9
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %24, %27
br label %29
29: ; preds = %20, %15
%30 = phi i32 [ %19, %15 ], [ %28, %20 ]
%31 = tail call i32 @sg_get_opcode_sa_name(i8 zeroext %13, i32 %30, i32 %1, i32 %2, i8* %3)
br label %32
32: ; preds = %4, %29, %10
ret void
}