#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ get_uint32le(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ telechips_encode_crc(unsigned char *, int);
int telechips_test_crc(unsigned char *buf, int length) {
  uint32_t crc1, crc2, test_crc1, test_crc2;
  unsigned char *test_buf;
  crc1 = get_uint32le(buf + 0x10);
  crc2 = get_uint32le(buf + 0x18);
  test_buf = malloc(length);
  if (!test_buf)
    return 1;
  memcpy(test_buf, buf, length);
  telechips_encode_crc(test_buf, length);
  test_crc1 = get_uint32le(test_buf + 0x10);
  test_crc2 = get_uint32le(test_buf + 0x18);
  free(test_buf);
  return (crc1 == test_crc1 && crc2 == test_crc2) ? 0 : 2;
}


x86 assembly (clang, -O0):
<telechips_test_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x18,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11a4 <telechips_test_crc+0x54>
movl   $0x1,-0x4(%rbp)
jmp    121f <telechips_test_crc+0xcf>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <telechips_encode_crc@plt>
mov    -0x40(%rbp),%rdi
add    $0x10,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x18,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x30(%rbp),%rcx
mov    %al,-0x41(%rbp)
jne    120c <telechips_test_crc+0xbc>
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%dl
mov    $0x2,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<telechips_test_crc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%rbp
add    $0x10,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,%r14
lea    0x18(%rbp),%rdi
call   1070 <get_uint32le@plt>
mov    %rax,%r15
mov    %r12d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d4 <telechips_test_crc+0x84>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <telechips_encode_crc@plt>
lea    0x10(%rbx),%rdi
call   1070 <get_uint32le@plt>
mov    %rax,%r12
mov    %rbx,%rdi
add    $0x18,%rdi
call   1070 <get_uint32le@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %r12,%r14
xor    %rbp,%r15
xor    %eax,%eax
or     %r14,%r15
setne  %al
add    %eax,%eax
jmp    11d9 <telechips_test_crc+0x89>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @telechips_test_crc(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 16
%13 = call i64 @get_uint32le(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 24
%16 = call i64 @get_uint32le(i8* %15)
store i64 %16, i64* %7
%17 = load i32, i32* %5
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i32 1, i32* %3
br label %49
22: ; preds = %2
%23 = load i8*, i8** %10
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
%27 = load i8*, i8** %10
%28 = load i32, i32* %5
%29 = call i32 @telechips_encode_crc(i8* %27, i32 %28)
%30 = load i8*, i8** %10
%31 = getelementptr inbounds i8, i8* %30, i64 16
%32 = call i64 @get_uint32le(i8* %31)
store i64 %32, i64* %8
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 24
%35 = call i64 @get_uint32le(i8* %34)
store i64 %35, i64* %9
%36 = load i8*, i8** %10
%37 = call i32 @free(i8* %36)
%38 = load i64, i64* %6
%39 = load i64, i64* %8
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %22
%42 = load i64, i64* %7
%43 = load i64, i64* %9
%44 = icmp eq i64 %42, %43
br label %45
45: ; preds = %41, %22
%46 = phi i1 [ false, %22 ], [ %44, %41 ]
%47 = zext i1 %46 to i64
%48 = select i1 %46, i32 0, i32 2
store i32 %48, i32* %3
br label %49
49: ; preds = %45, %21
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @telechips_test_crc(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 16
%4 = tail call i64 @get_uint32le(i8* %3)
%5 = getelementptr inbounds i8, i8* %0, i64 24
%6 = tail call i64 @get_uint32le(i8* %5)
%7 = tail call i8* @malloc(i32 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i32 %1)
%11 = tail call i32 @telechips_encode_crc(i8* %7, i32 %1)
%12 = getelementptr inbounds i8, i8* %7, i64 16
%13 = tail call i64 @get_uint32le(i8* %12)
%14 = getelementptr inbounds i8, i8* %7, i64 24
%15 = tail call i64 @get_uint32le(i8* %14)
%16 = tail call i32 @free(i8* %7)
%17 = icmp eq i64 %4, %13
%18 = icmp eq i64 %6, %15
%19 = select i1 %17, i1 %18, i1 false
%20 = select i1 %19, i32 0, i32 2
br label %21
21: ; preds = %2, %9
%22 = phi i32 [ %20, %9 ], [ 1, %2 ]
ret i32 %22
}