#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 */
struct CRYPTO_HASH_CTX {
  int dummy;
};
typedef int /*<<< orphan*/ EVP_MD_CTX;

/* Variables and functions */
scalar_t__ EVP_MD_CTX_copy_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ ssh_set_error(char *);
int crypto_sha2_copy_ctx(struct CRYPTO_HASH_CTX *crypto_to_ctx,
                         const struct CRYPTO_HASH_CTX *crypto_from_ctx) {
  EVP_MD_CTX *to_ctx = ((EVP_MD_CTX *)(crypto_to_ctx));
  const EVP_MD_CTX *from_ctx = ((EVP_MD_CTX *)(crypto_from_ctx));
  if (EVP_MD_CTX_copy_ex(to_ctx, from_ctx) == 0) {
    ssh_set_error("error copying sha2 hash");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<crypto_sha2_copy_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <EVP_MD_CTX_copy_ex@plt>
cmp    $0x0,%rax
jne    116f <crypto_sha2_copy_ctx+0x4f>
lea    0xea2(%rip),%rdi
call   1040 <ssh_set_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1176 <crypto_sha2_copy_ctx+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_sha2_copy_ctx>:
push   %rax
call   1030 <EVP_MD_CTX_copy_ex@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1132 <crypto_sha2_copy_ctx+0x12>
pop    %rcx
ret
lea    0xec7(%rip),%rdi
call   1040 <ssh_set_error@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.CRYPTO_HASH_CTX = type { i32 }
@.str = [24 x i8] c"error copying sha2 hash\00"
define i32 @crypto_sha2_copy_ctx(%struct.CRYPTO_HASH_CTX* %0, %struct.CRYPTO_HASH_CTX* %1) {
%3 = alloca i32
%4 = alloca %struct.CRYPTO_HASH_CTX*
%5 = alloca %struct.CRYPTO_HASH_CTX*
%6 = alloca i32*
%7 = alloca i32*
store %struct.CRYPTO_HASH_CTX* %0, %struct.CRYPTO_HASH_CTX** %4
store %struct.CRYPTO_HASH_CTX* %1, %struct.CRYPTO_HASH_CTX** %5
%8 = load %struct.CRYPTO_HASH_CTX*, %struct.CRYPTO_HASH_CTX** %4
%9 = bitcast %struct.CRYPTO_HASH_CTX* %8 to i32*
store i32* %9, i32** %6
%10 = load %struct.CRYPTO_HASH_CTX*, %struct.CRYPTO_HASH_CTX** %5
%11 = bitcast %struct.CRYPTO_HASH_CTX* %10 to i32*
store i32* %11, i32** %7
%12 = load i32*, i32** %6
%13 = load i32*, i32** %7
%14 = call i64 @EVP_MD_CTX_copy_ex(i32* %12, i32* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @ssh_set_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %19
18: ; preds = %2
store i32 0, i32* %3
br label %19
19: ; preds = %18, %16
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.CRYPTO_HASH_CTX = type { i32 }
@.str = [24 x i8] c"error copying sha2 hash\00"
define i32 @crypto_sha2_copy_ctx(%struct.CRYPTO_HASH_CTX* %0, %struct.CRYPTO_HASH_CTX* %1) {
%3 = getelementptr %struct.CRYPTO_HASH_CTX, %struct.CRYPTO_HASH_CTX* %0, i64 0, i32 0
%4 = getelementptr %struct.CRYPTO_HASH_CTX, %struct.CRYPTO_HASH_CTX* %1, i64 0, i32 0
%5 = tail call i64 @EVP_MD_CTX_copy_ex(i32* %3, i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @ssh_set_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ -1, %7 ], [ 0, %2 ]
ret i32 %10
}