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

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *xxtea_to_ubyte_array(int /*<<< orphan*/, size_t,
                                         int /*<<< orphan*/, size_t *);
int /*<<< orphan*/ *xxtea_to_uint_array(int /*<<< orphan*/ const *, int, int,
                                        size_t *);
int /*<<< orphan*/ xxtea_uint_encrypt(int /*<<< orphan*/ *, size_t,
                                      int /*<<< orphan*/ *);
uint8_t *xxtea_encrypt_ubyte(const uint8_t *data, size_t len,
                             const uint8_t *key, size_t *out_len) {
  uint8_t *out;
  uint32_t *data_array, *key_array;
  size_t data_len, key_len;
  if (!len)
    return NULL;
  data_array = xxtea_to_uint_array(data, len, 1, &data_len);
  if (!data_array)
    return NULL;
  key_array = xxtea_to_uint_array(key, 16, 0, &key_len);
  if (!key_array) {
    free(data_array);
    return NULL;
  }
  out =
      xxtea_to_ubyte_array(xxtea_uint_encrypt(data_array, data_len, key_array),
                           data_len, 0, out_len);
  free(data_array);
  free(key_array);
  return out;
}


x86 assembly (clang, -O0):
<xxtea_encrypt_ubyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1170 <xxtea_encrypt_ubyte+0x30>
movq   $0x0,-0x8(%rbp)
jmp    121d <xxtea_encrypt_ubyte+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    $0x1,%edx
lea    -0x48(%rbp),%rcx
call   1050 <xxtea_to_uint_array@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a4 <xxtea_encrypt_ubyte+0x64>
movq   $0x0,-0x8(%rbp)
jmp    121d <xxtea_encrypt_ubyte+0xdd>
mov    -0x20(%rbp),%rdi
mov    $0x10,%esi
xor    %edx,%edx
lea    -0x50(%rbp),%rcx
call   1050 <xxtea_to_uint_array@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11dd <xxtea_encrypt_ubyte+0x9d>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    121d <xxtea_encrypt_ubyte+0xdd>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <xxtea_uint_encrypt@plt>
mov    %eax,%edi
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rcx
xor    %edx,%edx
call   1060 <xxtea_to_ubyte_array@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxtea_encrypt_ubyte>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     11c4 <xxtea_encrypt_ubyte+0x84>
mov    %rcx,%r14
mov    %rdx,%r12
lea    0x8(%rsp),%rcx
mov    $0x1,%edx
call   1050 <xxtea_to_uint_array@plt>
test   %rax,%rax
je     11c4 <xxtea_encrypt_ubyte+0x84>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    $0x10,%esi
xor    %edx,%edx
call   1050 <xxtea_to_uint_array@plt>
test   %rax,%rax
je     11ba <xxtea_encrypt_ubyte+0x7a>
mov    %rax,%r12
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    %rax,%rdx
call   1040 <xxtea_uint_encrypt@plt>
mov    0x8(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   1060 <xxtea_to_ubyte_array@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%r15
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11c6 <xxtea_encrypt_ubyte+0x86>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @xxtea_encrypt_ubyte(i32* %0, i64 %1, i32* %2, i64* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64
%14 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64* %3, i64** %9
%15 = load i64, i64* %7
%16 = icmp ne i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %4
store i32* null, i32** %5
br label %47
18: ; preds = %4
%19 = load i32*, i32** %6
%20 = load i64, i64* %7
%21 = trunc i64 %20 to i32
%22 = call i32* @xxtea_to_uint_array(i32* %19, i32 %21, i32 1, i64* %13)
store i32* %22, i32** %11
%23 = load i32*, i32** %11
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
store i32* null, i32** %5
br label %47
26: ; preds = %18
%27 = load i32*, i32** %8
%28 = call i32* @xxtea_to_uint_array(i32* %27, i32 16, i32 0, i64* %14)
store i32* %28, i32** %12
%29 = load i32*, i32** %12
%30 = icmp ne i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i32*, i32** %11
%33 = call i32 @free(i32* %32)
store i32* null, i32** %5
br label %47
34: ; preds = %26
%35 = load i32*, i32** %11
%36 = load i64, i64* %13
%37 = load i32*, i32** %12
%38 = call i32 @xxtea_uint_encrypt(i32* %35, i64 %36, i32* %37)
%39 = load i64, i64* %13
%40 = load i64*, i64** %9
%41 = call i32* @xxtea_to_ubyte_array(i32 %38, i64 %39, i32 0, i64* %40)
store i32* %41, i32** %10
%42 = load i32*, i32** %11
%43 = call i32 @free(i32* %42)
%44 = load i32*, i32** %12
%45 = call i32 @free(i32* %44)
%46 = load i32*, i32** %10
store i32* %46, i32** %5
br label %47
47: ; preds = %34, %31, %25, %17
%48 = load i32*, i32** %5
ret i32* %48
}

LLVM IR (-O2):
define i32* @xxtea_encrypt_ubyte(i32* %0, i64 %1, i32* %2, i64* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = icmp eq i64 %1, 0
br i1 %9, label %27, label %10
10: ; preds = %4
%11 = trunc i64 %1 to i32
%12 = call i32* @xxtea_to_uint_array(i32* %0, i32 %11, i32 1, i64* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = call i32* @xxtea_to_uint_array(i32* %2, i32 16, i32 0, i64* %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i64, i64* %5
%19 = call i32 @xxtea_uint_encrypt(i32* %12, i64 %18, i32* %15)
%20 = load i64, i64* %5
%21 = call i32* @xxtea_to_ubyte_array(i32 %19, i64 %20, i32 0, i64* %3)
%22 = call i32 @free(i32* %12)
br label %23
23: ; preds = %14, %17
%24 = phi i32* [ %15, %17 ], [ %12, %14 ]
%25 = phi i32* [ %21, %17 ], [ null, %14 ]
%26 = call i32 @free(i32* %24)
br label %27
27: ; preds = %23, %10, %4
%28 = phi i32* [ null, %4 ], [ null, %10 ], [ %25, %23 ]
ret i32* %28
}