#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 eb_cmd_search_com_id(char *, char *, char *);
int /*<<< orphan*/ log_print(int, char *, char *, ...);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int eb_cmd_search_com(char *buf, char *data) {
  char *type, *class, *cmd, *tok;
  int id;
  type = strtok(buf, " ");
  class = strtok(NULL, " .");
  cmd = strtok(NULL, " .\n\r\t");
  if (class != NULL && cmd != NULL) {
    if (strncasecmp(type, "get", 3) == 0 || strncasecmp(type, "set", 3) == 0 ||
        strncasecmp(type, "cyc", 3) == 0) {
      log_print(0x02, "search: %s %s.%s", type, class, cmd);
      id = eb_cmd_search_com_id(type, class, cmd);
      if (id < 0)
        return -1;
      tok = strtok(NULL, "\n\r");
      if (tok == NULL)
        strncpy(data, "-", 1);
      else
        strncpy(data, tok, strlen(tok));
      log_print(0x02, "  data: %s", data);
      return id;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<eb_cmd_search_com>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe73(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe62(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12f0 <eb_cmd_search_com+0x190>
cmpq   $0x0,-0x30(%rbp)
je     12f0 <eb_cmd_search_com+0x190>
mov    -0x20(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     121f <eb_cmd_search_com+0xbf>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     121f <eb_cmd_search_com+0xbf>
mov    -0x20(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12eb <eb_cmd_search_com+0x18b>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    $0x2,%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1050 <log_print@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <eb_cmd_search_com_id@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1268 <eb_cmd_search_com+0x108>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f7 <eb_cmd_search_com+0x197>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb5(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12a1 <eb_cmd_search_com+0x141>
mov    -0x18(%rbp),%rdi
lea    0xd99(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
jmp    12c9 <eb_cmd_search_com+0x169>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdx
mov    $0x2,%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1050 <log_print@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f7 <eb_cmd_search_com+0x197>
jmp    12f0 <eb_cmd_search_com+0x190>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eb_cmd_search_com>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
lea    0xe8e(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%r12
lea    0xe81(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    %rax,%rbp
lea    0xe73(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    $0xffffffff,%r15d
test   %rbp,%rbp
je     1288 <eb_cmd_search_com+0x128>
mov    %rax,%rbx
test   %rax,%rax
je     1288 <eb_cmd_search_com+0x128>
lea    0xe50(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     1203 <eb_cmd_search_com+0xa3>
lea    0xe3b(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     1203 <eb_cmd_search_com+0xa3>
lea    0xe26(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
jne    1288 <eb_cmd_search_com+0x128>
lea    0xe0d(%rip),%rsi
mov    $0x2,%edi
mov    %r12,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <log_print@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1060 <eb_cmd_search_com_id@plt>
test   %eax,%eax
js     1288 <eb_cmd_search_com+0x128>
mov    %eax,%ebx
lea    0xdee(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     125b <eb_cmd_search_com+0xfb>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
jmp    126a <eb_cmd_search_com+0x10a>
lea    0xdc9(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1030 <strncpy@plt>
lea    0xdb7(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <log_print@plt>
mov    %ebx,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" .\00"
@.str.2 = [6 x i8] c" .\0A\0D\09\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [4 x i8] c"set\00"
@.str.5 = [4 x i8] c"cyc\00"
@.str.6 = [17 x i8] c"search: %s %s.%s\00"
@.str.7 = [3 x i8] c"\0A\0D\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [11 x i8] c" data: %s\00"
define i32 @eb_cmd_search_com(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %6
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %7
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %14, i8** %8
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %62
17: ; preds = %2
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %62
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = call i64 @strncasecmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = call i64 @strncasecmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8*, i8** %6
%30 = call i64 @strncasecmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %28, %24, %20
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = load i8*, i8** %8
%36 = call i32 (i32, i8*, i8*, ...) @log_print(i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %33, i8* %34, i8* %35)
%37 = load i8*, i8** %6
%38 = load i8*, i8** %7
%39 = load i8*, i8** %8
%40 = call i32 @eb_cmd_search_com_id(i8* %37, i8* %38, i8* %39)
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %32
store i32 -1, i32* %3
br label %63
44: ; preds = %32
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8*, i8** %5
%50 = call i32 @strncpy(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %57
51: ; preds = %44
%52 = load i8*, i8** %5
%53 = load i8*, i8** %9
%54 = load i8*, i8** %9
%55 = call i32 @strlen(i8* %54)
%56 = call i32 @strncpy(i8* %52, i8* %53, i32 %55)
br label %57
57: ; preds = %51, %48
%58 = load i8*, i8** %5
%59 = call i32 (i32, i8*, i8*, ...) @log_print(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %58)
%60 = load i32, i32* %10
store i32 %60, i32* %3
br label %63
61: ; preds = %28
br label %62
62: ; preds = %61, %17, %2
store i32 -1, i32* %3
br label %63
63: ; preds = %62, %57, %43
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" .\00"
@.str.2 = [6 x i8] c" .\0A\0D\09\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [4 x i8] c"set\00"
@.str.5 = [4 x i8] c"cyc\00"
@.str.6 = [17 x i8] c"search: %s %s.%s\00"
@.str.7 = [3 x i8] c"\0A\0D\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [11 x i8] c" data: %s\00"
define i32 @eb_cmd_search_com(i8* %0, i8* %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp ne i8* %4, null
%7 = icmp ne i8* %5, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %32
9: ; preds = %2
%10 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %15, %12, %9
%19 = tail call i32 (i32, i8*, i8*, ...) @log_print(i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %3, i8* %4, i8* %5)
%20 = tail call i32 @eb_cmd_search_com_id(i8* %3, i8* %4, i8* %5)
%21 = icmp slt i32 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %18
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %30
27: ; preds = %22
%28 = tail call i32 @strlen(i8* %23)
%29 = tail call i32 @strncpy(i8* %1, i8* %23, i32 %28)
br label %30
30: ; preds = %27, %25
%31 = tail call i32 (i32, i8*, i8*, ...) @log_print(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* %1)
br label %32
32: ; preds = %2, %15, %18, %30
%33 = phi i32 [ %20, %30 ], [ -1, %18 ], [ -1, %15 ], [ -1, %2 ]
ret i32 %33
}