#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
char *recive_raw_package_by_interface(int net_fd, char *returned_buffer) {
  char buffer[1024];
  int offset = 0;
  int payload_length;
  int plength;
  int ix;
  memset(buffer, 0, 1024);
  plength = read(net_fd, buffer, sizeof(buffer));
  if (plength > 0) {
    offset += 12;
    if (buffer[offset] == 0x86 && buffer[offset + 1] == 0xdd) {
      offset += 2;
      memset(returned_buffer, 0, 1024);
      payload_length = (buffer[offset + 4] << 8 | buffer[offset + 5]);
      for (ix = 0; ix < (payload_length + 40); ix++) {
        returned_buffer[ix] = buffer[offset + ix];
      }
      return returned_buffer;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<recive_raw_package_by_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jle    1278 <recive_raw_package_by_interface+0x158>
mov    -0x424(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x424(%rbp)
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x86,%eax
jne    1273 <recive_raw_package_by_interface+0x153>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xdd,%eax
jne    1273 <recive_raw_package_by_interface+0x153>
mov    -0x424(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x424(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0x424(%rbp),%eax
add    $0x4,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
shl    $0x8,%eax
mov    -0x424(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movsbl -0x420(%rbp,%rcx,1),%ecx
ff
or     %ecx,%eax
mov    %eax,-0x428(%rbp)
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
mov    -0x428(%rbp),%ecx
add    $0x28,%ecx
cmp    %ecx,%eax
jge    1266 <recive_raw_package_by_interface+0x146>
mov    -0x424(%rbp),%eax
add    -0x430(%rbp),%eax
cltq
mov    -0x420(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x430(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    1218 <recive_raw_package_by_interface+0xf8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1280 <recive_raw_package_by_interface+0x160>
jmp    1278 <recive_raw_package_by_interface+0x158>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recive_raw_package_by_interface>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @recive_raw_package_by_interface(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %7
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1024)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 1024)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %76
18: ; preds = %2
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 12
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 134
br i1 %26, label %27, label %75
27: ; preds = %18
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 221
br i1 %34, label %35, label %75
35: ; preds = %27
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 2
store i32 %37, i32* %7
%38 = load i8*, i8** %5
%39 = call i32 @memset(i8* %38, i32 0, i32 1024)
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = shl i32 %45, 8
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = or i32 %46, %52
store i32 %53, i32* %8
store i32 0, i32* %10
br label %54
54: ; preds = %70, %35
%55 = load i32, i32* %10
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 40
%58 = icmp slt i32 %55, %57
br i1 %58, label %59, label %73
59: ; preds = %54
%60 = load i32, i32* %7
%61 = load i32, i32* %10
%62 = add nsw i32 %60, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = load i8*, i8** %5
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 %65, i8* %69
br label %70
70: ; preds = %59
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
br label %54
73: ; preds = %54
%74 = load i8*, i8** %5
store i8* %74, i8** %3
br label %77
75: ; preds = %27, %18
br label %76
76: ; preds = %75, %2
store i8* null, i8** %3
br label %77
77: ; preds = %76, %73
%78 = load i8*, i8** %3
ret i8* %78
}

LLVM IR (-O2):
define noalias i8* @recive_raw_package_by_interface(i32 %0, i8* nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = call i32 @read(i32 %0, i8* %4, i32 1024)
ret i8* null
}