#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*/ 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)) {
    free(str);
    return (0);
  }
  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    11ca <ASN1_item_digest+0x9a>
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   1040 <EVP_Digest@plt>
cmp    $0x0,%eax
jne    11ba <ASN1_item_digest+0x8a>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ca <ASN1_item_digest+0x9a>
mov    -0x40(%rbp),%rdi
call   1030 <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     118e <ASN1_item_digest+0x5e>
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1040 <EVP_Digest@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1190 <ASN1_item_digest+0x60>
xor    %ebx,%ebx
mov    %ebx,%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 %34
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 %31, label %28
28: ; preds = %20
%29 = load i8*, i8** %13
%30 = call i32 @free(i8* %29)
store i32 0, i32* %6
br label %34
31: ; preds = %20
%32 = load i8*, i8** %13
%33 = call i32 @free(i8* %32)
store i32 1, i32* %6
br label %34
34: ; preds = %31, %28, %19
%35 = load i32, i32* %6
ret i32 %35
}

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 ne i32 %12, 0
%14 = load i8*, i8** %6
%15 = call i32 @free(i8* %14)
%16 = zext i1 %13 to i32
br label %17
17: ; preds = %11, %5
%18 = phi i32 [ 0, %5 ], [ %16, %11 ]
ret i32 %18
}