#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*/ assert(char const *);
int /*<<< orphan*/ memset(char *, char, size_t);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int get_data(const char *msg, size_t len, char *data) {
  assert(msg);
  assert(data);
  int datatype = -1;
  if (len < 1)
    return -1;
  memset(data, '\0', len * sizeof(char));
  if (len == 1) {
    data[0] = msg[0];
    switch (data[0]) {
    case 0x06:
      datatype = 1;
      break;
    default:
      datatype = 0;
      break;
    }
  } else {
    if (msg[0] != 0x02 || msg[len - 1] != 0x03)
      return -1;
    strncpy(data, msg + 1, (len - 2));
    if (strncmp(data, "GI_RM_V00.70", 7) == 0)
      datatype = 11;
    else if (strcmp(data, "Timeout") == 0)
      datatype = 19;
    else if (strcmp(data, "REC") == 0)
      datatype = 12;
    else if (strcmp(data, "Done") == 0)
      datatype = 13;
    else
      datatype = 10;
  }
  return datatype;
}


x86 assembly (clang, -O0):
<get_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1070 <assert@plt>
movl   $0xffffffff,-0x24(%rbp)
cmpq   $0x1,-0x18(%rbp)
jae    1194 <get_data+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <get_data+0x1a5>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
shl    $0x0,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
cmpq   $0x1,-0x18(%rbp)
jne    11e9 <get_data+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%al
sub    $0x6,%al
jne    11dd <get_data+0x8d>
jmp    11d1 <get_data+0x81>
movl   $0x1,-0x24(%rbp)
jmp    11e4 <get_data+0x94>
movl   $0x0,-0x24(%rbp)
jmp    12ef <get_data+0x19f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2,%eax
jne    1212 <get_data+0xc2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3,%eax
je     121e <get_data+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <get_data+0x1a5>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
sub    $0x2,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdbe(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1262 <get_data+0x112>
movl   $0xb,-0x24(%rbp)
jmp    12ea <get_data+0x19a>
mov    -0x20(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1288 <get_data+0x138>
movl   $0x13,-0x24(%rbp)
jmp    12e5 <get_data+0x195>
mov    -0x20(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <get_data+0x15e>
movl   $0xc,-0x24(%rbp)
jmp    12e0 <get_data+0x190>
mov    -0x20(%rbp),%rdi
lea    0xd60(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12d4 <get_data+0x184>
movl   $0xd,-0x24(%rbp)
jmp    12db <get_data+0x18b>
movl   $0xa,-0x24(%rbp)
jmp    12e0 <get_data+0x190>
jmp    12e5 <get_data+0x195>
jmp    12ea <get_data+0x19a>
jmp    12ef <get_data+0x19f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1070 <assert@plt>
mov    %r14,%rdi
call   1070 <assert@plt>
mov    $0xffffffff,%r15d
test   %rbx,%rbx
je     1244 <get_data+0xf4>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    0x0(%rbp),%al
cmp    $0x1,%rbx
jne    11a3 <get_data+0x53>
mov    %al,(%r14)
xor    %r15d,%r15d
cmp    $0x6,%al
sete   %r15b
jmp    1244 <get_data+0xf4>
cmp    $0x2,%al
jne    1244 <get_data+0xf4>
cmpb   $0x3,-0x1(%rbx,%rbp,1)
jne    1244 <get_data+0xf4>
add    $0x1,%rbp
add    $0xfffffffffffffffe,%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
lea    0xe2d(%rip),%rsi
mov    %r14,%rdi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     122e <get_data+0xde>
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1236 <get_data+0xe6>
lea    0xe15(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <get_data+0xee>
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%r15d
add    $0xa,%r15d
jmp    1244 <get_data+0xf4>
mov    $0xb,%r15d
jmp    1244 <get_data+0xf4>
mov    $0x13,%r15d
jmp    1244 <get_data+0xf4>
mov    $0xc,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"GI_RM_V00.70\00"
@.str.1 = [8 x i8] c"Timeout\00"
@.str.2 = [4 x i8] c"REC\00"
@.str.3 = [5 x i8] c"Done\00"
define i32 @get_data(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %7
%12 = call i32 @assert(i8* %11)
store i32 -1, i32* %8
%13 = load i64, i64* %6
%14 = icmp ult i64 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %84
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = load i64, i64* %6
%19 = mul i64 %18, 1
%20 = call i32 @memset(i8* %17, i8 signext 0, i64 %19)
%21 = load i64, i64* %6
%22 = icmp eq i64 %21, 1
br i1 %22, label %23, label %36
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 %26, i8* %28
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
switch i32 %32, label %34 [
i32 6, label %33
]
33: ; preds = %23
store i32 1, i32* %8
br label %35
34: ; preds = %23
store i32 0, i32* %8
br label %35
35: ; preds = %34, %33
br label %82
36: ; preds = %16
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 2
br i1 %41, label %50, label %42
42: ; preds = %36
%43 = load i8*, i8** %5
%44 = load i64, i64* %6
%45 = sub i64 %44, 1
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 3
br i1 %49, label %50, label %51
50: ; preds = %42, %36
store i32 -1, i32* %4
br label %84
51: ; preds = %42
%52 = load i8*, i8** %7
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i64, i64* %6
%56 = sub i64 %55, 2
%57 = call i32 @strncpy(i8* %52, i8* %54, i64 %56)
%58 = load i8*, i8** %7
%59 = call i64 @strncmp(i8* %58, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 7)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %51
store i32 11, i32* %8
br label %81
62: ; preds = %51
%63 = load i8*, i8** %7
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %62
store i32 19, i32* %8
br label %80
67: ; preds = %62
%68 = load i8*, i8** %7
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %67
store i32 12, i32* %8
br label %79
72: ; preds = %67
%73 = load i8*, i8** %7
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %72
store i32 13, i32* %8
br label %78
77: ; preds = %72
store i32 10, i32* %8
br label %78
78: ; preds = %77, %76
br label %79
79: ; preds = %78, %71
br label %80
80: ; preds = %79, %66
br label %81
81: ; preds = %80, %61
br label %82
82: ; preds = %81, %35
%83 = load i32, i32* %8
store i32 %83, i32* %4
br label %84
84: ; preds = %82, %50, %15
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
@.str = [13 x i8] c"GI_RM_V00.70\00"
@.str.1 = [8 x i8] c"Timeout\00"
@.str.2 = [4 x i8] c"REC\00"
@.str.3 = [5 x i8] c"Done\00"
define i32 @get_data(i8* %0, i64 %1, i8* %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = tail call i32 @assert(i8* %2)
%6 = icmp eq i64 %1, 0
br i1 %6, label %37, label %7
7: ; preds = %3
%8 = tail call i32 @memset(i8* %2, i8 signext 0, i64 %1)
%9 = icmp eq i64 %1, 1
%10 = load i8, i8* %0
br i1 %9, label %11, label %14
11: ; preds = %7
store i8 %10, i8* %2
%12 = icmp eq i8 %10, 6
%13 = zext i1 %12 to i32
br label %37
14: ; preds = %7
%15 = icmp eq i8 %10, 2
br i1 %15, label %16, label %37
16: ; preds = %14
%17 = add i64 %1, -1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 3
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %0, i64 1
%23 = add i64 %1, -2
%24 = tail call i32 @strncpy(i8* %2, i8* %22, i64 %23)
%25 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %21
%28 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
%36 = select i1 %35, i32 13, i32 10
br label %37
37: ; preds = %11, %21, %27, %30, %33, %14, %16, %3
%38 = phi i32 [ -1, %3 ], [ -1, %16 ], [ -1, %14 ], [ %13, %11 ], [ 11, %21 ], [ 19, %27 ], [ 12, %30 ], [ %36, %33 ]
ret i32 %38
}