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

/* Variables and functions */
int /*<<< orphan*/ ERR_GOST_error(int, int, char *, int);
int /*<<< orphan*/ EVP_PKEY_CTRL_SET_MAC_KEY;
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int pkey_gost_mac_ctrl(int /*<<< orphan*/ *, int /*<<< orphan*/, int, ...);
int /*<<< orphan*/ strcmp(char const *, char *);
unsigned char *string_to_hex(char const *, long *);
int strlen(char const *);
int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
                           const char *value) {
  if (!strcmp(type, "key")) {
    if (strlen(value) != 32) {
      ERR_GOST_error(
          (129), (111),
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/"
          "lib/dependencies/openssl/engines/ccgost/gost_pmeth.c",
          502);
      return 0;
    }
    return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32,
                              (char *)value);
  }
  if (!strcmp(type, "hexkey")) {
    long keylen;
    int ret;
    unsigned char *keybuf = string_to_hex(value, &keylen);
    if (!keybuf || keylen != 32) {
      ERR_GOST_error(
          (129), (111),
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/"
          "lib/dependencies/openssl/engines/ccgost/gost_pmeth.c",
          514);
      OPENSSL_free(keybuf);
      return 0;
    }
    ret = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32, keybuf);
    OPENSSL_free(keybuf);
    return ret;
  }
  return -2;
}


x86 assembly (clang, -O0):
<pkey_gost_mac_ctrl_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xf3b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11eb <pkey_gost_mac_ctrl_str+0x8b>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x20,%eax
je     11c6 <pkey_gost_mac_ctrl_str+0x66>
mov    $0x81,%edi
mov    $0x6f,%esi
lea    0xe50(%rip),%rdx
mov    $0x1f6,%ecx
call   1070 <ERR_GOST_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1296 <pkey_gost_mac_ctrl_str+0x136>
mov    -0x10(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rcx
mov    $0x20,%edx
mov    $0x0,%al
call   1040 <pkey_gost_mac_ctrl@plt>
mov    %eax,-0x4(%rbp)
jmp    1296 <pkey_gost_mac_ctrl_str+0x136>
mov    -0x18(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    128f <pkey_gost_mac_ctrl_str+0x12f>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <string_to_hex@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     122b <pkey_gost_mac_ctrl_str+0xcb>
cmpq   $0x20,-0x28(%rbp)
je     125b <pkey_gost_mac_ctrl_str+0xfb>
mov    $0x81,%edi
mov    $0x6f,%esi
lea    0xdc4(%rip),%rdx
mov    $0x202,%ecx
call   1070 <ERR_GOST_error@plt>
mov    -0x38(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1296 <pkey_gost_mac_ctrl_str+0x136>
mov    -0x10(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rcx
mov    $0x20,%edx
mov    $0x0,%al
call   1040 <pkey_gost_mac_ctrl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1296 <pkey_gost_mac_ctrl_str+0x136>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_gost_mac_ctrl_str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xf42(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e4 <pkey_gost_mac_ctrl_str+0x84>
lea    0xf2c(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
mov    $0xfffffffe,%ebp
test   %eax,%eax
jne    1256 <pkey_gost_mac_ctrl_str+0xf6>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <string_to_hex@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1231 <pkey_gost_mac_ctrl_str+0xd1>
cmpq   $0x20,0x8(%rsp)
jne    1231 <pkey_gost_mac_ctrl_str+0xd1>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    $0x20,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <pkey_gost_mac_ctrl@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <OPENSSL_free@plt>
jmp    1256 <pkey_gost_mac_ctrl_str+0xf6>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x20,%eax
jne    1214 <pkey_gost_mac_ctrl_str+0xb4>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    $0x20,%edx
mov    %rbx,%rcx
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <pkey_gost_mac_ctrl@plt>
lea    0xde5(%rip),%rdx
mov    $0x81,%edi
mov    $0x6f,%esi
mov    $0x1f6,%ecx
call   1070 <ERR_GOST_error@plt>
jmp    1254 <pkey_gost_mac_ctrl_str+0xf4>
lea    0xdc8(%rip),%rdx
mov    $0x81,%edi
mov    $0x6f,%esi
mov    $0x202,%ecx
call   1070 <ERR_GOST_error@plt>
mov    %rbx,%rdi
call   1080 <OPENSSL_free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"key\00"
@.str.1 = [183 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/dependencies/openssl/engines/ccgost/gost_pmeth.c\00"
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
@.str.2 = [7 x i8] c"hexkey\00"
define i32 @pkey_gost_mac_ctrl_str(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %6
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
%17 = icmp ne i32 %16, 32
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @ERR_GOST_error(i32 129, i32 111, i8* getelementptr inbounds ([183 x i8], [183 x i8]* @.str.1, i64 0, i64 0), i32 502)
store i32 0, i32* %4
br label %50
20: ; preds = %14
%21 = load i32*, i32** %5
%22 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%23 = load i8*, i8** %7
%24 = call i32 (i32*, i32, i32, ...) @pkey_gost_mac_ctrl(i32* %21, i32 %22, i32 32, i8* %23)
store i32 %24, i32* %4
br label %50
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %49, label %29
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = call i8* @string_to_hex(i8* %30, i64* %8)
store i8* %31, i8** %10
%32 = load i8*, i8** %10
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i64, i64* %8
%36 = icmp ne i64 %35, 32
br i1 %36, label %37, label %41
37: ; preds = %34, %29
%38 = call i32 @ERR_GOST_error(i32 129, i32 111, i8* getelementptr inbounds ([183 x i8], [183 x i8]* @.str.1, i64 0, i64 0), i32 514)
%39 = load i8*, i8** %10
%40 = call i32 @OPENSSL_free(i8* %39)
store i32 0, i32* %4
br label %50
41: ; preds = %34
%42 = load i32*, i32** %5
%43 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%44 = load i8*, i8** %10
%45 = call i32 (i32*, i32, i32, ...) @pkey_gost_mac_ctrl(i32* %42, i32 %43, i32 32, i8* %44)
store i32 %45, i32* %9
%46 = load i8*, i8** %10
%47 = call i32 @OPENSSL_free(i8* %46)
%48 = load i32, i32* %9
store i32 %48, i32* %4
br label %50
49: ; preds = %25
store i32 -2, i32* %4
br label %50
50: ; preds = %49, %41, %37, %20, %18
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"key\00"
@.str.1 = [183 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/dependencies/openssl/engines/ccgost/gost_pmeth.c\00"
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
@.str.2 = [7 x i8] c"hexkey\00"
define i32 @pkey_gost_mac_ctrl_str(i32* %0, i8* nocapture %1, i8* %2) {
%4 = alloca i64
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp eq i32 %8, 32
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @ERR_GOST_error(i32 129, i32 111, i8* getelementptr inbounds ([183 x i8], [183 x i8]* @.str.1, i64 0, i64 0), i32 502)
br label %34
12: ; preds = %7
%13 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%14 = tail call i32 (i32*, i32, i32, ...) @pkey_gost_mac_ctrl(i32* %0, i32 %13, i32 32, i8* %2)
br label %34
15: ; preds = %3
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = bitcast i64* %4 to i8*
%20 = call i8* @string_to_hex(i8* %2, i64* %4)
%21 = icmp eq i8* %20, null
%22 = load i64, i64* %4
%23 = icmp ne i64 %22, 32
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = call i32 @ERR_GOST_error(i32 129, i32 111, i8* getelementptr inbounds ([183 x i8], [183 x i8]* @.str.1, i64 0, i64 0), i32 514)
%27 = call i32 @OPENSSL_free(i8* %20)
br label %32
28: ; preds = %18
%29 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%30 = call i32 (i32*, i32, i32, ...) @pkey_gost_mac_ctrl(i32* %0, i32 %29, i32 32, i8* %20)
%31 = call i32 @OPENSSL_free(i8* %20)
br label %32
32: ; preds = %28, %25
%33 = phi i32 [ 0, %25 ], [ %30, %28 ]
br label %34
34: ; preds = %15, %32, %12, %10
%35 = phi i32 [ %33, %32 ], [ 0, %10 ], [ %14, %12 ], [ -2, %15 ]
ret i32 %35
}