#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_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char *, int);
int /*<<< orphan*/ assert(int);
scalar_t__ log2(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void do_step_encrypt(EVP_CIPHER_CTX *ctx, unsigned char *buffer,
                     const unsigned char *macro, unsigned char *out,
                     const unsigned int step) {
  int 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(bp, macro + off, 4);
      bp += 4;
    }
  };
  EVP_EncryptUpdate(ctx, out, &outl, buffer, (4 * 1024));
  if (0)
    assert((4 * 1024) == outl);
}


x86 assembly (clang, -O0):
<do_step_encrypt>:
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    -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    1252 <do_step_encrypt+0x122>
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jae    1234 <do_step_encrypt+0x104>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%eax
add    %rax,%rsi
mov    $0x4,%edx
call   1050 <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    11ef <do_step_encrypt+0xbf>
jmp    1239 <do_step_encrypt+0x109>
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    11b8 <do_step_encrypt+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdx
mov    $0x1000,%r8d
call   1040 <EVP_EncryptUpdate@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_step_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,0x8(%rsp)
mov    $0x4,%r14d
mov    $0x4,%edi
call   1030 <log2@plt>
mov    $0xffffffff,%r15d
mov    %eax,%ecx
shl    %cl,%r15d
not    %r15d
mov    $0x4,%edi
call   1030 <log2@plt>
imul   %ebx,%eax
mov    %eax,%ecx
shl    %cl,%r15d
mov    $0x4,%edi
call   1030 <log2@plt>
imul   %eax,%ebx
mov    %ebx,%ecx
shl    %cl,%r14d
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %r15d,0x4(%rsp)
not    %r15d
xor    %r12d,%r12d
mov    %rbp,0x18(%rsp)
mov    %rbp,%rbx
lea    0x0(,%r12,4),%esi
add    %r13,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    (%r14,%r12,4),%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x4(%rbx),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
add    %r14d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x8(%rbx),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
add    %r14d,%ebp
add    %r13,%rbp
lea    0xc(%rbx),%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
or     0x4(%rsp),%r12d
add    $0x1,%r12d
and    %r15d,%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_encrypt+0x80>
lea    0x24(%rsp),%rdx
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rcx
mov    $0x1000,%r8d
call   1040 <EVP_EncryptUpdate@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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