#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 */

/* Variables and functions */
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/, unsigned char const *, unsigned int,
                        unsigned char const *, unsigned int, unsigned char *,
                        unsigned int *);
int /*<<< orphan*/ SHA256_DIGEST_LENGTH;
unsigned char *malloc(int /*<<< orphan*/);
unsigned char *KDF(const unsigned char *key, unsigned int keylen,
                   const unsigned char *appid, unsigned int appid_len) {
  unsigned int r;
  unsigned char *ret;
  ret = malloc(SHA256_DIGEST_LENGTH);
  if (!ret)
    return NULL;
  HMAC(EVP_sha256(), key, keylen, appid, appid_len, ret, &r);
  return ret;
}


x86 assembly (clang, -O0):
<KDF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1170 <KDF+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11a1 <KDF+0x71>
mov    $0x0,%al
call   1050 <EVP_sha256@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
lea    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <HMAC@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KDF>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <KDF+0x54>
xor    %eax,%eax
call   1050 <EVP_sha256@plt>
lea    0xc(%rsp),%rcx
mov    %rcx,(%rsp)
mov    %eax,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
mov    %rbx,%r9
call   1030 <HMAC@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @KDF(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %4
store i8* null, i8** %5
br label %26
17: ; preds = %4
%18 = call i32 (...) @EVP_sha256()
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = load i8*, i8** %11
%24 = call i32 @HMAC(i32 %18, i8* %19, i32 %20, i8* %21, i32 %22, i8* %23, i32* %10)
%25 = load i8*, i8** %11
store i8* %25, i8** %5
br label %26
26: ; preds = %17, %16
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @KDF(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @SHA256_DIGEST_LENGTH
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = tail call i32 (...) @EVP_sha256()
%12 = call i32 @HMAC(i32 %11, i8* %0, i32 %1, i8* %2, i32 %3, i8* %8, i32* %5)
br label %13
13: ; preds = %4, %10
ret i8* %8
}