#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_PKEY_CTX;
typedef int /*<<< orphan*/ EVP_MD_CTX;

/* Variables and functions */
int EVP_DigestFinal_ex(int /*<<< orphan*/ *, unsigned char *, unsigned int *);
int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
                          EVP_MD_CTX *mctx) {
  unsigned int tmpsiglen = *siglen;
  int ret;
  if (!sig) {
    *siglen = 4;
    return 1;
  }
  ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
  *siglen = tmpsiglen;
  return ret;
}


x86 assembly (clang, -O0):
<pkey_gost_mac_signctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1154 <pkey_gost_mac_signctx+0x44>
mov    -0x20(%rbp),%rax
movq   $0x4,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    117a <pkey_gost_mac_signctx+0x6a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <EVP_DigestFinal_ex@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_gost_mac_signctx>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    (%rdx),%eax
mov    %eax,0xc(%rsp)
test   %rsi,%rsi
je     1136 <pkey_gost_mac_signctx+0x26>
lea    0xc(%rsp),%rdx
mov    %rcx,%rdi
call   1030 <EVP_DigestFinal_ex@plt>
mov    0xc(%rsp),%ecx
jmp    1140 <pkey_gost_mac_signctx+0x30>
mov    $0x1,%eax
mov    $0x4,%ecx
mov    %rcx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pkey_gost_mac_signctx(i32* %0, i8* %1, i64* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i32* %3, i32** %9
%12 = load i64*, i64** %8
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
store i32 %14, i32* %10
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %4
%18 = load i64*, i64** %8
store i64 4, i64* %18
store i32 1, i32* %5
br label %27
19: ; preds = %4
%20 = load i32*, i32** %9
%21 = load i8*, i8** %7
%22 = call i32 @EVP_DigestFinal_ex(i32* %20, i8* %21, i32* %10)
store i32 %22, i32* %11
%23 = load i32, i32* %10
%24 = zext i32 %23 to i64
%25 = load i64*, i64** %8
store i64 %24, i64* %25
%26 = load i32, i32* %11
store i32 %26, i32* %5
br label %27
27: ; preds = %19, %17
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
define i32 @pkey_gost_mac_signctx(i32* nocapture readnone %0, i8* %1, i64* nocapture %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i64, i64* %2
%8 = trunc i64 %7 to i32
store i32 %8, i32* %5
%9 = icmp eq i8* %1, null
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = call i32 @EVP_DigestFinal_ex(i32* %3, i8* %1, i32* %5)
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %4, %10
%15 = phi i64 [ %13, %10 ], [ 4, %4 ]
%16 = phi i32 [ %11, %10 ], [ 1, %4 ]
store i64 %15, i64* %2
ret i32 %16
}