#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*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char const *, int);
int /*<<< orphan*/ assert(int);
scalar_t__ log2(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void do_step_decrypt(EVP_CIPHER_CTX *ctx, unsigned char *buffer,
                     const unsigned char *macro, unsigned char *out,
                     const unsigned int step) {
  int outl;
  EVP_DecryptUpdate(ctx, buffer, &outl, macro, (4 * 1024));
  if (0)
    assert((4 * 1024) == outl);
  unsigned int j, off, mask, start, dist;
  unsigned char *bp = buffer;
  mask = ((1 << ((int)log2((16 / 4)))) - 1) << (step * ((int)log2((16 / 4))));
  dist = (1 << (step * ((int)log2((16 / 4))))) * 4;
  for (start = 0; start < (1 << ((int)log2(1024)));
       start = ((start | mask) + 1) & ~mask) {
    for (j = 0, off = start * 4; j < (16 / 4); ++j, off += dist) {
      memcpy(out + off, bp, 4);
      bp += 4;
    }
  };
}


x86 assembly (clang, -O0):
<do_step_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdx
mov    $0x1000,%r8d
call   1050 <EVP_DecryptUpdate@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x4,%edi
call   1030 <log2@plt>
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    $0x4,%edi
call   1030 <log2@plt>
mov    -0x54(%rbp),%ecx
mov    %rax,%rdx
mov    -0x50(%rbp),%eax
imul   %edx,%ecx
shl    %cl,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x4,%edi
call   1030 <log2@plt>
mov    -0x4c(%rbp),%ecx
imul   %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
shl    $0x2,%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%eax
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jae    126d <do_step_decrypt+0x13d>
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jae    124f <do_step_decrypt+0x11f>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%eax
add    %rax,%rdi
mov    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    120a <do_step_decrypt+0xda>
jmp    1254 <do_step_decrypt+0x124>
mov    -0x38(%rbp),%eax
or     -0x34(%rbp),%eax
add    $0x1,%eax
mov    -0x34(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x38(%rbp)
jmp    11d3 <do_step_decrypt+0xa3>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_step_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rdx,%rcx
mov    %rsi,%rbx
lea    0x4(%rsp),%rdx
mov    $0x1000,%r8d
call   1050 <EVP_DecryptUpdate@plt>
mov    $0x4,%r15d
mov    $0x4,%edi
call   1030 <log2@plt>
mov    $0xffffffff,%r13d
mov    %eax,%ecx
shl    %cl,%r13d
not    %r13d
mov    $0x4,%edi
call   1030 <log2@plt>
imul   %ebp,%eax
mov    %eax,%ecx
shl    %cl,%r13d
mov    $0x4,%edi
call   1030 <log2@plt>
imul   %eax,%ebp
mov    %ebp,%ecx
shl    %cl,%r15d
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %r13d,(%rsp)
not    %r13d
xor    %r12d,%r12d
nopl   (%rax)
lea    0x0(,%r12,4),%edi
add    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    (%r15,%r12,4),%ebp
lea    (%r14,%rbp,1),%rdi
lea    0x4(%rbx),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    %r15d,%ebp
lea    (%r14,%rbp,1),%rdi
lea    0x8(%rbx),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    %r15d,%ebp
add    %r14,%rbp
lea    0xc(%rbx),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
or     (%rsp),%r12d
add    $0x1,%r12d
and    %r13d,%r12d
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %r12d,%edx
mov    %eax,%ecx
shr    %cl,%edx
add    $0x10,%rbx
test   %edx,%edx
je     11b0 <do_step_decrypt+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @do_step_decrypt(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%18 = load i32*, i32** %6
%19 = load i8*, i8** %7
%20 = load i8*, i8** %8
%21 = call i32 @EVP_DecryptUpdate(i32* %18, i8* %19, i32* %11, i8* %20, i32 4096)
%22 = load i8*, i8** %7
store i8* %22, i8** %17
%23 = call i64 @log2(i32 4)
%24 = trunc i64 %23 to i32
%25 = shl i32 1, %24
%26 = sub nsw i32 %25, 1
%27 = load i32, i32* %10
%28 = call i64 @log2(i32 4)
%29 = trunc i64 %28 to i32
%30 = mul i32 %27, %29
%31 = shl i32 %26, %30
store i32 %31, i32* %14
%32 = load i32, i32* %10
%33 = call i64 @log2(i32 4)
%34 = trunc i64 %33 to i32
%35 = mul i32 %32, %34
%36 = shl i32 1, %35
%37 = mul nsw i32 %36, 4
store i32 %37, i32* %16
store i32 0, i32* %15
br label %38
38: ; preds = %66, %5
%39 = load i32, i32* %15
%40 = call i64 @log2(i32 1024)
%41 = trunc i64 %40 to i32
%42 = shl i32 1, %41
%43 = icmp ult i32 %39, %42
br i1 %43, label %44, label %74
44: ; preds = %38
store i32 0, i32* %12
%45 = load i32, i32* %15
%46 = mul i32 %45, 4
store i32 %46, i32* %13
br label %47
47: ; preds = %59, %44
%48 = load i32, i32* %12
%49 = icmp ult i32 %48, 4
br i1 %49, label %50, label %65
50: ; preds = %47
%51 = load i8*, i8** %9
%52 = load i32, i32* %13
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8*, i8** %17
%56 = call i32 @memcpy(i8* %54, i8* %55, i32 4)
%57 = load i8*, i8** %17
%58 = getelementptr inbounds i8, i8* %57, i64 4
store i8* %58, i8** %17
br label %59
59: ; preds = %50
%60 = load i32, i32* %12
%61 = add i32 %60, 1
store i32 %61, i32* %12
%62 = load i32, i32* %16
%63 = load i32, i32* %13
%64 = add i32 %63, %62
store i32 %64, i32* %13
br label %47
65: ; preds = %47
br label %66
66: ; preds = %65
%67 = load i32, i32* %15
%68 = load i32, i32* %14
%69 = or i32 %67, %68
%70 = add i32 %69, 1
%71 = load i32, i32* %14
%72 = xor i32 %71, -1
%73 = and i32 %70, %72
store i32 %73, i32* %15
br label %38
74: ; preds = %38
ret void
}

LLVM IR (-O2):
define void @do_step_decrypt(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = call i32 @EVP_DecryptUpdate(i32* %0, i8* %1, i32* %6, i8* %2, i32 4096)
%9 = call i64 @log2(i32 4)
%10 = trunc i64 %9 to i32
%11 = shl nsw i32 -1, %10
%12 = xor i32 %11, -1
%13 = call i64 @log2(i32 4)
%14 = trunc i64 %13 to i32
%15 = mul i32 %14, %4
%16 = shl i32 %12, %15
%17 = call i64 @log2(i32 4)
%18 = trunc i64 %17 to i32
%19 = mul i32 %18, %4
%20 = shl i32 4, %19
%21 = call i64 @log2(i32 1024)
%22 = xor i32 %16, -1
br label %23
23: ; preds = %5, %23
%24 = phi i8* [ %1, %5 ], [ %45, %23 ]
%25 = phi i32 [ 0, %5 ], [ %48, %23 ]
%26 = shl i32 %25, 2
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %3, i64 %27
%29 = call i32 @memcpy(i8* %28, i8* %24, i32 4)
%30 = getelementptr inbounds i8, i8* %24, i64 4
%31 = add i32 %26, %20
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %3, i64 %32
%34 = call i32 @memcpy(i8* %33, i8* %30, i32 4)
%35 = getelementptr inbounds i8, i8* %24, i64 8
%36 = add i32 %31, %20
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = call i32 @memcpy(i8* %38, i8* %35, i32 4)
%40 = getelementptr inbounds i8, i8* %24, i64 12
%41 = add i32 %36, %20
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %3, i64 %42
%44 = call i32 @memcpy(i8* %43, i8* %40, i32 4)
%45 = getelementptr inbounds i8, i8* %24, i64 16
%46 = or i32 %25, %16
%47 = add i32 %46, 1
%48 = and i32 %47, %22
%49 = call i64 @log2(i32 1024)
%50 = trunc i64 %49 to i32
%51 = lshr i32 %48, %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %23, label %53
53: ; preds = %23
ret void
}