#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 int uint8_t;
typedef scalar_t__ uint16_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ log_write(char *, char *, int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
void _string_analyze(char *buffer, int len) {
  unsigned char ident = buffer[0];
  buffer++;
  uint16_t size = (uint16_t)((uint8_t)(buffer[1]) + 256 * (uint8_t)(buffer[0]));
  buffer += 2;
  if (strlen(buffer) > size)
    log_write("Communication Process", "Extra data transmitted. Continuing...",
              NULL);
  else if (strlen(buffer) < size) {
    log_write("Communication Process",
              "Insuffucient data transmitted. Dropping data...", NULL);
    return;
  }
  switch (ident) {
  case 2: {
    switch (buffer[0]) {
    case 0:
      break;
    case 1:
      break;
    }
    break;
  }
  default:
    log_write("Communication Process", "Failed to identify data. Dropping.",
              NULL);
  }
}


x86 assembly (clang, -O0):
<_string_analyze>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x18(%rbp),%rax
jle    1199 <_string_analyze+0x79>
lea    0xe7c(%rip),%rdi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <log_write@plt>
jmp    11cd <_string_analyze+0xad>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x18(%rbp),%rax
jge    11c8 <_string_analyze+0xa8>
lea    0xe4d(%rip),%rdi
lea    0xe82(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <log_write@plt>
jmp    122b <_string_analyze+0x10b>
jmp    11cd <_string_analyze+0xad>
mov    -0xd(%rbp),%al
sub    $0x2,%al
jne    1214 <_string_analyze+0xf4>
jmp    11dd <_string_analyze+0xbd>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1205 <_string_analyze+0xe5>
jmp    11f4 <_string_analyze+0xd4>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     120a <_string_analyze+0xea>
jmp    120f <_string_analyze+0xef>
jmp    120f <_string_analyze+0xef>
jmp    120f <_string_analyze+0xef>
jmp    122b <_string_analyze+0x10b>
lea    0xde5(%rip),%rdi
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <log_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_string_analyze>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%bpl
movsbq 0x2(%rdi),%rax
movsbq 0x1(%rdi),%rbx
shl    $0x8,%rbx
add    %rax,%rbx
add    $0x3,%rdi
call   1030 <strlen@plt>
cmp    %rbx,%rax
jle    115c <_string_analyze+0x3c>
lea    0xeb4(%rip),%rdi
lea    0xec3(%rip),%rsi
xor    %edx,%edx
call   1040 <log_write@plt>
jmp    1167 <_string_analyze+0x47>
jge    1167 <_string_analyze+0x47>
lea    0xed7(%rip),%rsi
jmp    117b <_string_analyze+0x5b>
cmp    $0x2,%bpl
jne    1174 <_string_analyze+0x54>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xef1(%rip),%rsi
lea    0xe7e(%rip),%rdi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <log_write@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Communication Process\00"
@.str.1 = [38 x i8] c"Extra data transmitted. Continuing...\00"
@.str.2 = [48 x i8] c"Insuffucient data transmitted. Dropping data...\00"
@.str.3 = [35 x i8] c"Failed to identify data. Dropping.\00"
define void @_string_analyze(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
store i8 %9, i8* %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = mul nsw i32 256, %19
%21 = add nsw i32 %15, %20
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = load i64, i64* %6
%28 = icmp sgt i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %39
31: ; preds = %2
%32 = load i8*, i8** %3
%33 = call i64 @strlen(i8* %32)
%34 = load i64, i64* %6
%35 = icmp slt i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %52
38: ; preds = %31
br label %39
39: ; preds = %38, %29
%40 = load i8, i8* %5
%41 = zext i8 %40 to i32
switch i32 %41, label %50 [
i32 2, label %42
]
42: ; preds = %39
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
switch i32 %46, label %49 [
i32 0, label %47
i32 1, label %48
]
47: ; preds = %42
br label %49
48: ; preds = %42
br label %49
49: ; preds = %42, %48, %47
br label %52
50: ; preds = %39
%51 = call i32 @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %52
52: ; preds = %36, %50, %49
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Communication Process\00"
@.str.1 = [38 x i8] c"Extra data transmitted. Continuing...\00"
@.str.2 = [48 x i8] c"Insuffucient data transmitted. Dropping data...\00"
@.str.3 = [35 x i8] c"Failed to identify data. Dropping.\00"
define void @_string_analyze(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = shl nsw i32 %9, 8
%11 = add nsw i32 %10, %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = tail call i64 @strlen(i8* %13)
%15 = icmp sgt i64 %14, %12
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = tail call i32 @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %20
18: ; preds = %2
%19 = icmp slt i64 %14, %12
br i1 %19, label %22, label %20
20: ; preds = %18, %16
%21 = icmp eq i8 %3, 2
br i1 %21, label %25, label %22
22: ; preds = %20, %18
%23 = phi i8* [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), %20 ]
%24 = tail call i32 @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %23, i32* null)
br label %25
25: ; preds = %22, %20
ret void
}