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

/* Variables and functions */
int /*<<< orphan*/ EVP_DigestFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                      unsigned int *);
int /*<<< orphan*/ EVP_DigestInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DigestUpdate(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ EVP_sha512();
int /*<<< orphan*/ assert(int);
scalar_t__ log2(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void do_step_G(EVP_MD_CTX *ctx, unsigned char *buffer,
               const unsigned char *macro, unsigned char *gout,
               const unsigned int step) {
  unsigned int outl, off;
  if (step) {
    unsigned int j, off, mask, start, dist;
    unsigned char *bp = buffer;
    mask = ((1 << ((int)log2((64 / 4)))) - 1) << (step * ((int)log2((64 / 4))));
    dist = (1 << (step * ((int)log2((64 / 4))))) * 4;
    for (start = 0; start < (1 << ((int)log2(4096)));
         start = ((start | mask) + 1) & ~mask) {
      for (j = 0, off = start * 4; j < (64 / 4); ++j, off += dist) {
        memcpy(bp, macro + off, 4);
        bp += 4;
      }
    };
  } else {
    buffer = (unsigned char *)macro;
  }
  for (off = 0; off < (4 * 4096); off += 64) {
    EVP_DigestInit_ex(ctx, EVP_sha512(), NULL);
    EVP_DigestUpdate(ctx, buffer + off, 64);
    EVP_DigestFinal_ex(ctx, gout + off, &outl);
    if (0)
      assert(64 == outl);
  }
}


x86 assembly (clang, -O0):
<do_step_G>:
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)
cmpl   $0x0,-0x24(%rbp)
je     1291 <do_step_G+0x131>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x10,%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    $0x10,%edi
call   1030 <log2@plt>
mov    -0x54(%rbp),%ecx
mov    %rax,%rdx
mov    -0x50(%rbp),%eax
imul   %edx,%ecx
shl    %cl,%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x10,%edi
call   1030 <log2@plt>
mov    -0x4c(%rbp),%ecx
imul   %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
shl    $0x2,%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x1000,%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    128c <do_step_G+0x12c>
movl   $0x0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x10,-0x30(%rbp)
jae    126e <do_step_G+0x10e>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1229 <do_step_G+0xc9>
jmp    1273 <do_step_G+0x113>
mov    -0x3c(%rbp),%eax
or     -0x38(%rbp),%eax
add    $0x1,%eax
mov    -0x38(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f2 <do_step_G+0x92>
jmp    1299 <do_step_G+0x139>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4000,-0x2c(%rbp)
jae    1308 <do_step_G+0x1a8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1050 <EVP_sha512@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <EVP_DigestInit_ex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    $0x40,%edx
call   1080 <EVP_DigestUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
lea    -0x28(%rbp),%rdx
call   1040 <EVP_DigestFinal_ex@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a0 <do_step_G+0x140>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_step_G>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rdi,%r15
test   %r8d,%r8d
je     1397 <do_step_G+0x237>
mov    %r8d,%r14d
mov    %rbx,0x18(%rsp)
mov    $0x10,%edi
mov    %rsi,%rbx
call   1030 <log2@plt>
mov    $0xffffffff,%ebp
mov    %eax,%ecx
shl    %cl,%ebp
not    %ebp
mov    $0x10,%edi
call   1030 <log2@plt>
imul   %r14d,%eax
mov    %eax,%ecx
shl    %cl,%ebp
mov    $0x10,%edi
call   1030 <log2@plt>
imul   %eax,%r14d
mov    $0x4,%r12d
mov    %r14d,%ecx
shl    %cl,%r12d
mov    $0x1000,%edi
call   1030 <log2@plt>
mov    %ebp,0xc(%rsp)
not    %ebp
mov    %ebp,0x8(%rsp)
xor    %r14d,%r14d
mov    %rbx,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
lea    0x0(,%r14,4),%esi
add    %r13,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    (%r12,%r14,4),%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x4(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x8(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0xc(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x10(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x14(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x18(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x1c(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x20(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x24(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x28(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x2c(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x30(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x34(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
mov    %rbp,%rsi
add    %r13,%rsi
lea    0x38(%rbx),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
add    %r12d,%ebp
add    %r13,%rbp
lea    0x3c(%rbx),%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
or     0xc(%rsp),%r14d
add    $0x1,%r14d
and    0x8(%rsp),%r14d
mov    $0x1000,%edi
call   1030 <log2@plt>
mov    %r14d,%edx
mov    %eax,%ecx
shr    %cl,%edx
add    $0x40,%rbx
test   %edx,%edx
je     11f0 <do_step_G+0x90>
mov    0x10(%rsp),%r13
mov    0x18(%rsp),%rbx
lea    0x24(%rsp),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <EVP_sha512@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <EVP_DigestInit_ex@plt>
mov    %r13,%rsi
add    %rbp,%rsi
mov    %r15,%rdi
mov    $0x40,%edx
call   1080 <EVP_DigestUpdate@plt>
lea    (%rbx,%rbp,1),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <EVP_DigestFinal_ex@plt>
lea    0x40(%rbp),%rax
cmp    $0x3fc0,%rbp
mov    %rax,%rbp
jb     13a0 <do_step_G+0x240>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @do_step_G(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 i32
%18 = 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
%19 = load i32, i32* %10
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %75
21: ; preds = %5
%22 = load i8*, i8** %7
store i8* %22, i8** %18
%23 = call i64 @log2(i32 16)
%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 16)
%29 = trunc i64 %28 to i32
%30 = mul i32 %27, %29
%31 = shl i32 %26, %30
store i32 %31, i32* %15
%32 = load i32, i32* %10
%33 = call i64 @log2(i32 16)
%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* %17
store i32 0, i32* %16
br label %38
38: ; preds = %66, %21
%39 = load i32, i32* %16
%40 = call i64 @log2(i32 4096)
%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* %13
%45 = load i32, i32* %16
%46 = mul i32 %45, 4
store i32 %46, i32* %14
br label %47
47: ; preds = %59, %44
%48 = load i32, i32* %13
%49 = icmp ult i32 %48, 16
br i1 %49, label %50, label %65
50: ; preds = %47
%51 = load i8*, i8** %18
%52 = load i8*, i8** %8
%53 = load i32, i32* %14
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = call i32 @memcpy(i8* %51, i8* %55, i32 4)
%57 = load i8*, i8** %18
%58 = getelementptr inbounds i8, i8* %57, i64 4
store i8* %58, i8** %18
br label %59
59: ; preds = %50
%60 = load i32, i32* %13
%61 = add i32 %60, 1
store i32 %61, i32* %13
%62 = load i32, i32* %17
%63 = load i32, i32* %14
%64 = add i32 %63, %62
store i32 %64, i32* %14
br label %47
65: ; preds = %47
br label %66
66: ; preds = %65
%67 = load i32, i32* %16
%68 = load i32, i32* %15
%69 = or i32 %67, %68
%70 = add i32 %69, 1
%71 = load i32, i32* %15
%72 = xor i32 %71, -1
%73 = and i32 %70, %72
store i32 %73, i32* %16
br label %38
74: ; preds = %38
br label %77
75: ; preds = %5
%76 = load i8*, i8** %8
store i8* %76, i8** %7
br label %77
77: ; preds = %75, %74
store i32 0, i32* %12
br label %78
78: ; preds = %97, %77
%79 = load i32, i32* %12
%80 = icmp ult i32 %79, 16384
br i1 %80, label %81, label %100
81: ; preds = %78
%82 = load i32*, i32** %6
%83 = call i32 (...) @EVP_sha512()
%84 = call i32 @EVP_DigestInit_ex(i32* %82, i32 %83, i32* null)
%85 = load i32*, i32** %6
%86 = load i8*, i8** %7
%87 = load i32, i32* %12
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = call i32 @EVP_DigestUpdate(i32* %85, i8* %89, i32 64)
%91 = load i32*, i32** %6
%92 = load i8*, i8** %9
%93 = load i32, i32* %12
%94 = zext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = call i32 @EVP_DigestFinal_ex(i32* %91, i8* %95, i32* %11)
br label %97
97: ; preds = %81
%98 = load i32, i32* %12
%99 = add i32 %98, 64
store i32 %99, i32* %12
br label %78
100: ; preds = %78
ret void
}

LLVM IR (-O2):
define void @do_step_G(i32* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = icmp eq i32 %4, 0
br i1 %8, label %114, label %9
9: ; preds = %5
%10 = tail call i64 @log2(i32 16)
%11 = trunc i64 %10 to i32
%12 = shl nsw i32 -1, %11
%13 = xor i32 %12, -1
%14 = tail call i64 @log2(i32 16)
%15 = trunc i64 %14 to i32
%16 = mul i32 %15, %4
%17 = shl i32 %13, %16
%18 = tail call i64 @log2(i32 16)
%19 = trunc i64 %18 to i32
%20 = mul i32 %19, %4
%21 = shl i32 4, %20
%22 = tail call i64 @log2(i32 4096)
%23 = xor i32 %17, -1
br label %24
24: ; preds = %9, %24
%25 = phi i8* [ %1, %9 ], [ %106, %24 ]
%26 = phi i32 [ 0, %9 ], [ %109, %24 ]
%27 = shl i32 %26, 2
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = tail call i32 @memcpy(i8* %25, i8* %29, i32 4)
%31 = getelementptr inbounds i8, i8* %25, i64 4
%32 = add i32 %27, %21
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %2, i64 %33
%35 = tail call i32 @memcpy(i8* %31, i8* %34, i32 4)
%36 = getelementptr inbounds i8, i8* %25, i64 8
%37 = add i32 %32, %21
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %2, i64 %38
%40 = tail call i32 @memcpy(i8* %36, i8* %39, i32 4)
%41 = getelementptr inbounds i8, i8* %25, i64 12
%42 = add i32 %37, %21
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %2, i64 %43
%45 = tail call i32 @memcpy(i8* %41, i8* %44, i32 4)
%46 = getelementptr inbounds i8, i8* %25, i64 16
%47 = add i32 %42, %21
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %2, i64 %48
%50 = tail call i32 @memcpy(i8* %46, i8* %49, i32 4)
%51 = getelementptr inbounds i8, i8* %25, i64 20
%52 = add i32 %47, %21
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %2, i64 %53
%55 = tail call i32 @memcpy(i8* %51, i8* %54, i32 4)
%56 = getelementptr inbounds i8, i8* %25, i64 24
%57 = add i32 %52, %21
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %2, i64 %58
%60 = tail call i32 @memcpy(i8* %56, i8* %59, i32 4)
%61 = getelementptr inbounds i8, i8* %25, i64 28
%62 = add i32 %57, %21
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %2, i64 %63
%65 = tail call i32 @memcpy(i8* %61, i8* %64, i32 4)
%66 = getelementptr inbounds i8, i8* %25, i64 32
%67 = add i32 %62, %21
%68 = zext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %2, i64 %68
%70 = tail call i32 @memcpy(i8* %66, i8* %69, i32 4)
%71 = getelementptr inbounds i8, i8* %25, i64 36
%72 = add i32 %67, %21
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %2, i64 %73
%75 = tail call i32 @memcpy(i8* %71, i8* %74, i32 4)
%76 = getelementptr inbounds i8, i8* %25, i64 40
%77 = add i32 %72, %21
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %2, i64 %78
%80 = tail call i32 @memcpy(i8* %76, i8* %79, i32 4)
%81 = getelementptr inbounds i8, i8* %25, i64 44
%82 = add i32 %77, %21
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %2, i64 %83
%85 = tail call i32 @memcpy(i8* %81, i8* %84, i32 4)
%86 = getelementptr inbounds i8, i8* %25, i64 48
%87 = add i32 %82, %21
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %2, i64 %88
%90 = tail call i32 @memcpy(i8* %86, i8* %89, i32 4)
%91 = getelementptr inbounds i8, i8* %25, i64 52
%92 = add i32 %87, %21
%93 = zext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %2, i64 %93
%95 = tail call i32 @memcpy(i8* %91, i8* %94, i32 4)
%96 = getelementptr inbounds i8, i8* %25, i64 56
%97 = add i32 %92, %21
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %2, i64 %98
%100 = tail call i32 @memcpy(i8* %96, i8* %99, i32 4)
%101 = getelementptr inbounds i8, i8* %25, i64 60
%102 = add i32 %97, %21
%103 = zext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %2, i64 %103
%105 = tail call i32 @memcpy(i8* %101, i8* %104, i32 4)
%106 = getelementptr inbounds i8, i8* %25, i64 64
%107 = or i32 %26, %17
%108 = add i32 %107, 1
%109 = and i32 %108, %23
%110 = tail call i64 @log2(i32 4096)
%111 = trunc i64 %110 to i32
%112 = lshr i32 %109, %111
%113 = icmp eq i32 %112, 0
br i1 %113, label %24, label %114
114: ; preds = %24, %5
%115 = phi i8* [ %2, %5 ], [ %1, %24 ]
br label %116
116: ; preds = %114, %116
%117 = phi i64 [ 0, %114 ], [ %124, %116 ]
%118 = call i32 (...) @EVP_sha512()
%119 = call i32 @EVP_DigestInit_ex(i32* %0, i32 %118, i32* null)
%120 = getelementptr inbounds i8, i8* %115, i64 %117
%121 = call i32 @EVP_DigestUpdate(i32* %0, i8* %120, i32 64)
%122 = getelementptr inbounds i8, i8* %3, i64 %117
%123 = call i32 @EVP_DigestFinal_ex(i32* %0, i8* %122, i32* %6)
%124 = add nuw nsw i64 %117, 64
%125 = icmp ult i64 %117, 16320
br i1 %125, label %116, label %126
126: ; preds = %116
ret void
}