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

/* Variables and functions */
int ASN1_item_i2d(void *, unsigned char **, int /*<<< orphan*/ const *);
int /*<<< orphan*/ EVP_Digest(unsigned char *, int, unsigned char *,
                              unsigned int *, int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
                     unsigned char *md, unsigned int *len) {
  int i;
  unsigned char *str = NULL;
  i = ASN1_item_i2d(asn, &str, it);
  if (!str)
    return (0);
  if (!EVP_Digest(str, i, md, len, type, NULL))
    return 0;
  OPENSSL_free(str);
  return (1);
}


x86 assembly (clang, -O0):
<ASN1_item_digest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rsi
call   1050 <ASN1_item_i2d@plt>
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    117f <ASN1_item_digest+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <ASN1_item_digest+0x91>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1030 <EVP_Digest@plt>
cmp    $0x0,%eax
jne    11b1 <ASN1_item_digest+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <ASN1_item_digest+0x91>
mov    -0x40(%rbp),%rdi
call   1040 <OPENSSL_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_item_digest>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%r12
mov    %rdi,%rax
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rdx,%rdi
mov    %rax,%rdx
call   1050 <ASN1_item_i2d@plt>
mov    (%rsp),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     118a <ASN1_item_digest+0x5a>
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
xor    %r9d,%r9d
call   1030 <EVP_Digest@plt>
test   %eax,%eax
je     118a <ASN1_item_digest+0x5a>
mov    (%rsp),%rdi
call   1040 <OPENSSL_free@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ASN1_item_digest(i32* %0, i32* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
store i32* %0, i32** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i8* null, i8** %13
%14 = load i8*, i8** %9
%15 = load i32*, i32** %7
%16 = call i32 @ASN1_item_i2d(i8* %14, i8** %13, i32* %15)
store i32 %16, i32* %12
%17 = load i8*, i8** %13
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %5
store i32 0, i32* %6
br label %32
20: ; preds = %5
%21 = load i8*, i8** %13
%22 = load i32, i32* %12
%23 = load i8*, i8** %10
%24 = load i32*, i32** %11
%25 = load i32*, i32** %8
%26 = call i32 @EVP_Digest(i8* %21, i32 %22, i8* %23, i32* %24, i32* %25, i32* null)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %20
store i32 0, i32* %6
br label %32
29: ; preds = %20
%30 = load i8*, i8** %13
%31 = call i32 @OPENSSL_free(i8* %30)
store i32 1, i32* %6
br label %32
32: ; preds = %29, %28, %19
%33 = load i32, i32* %6
ret i32 %33
}

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