#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);
  EVP_Digest(str, i, md, len, type, NULL);
  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    11ac <ASN1_item_digest+0x7c>
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>
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   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%rbx
mov    %rdi,%rax
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rdx,%rdi
mov    %rax,%rdx
call   1050 <ASN1_item_i2d@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     118c <ASN1_item_digest+0x5c>
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1030 <EVP_Digest@plt>
mov    0x8(%rsp),%rdi
call   1040 <OPENSSL_free@plt>
mov    $0x1,%eax
jmp    118e <ASN1_item_digest+0x5e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
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 %29
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 = load i8*, i8** %13
%28 = call i32 @OPENSSL_free(i8* %27)
store i32 1, i32* %6
br label %29
29: ; preds = %20, %19
%30 = load i32, i32* %6
ret i32 %30
}

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 %15, label %11
11: ; preds = %5
%12 = call i32 @EVP_Digest(i8* %9, i32 %8, i8* %3, i32* %4, i32* %1, i32* null)
%13 = load i8*, i8** %6
%14 = call i32 @OPENSSL_free(i8* %13)
br label %15
15: ; preds = %5, %11
%16 = phi i32 [ 1, %11 ], [ 0, %5 ]
ret i32 %16
}