#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ xxtea_decode(unsigned char *, int *);
int /*<<< orphan*/ xxtea_decode_byte(unsigned char *, int *, int);
void xxtea_decode_buffer(unsigned char *in_buffer, off_t in_size, int *key,
                         int cipherRemains) {
  unsigned char *p;
  off_t remain = in_size % 8;
  off_t align_size = in_size - remain;
  for (p = in_buffer; p < in_buffer + align_size; p += 8)
    xxtea_decode(p, key);
  if (remain > 0 && cipherRemains)
    for (p = in_buffer + align_size; p < in_buffer + in_size; p += 1)
      xxtea_decode_byte(p, key, --remain);
}


x86 assembly (clang, -O0):
<xxtea_decode_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
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-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
movslq -0x30(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    118b <xxtea_decode_buffer+0x6b>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <xxtea_decode@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1155 <xxtea_decode_buffer+0x35>
cmpl   $0x0,-0x2c(%rbp)
jle    11f2 <xxtea_decode_buffer+0xd2>
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <xxtea_decode_buffer+0xd2>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11ed <xxtea_decode_buffer+0xcd>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x2c(%rbp)
call   1030 <xxtea_decode_byte@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ae <xxtea_decode_buffer+0x8e>
jmp    11f2 <xxtea_decode_buffer+0xd2>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxtea_decode_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r13
lea    0x7(%r12),%eax
test   %esi,%esi
cmovns %esi,%eax
and    $0xfffffff8,%eax
mov    %esi,%ebp
sub    %eax,%ebp
cltq
lea    (%rdi,%rax,1),%rbx
test   %eax,%eax
jle    1174 <xxtea_decode_buffer+0x54>
mov    %r13,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <xxtea_decode@plt>
add    $0x8,%r14
cmp    %rbx,%r14
jb     1160 <xxtea_decode_buffer+0x40>
test   %ebp,%ebp
jle    11a9 <xxtea_decode_buffer+0x89>
cmpl   $0x0,0x4(%rsp)
je     11a9 <xxtea_decode_buffer+0x89>
movslq %r12d,%rax
add    %rax,%r13
add    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <xxtea_decode_byte@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %r13,%rbx
jb     1190 <xxtea_decode_buffer+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xxtea_decode_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 = srem i32 %12, 8
store i32 %13, i32* %10
%14 = load i32, i32* %6
%15 = load i32, i32* %10
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %11
%17 = load i8*, i8** %5
store i8* %17, i8** %9
br label %18
18: ; preds = %29, %4
%19 = load i8*, i8** %9
%20 = load i8*, i8** %5
%21 = load i32, i32* %11
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = icmp ult i8* %19, %23
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = load i32*, i32** %7
%28 = call i32 @xxtea_decode(i8* %26, i32* %27)
br label %29
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 8
store i8* %31, i8** %9
br label %18
32: ; preds = %18
%33 = load i32, i32* %10
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %60
35: ; preds = %32
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %60
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8* %42, i8** %9
br label %43
43: ; preds = %56, %38
%44 = load i8*, i8** %9
%45 = load i8*, i8** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = icmp ult i8* %44, %48
br i1 %49, label %50, label %59
50: ; preds = %43
%51 = load i8*, i8** %9
%52 = load i32*, i32** %7
%53 = load i32, i32* %10
%54 = add nsw i32 %53, -1
store i32 %54, i32* %10
%55 = call i32 @xxtea_decode_byte(i8* %51, i32* %52, i32 %54)
br label %56
56: ; preds = %50
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %9
br label %43
59: ; preds = %43
br label %60
60: ; preds = %59, %35, %32
ret void
}

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