#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*/ SHA256(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void gen_message_random(unsigned char *R, const unsigned char *sk_prf,
                        const unsigned char *optrand, unsigned char *m,
                        unsigned long long mlen) {
  unsigned char outbuf[32];
  unsigned char tmp[64 + 32];
  unsigned char *m_with_prefix = m - 64 - 16;
  int i;
  memcpy(m_with_prefix, sk_prf, 16);
  memset(m_with_prefix + 16, 0, 64 - 16);
  for (i = 0; i < 64; i++) {
    m_with_prefix[i] ^= 0x36;
  }
  memcpy(m_with_prefix + 64, optrand, 16);
  SHA256(m_with_prefix, mlen + 64 + 16, tmp + 64);
  memcpy(tmp, sk_prf, 16);
  memset(tmp + 16, 0, 64 - 16);
  for (i = 0; i < 64; i++) {
    tmp[i] ^= 0x5c;
  }
  SHA256(tmp, 64, outbuf);
  memcpy(R, outbuf, 16);
}


x86 assembly (clang, -O0):
<gen_message_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffc0,%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0xb8(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movl   $0x0,-0xbc(%rbp)
cmpl   $0x40,-0xbc(%rbp)
jge    11d1 <gen_message_random+0xa1>
mov    -0xb8(%rbp),%rax
movslq -0xbc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
xor    $0x36,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    1198 <gen_message_random+0x68>
mov    -0xb8(%rbp),%rdi
add    $0x40,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0xb8(%rbp),%rdi
mov    -0x28(%rbp),%rax
add    $0x40,%rax
add    $0x10,%rax
mov    %eax,%esi
lea    -0xb0(%rbp),%rdx
add    $0x40,%rdx
call   1030 <SHA256@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movl   $0x0,-0xbc(%rbp)
cmpl   $0x40,-0xbc(%rbp)
jge    127f <gen_message_random+0x14f>
movslq -0xbc(%rbp),%rax
movzbl -0xb0(%rbp,%rax,1),%ecx
ff
xor    $0x5c,%ecx
mov    %cl,-0xb0(%rbp,%rax,1)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    1245 <gen_message_random+0x115>
lea    -0xb0(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x40,%esi
call   1030 <SHA256@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_message_random>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
lea    -0x50(%rcx),%r12
mov    %r12,%rdi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movaps 0xe88(%rip),%xmm0
movups -0x50(%rbp),%xmm1
movups -0x40(%rbp),%xmm2
movups -0x30(%rbp),%xmm3
movups -0x20(%rbp),%xmm4
xorps  %xmm0,%xmm1
movups %xmm1,-0x50(%rbp)
xorps  %xmm0,%xmm2
movups %xmm2,-0x40(%rbp)
xorps  %xmm0,%xmm3
movups %xmm3,-0x30(%rbp)
xorps  %xmm0,%xmm4
movups %xmm4,-0x20(%rbp)
add    $0xfffffffffffffff0,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x50,%ebx
lea    0x40(%rsp),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <SHA256@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movaps 0xe1b(%rip),%xmm0
movaps (%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,(%rsp)
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
xorps  0x30(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x60(%rsp),%rbp
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   1030 <SHA256@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @gen_message_random(i8* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca [32 x i8]
%7 = alloca [96 x i8]
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds i8, i8* %3, i64 -80
%11 = tail call i32 @memcpy(i8* %10, i8* %1, i32 16)
%12 = getelementptr inbounds i8, i8* %3, i64 -64
%13 = tail call i32 @memset(i8* %12, i32 0, i32 48)
%14 = bitcast i8* %10 to <16 x i8>*
%15 = load <16 x i8>, <16 x i8>* %14
%16 = xor <16 x i8> %15, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%17 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> %16, <16 x i8>* %17
%18 = getelementptr inbounds i8, i8* %3, i64 -64
%19 = bitcast i8* %18 to <16 x i8>*
%20 = load <16 x i8>, <16 x i8>* %19
%21 = xor <16 x i8> %20, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%22 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> %21, <16 x i8>* %22
%23 = getelementptr inbounds i8, i8* %3, i64 -48
%24 = bitcast i8* %23 to <16 x i8>*
%25 = load <16 x i8>, <16 x i8>* %24
%26 = xor <16 x i8> %25, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%27 = bitcast i8* %23 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %27
%28 = getelementptr inbounds i8, i8* %3, i64 -32
%29 = bitcast i8* %28 to <16 x i8>*
%30 = load <16 x i8>, <16 x i8>* %29
%31 = xor <16 x i8> %30, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%32 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> %31, <16 x i8>* %32
%33 = getelementptr inbounds i8, i8* %3, i64 -16
%34 = tail call i32 @memcpy(i8* %33, i8* %2, i32 16)
%35 = trunc i64 %4 to i32
%36 = add i32 %35, 80
%37 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 64
%38 = call i32 @SHA256(i8* %10, i32 %36, i8* %37)
%39 = call i32 @memcpy(i8* %9, i8* %1, i32 16)
%40 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 16
%41 = call i32 @memset(i8* %40, i32 0, i32 48)
%42 = bitcast [96 x i8]* %7 to <16 x i8>*
%43 = load <16 x i8>, <16 x i8>* %42
%44 = xor <16 x i8> %43, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%45 = bitcast [96 x i8]* %7 to <16 x i8>*
store <16 x i8> %44, <16 x i8>* %45
%46 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 16
%47 = bitcast i8* %46 to <16 x i8>*
%48 = load <16 x i8>, <16 x i8>* %47
%49 = xor <16 x i8> %48, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%50 = bitcast i8* %46 to <16 x i8>*
store <16 x i8> %49, <16 x i8>* %50
%51 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 32
%52 = bitcast i8* %51 to <16 x i8>*
%53 = load <16 x i8>, <16 x i8>* %52
%54 = xor <16 x i8> %53, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%55 = bitcast i8* %51 to <16 x i8>*
store <16 x i8> %54, <16 x i8>* %55
%56 = getelementptr inbounds [96 x i8], [96 x i8]* %7, i64 0, i64 48
%57 = bitcast i8* %56 to <16 x i8>*
%58 = load <16 x i8>, <16 x i8>* %57
%59 = xor <16 x i8> %58, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%60 = bitcast i8* %56 to <16 x i8>*
store <16 x i8> %59, <16 x i8>* %60
%61 = call i32 @SHA256(i8* %9, i32 64, i8* %8)
%62 = call i32 @memcpy(i8* %0, i8* %8, i32 16)
ret void
}