#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*/ free(unsigned char *);
unsigned char *malloc(unsigned long const);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ t_mixencrypt(unsigned int, unsigned char const *,
                                unsigned char *, unsigned long const,
                                unsigned char const *, unsigned char const *);
void mixslice(unsigned int thr, const unsigned char *data,
              unsigned char *fragdata, const unsigned long size,
              const unsigned char *key, const unsigned char *iv) {
  unsigned int fragoffset, readoffset, writeoffset;
  unsigned char *temp = malloc(size);
  t_mixencrypt(thr, data, temp, size, key, iv);
  writeoffset = 0;
  for (fragoffset = 0; fragoffset < (4 * 1024); fragoffset += 4) {
    for (readoffset = fragoffset; readoffset < size; readoffset += (4 * 1024)) {
      memcpy(fragdata + writeoffset, temp + readoffset, 4);
      writeoffset += 4;
    }
  }
  free(temp);
}


x86 assembly (clang, -O0):
<mixslice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1060 <t_mixencrypt@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x1000,-0x34(%rbp)
jae    1200 <mixslice+0xc0>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    11ed <mixslice+0xad>
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%eax
add    %rax,%rdi
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%eax
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1000,%eax
mov    %eax,-0x38(%rbp)
jmp    11a9 <mixslice+0x69>
jmp    11f2 <mixslice+0xb2>
mov    -0x34(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
jmp    1196 <mixslice+0x56>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixslice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rcx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
mov    (%rsp),%r9
call   1060 <t_mixencrypt@plt>
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    11a1 <mixslice+0x61>
nopl   0x0(%rax,%rax,1)
lea    0x4(%r12),%rax
cmp    $0xffc,%r12
mov    %rax,%r12
jae    11d3 <mixslice+0x93>
cmp    %r15,%r12
jae    1190 <mixslice+0x50>
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
add    %r14,%rdi
lea    (%rbx,%r13,1),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x4,%ebp
add    $0x1000,%ebx
cmp    %r15,%rbx
jb     11b0 <mixslice+0x70>
jmp    1190 <mixslice+0x50>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @mixslice(i32 %0, i8* %1, i8* %2, i64 %3, i8* %4, i8* %5) {
%7 = tail call i8* @malloc(i64 %3)
%8 = tail call i32 @t_mixencrypt(i32 %0, i8* %1, i8* %7, i64 %3, i8* %4, i8* %5)
br label %9
9: ; preds = %6, %24
%10 = phi i64 [ 0, %6 ], [ %26, %24 ]
%11 = phi i32 [ 0, %6 ], [ %25, %24 ]
%12 = icmp ult i64 %10, %3
br i1 %12, label %13, label %24
13: ; preds = %9, %13
%14 = phi i64 [ %22, %13 ], [ %10, %9 ]
%15 = phi i32 [ %20, %13 ], [ %11, %9 ]
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = getelementptr inbounds i8, i8* %7, i64 %14
%19 = tail call i32 @memcpy(i8* %17, i8* %18, i32 4)
%20 = add i32 %15, 4
%21 = add nuw i64 %14, 4096
%22 = and i64 %21, 4294967295
%23 = icmp ult i64 %22, %3
br i1 %23, label %13, label %24
24: ; preds = %13, %9
%25 = phi i32 [ %11, %9 ], [ %20, %13 ]
%26 = add nuw nsw i64 %10, 4
%27 = icmp ult i64 %10, 4092
br i1 %27, label %9, label %28
28: ; preds = %24
%29 = tail call i32 @free(i8* %7)
ret void
}