#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*/ xxtea_encode(int *, int *);
int /*<<< orphan*/ xxtea_encode_byte(char *, int *, unsigned int);
void xxtea_encode_buffer(char *in_buffer, unsigned int in_size, int *key,
                         int cipherRemains) {
  char *p;
  unsigned int remain = in_size % 8;
  unsigned int align_size = in_size - remain;
  for (p = in_buffer; p < in_buffer + align_size; p += 8)
    xxtea_encode((int *)p, key);
  if (remain > 0 && cipherRemains)
    for (p = in_buffer + align_size; p < in_buffer + in_size; p += 1)
      xxtea_encode_byte(p, key, --remain);
}


x86 assembly (clang, -O0):
<xxtea_encode_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1185 <xxtea_encode_buffer+0x65>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <xxtea_encode@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1150 <xxtea_encode_buffer+0x30>
cmpl   $0x0,-0x2c(%rbp)
jbe    11ea <xxtea_encode_buffer+0xca>
cmpl   $0x0,-0x1c(%rbp)
je     11ea <xxtea_encode_buffer+0xca>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11e5 <xxtea_encode_buffer+0xc5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x2c(%rbp)
call   1030 <xxtea_encode_byte@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a7 <xxtea_encode_buffer+0x87>
jmp    11ea <xxtea_encode_buffer+0xca>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxtea_encode_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %rdx,%r15
mov    %rdi,%r13
mov    %esi,%ebp
and    $0x7,%ebp
mov    %esi,(%rsp)
mov    %esi,%r12d
and    $0xfffffff8,%r12d
lea    (%r12,%rdi,1),%rbx
test   %r12d,%r12d
je     1164 <xxtea_encode_buffer+0x44>
mov    %r13,%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <xxtea_encode@plt>
add    $0x8,%r14
cmp    %rbx,%r14
jb     1150 <xxtea_encode_buffer+0x30>
test   %ebp,%ebp
je     1199 <xxtea_encode_buffer+0x79>
cmpl   $0x0,0x4(%rsp)
je     1199 <xxtea_encode_buffer+0x79>
cmp    (%rsp),%r12d
jae    1199 <xxtea_encode_buffer+0x79>
mov    (%rsp),%eax
add    %rax,%r13
add    $0xffffffff,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <xxtea_encode_byte@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %r13,%rbx
jb     1180 <xxtea_encode_buffer+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xxtea_encode_buffer(i8* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = urem i32 %12, 8
store i32 %13, i32* %10
%14 = load i32, i32* %6
%15 = load i32, i32* %10
%16 = sub i32 %14, %15
store i32 %16, i32* %11
%17 = load i8*, i8** %5
store i8* %17, i8** %9
br label %18
18: ; preds = %30, %4
%19 = load i8*, i8** %9
%20 = load i8*, i8** %5
%21 = load i32, i32* %11
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = icmp ult i8* %19, %23
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = bitcast i8* %26 to i32*
%28 = load i32*, i32** %7
%29 = call i32 @xxtea_encode(i32* %27, i32* %28)
br label %30
30: ; preds = %25
%31 = load i8*, i8** %9
%32 = getelementptr inbounds i8, i8* %31, i64 8
store i8* %32, i8** %9
br label %18
33: ; preds = %18
%34 = load i32, i32* %10
%35 = icmp ugt i32 %34, 0
br i1 %35, label %36, label %61
36: ; preds = %33
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %61
39: ; preds = %36
%40 = load i8*, i8** %5
%41 = load i32, i32* %11
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8* %43, i8** %9
br label %44
44: ; preds = %57, %39
%45 = load i8*, i8** %9
%46 = load i8*, i8** %5
%47 = load i32, i32* %6
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = icmp ult i8* %45, %49
br i1 %50, label %51, label %60
51: ; preds = %44
%52 = load i8*, i8** %9
%53 = load i32*, i32** %7
%54 = load i32, i32* %10
%55 = add i32 %54, -1
store i32 %55, i32* %10
%56 = call i32 @xxtea_encode_byte(i8* %52, i32* %53, i32 %55)
br label %57
57: ; preds = %51
%58 = load i8*, i8** %9
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8* %59, i8** %9
br label %44
60: ; preds = %44
br label %61
61: ; preds = %60, %36, %33
ret void
}

LLVM IR (-O2):
define void @xxtea_encode_buffer(i8* %0, i32 %1, i32* %2, i32 %3) {
%5 = and i32 %1, 7
%6 = and i32 %1, -8
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = icmp eq i32 %6, 0
br i1 %9, label %16, label %10
10: ; preds = %4, %10
%11 = phi i8* [ %14, %10 ], [ %0, %4 ]
%12 = bitcast i8* %11 to i32*
%13 = tail call i32 @xxtea_encode(i32* %12, i32* %2)
%14 = getelementptr inbounds i8, i8* %11, i64 8
%15 = icmp ult i8* %14, %8
br i1 %15, label %10, label %16
16: ; preds = %10, %4
%17 = icmp ne i32 %5, 0
%18 = icmp ne i32 %3, 0
%19 = and i1 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = zext i32 %1 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = icmp ult i32 %6, %1
br i1 %23, label %24, label %31
24: ; preds = %20, %24
%25 = phi i8* [ %29, %24 ], [ %8, %20 ]
%26 = phi i32 [ %27, %24 ], [ %5, %20 ]
%27 = add i32 %26, -1
%28 = tail call i32 @xxtea_encode_byte(i8* %25, i32* %2, i32 %27)
%29 = getelementptr inbounds i8, i8* %25, i64 1
%30 = icmp ult i8* %29, %22
br i1 %30, label %24, label %31
31: ; preds = %24, %20, %16
ret void
}