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

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                              size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void calculate_signature(const uint8_t *data, size_t length,
                         const uint8_t mac_key[40], uint8_t signature[8]) {
  MD5_CTX md5;
  uint8_t full_result[16];
  MD5_Init(&md5);
  MD5_Update(&md5, mac_key, 40);
  MD5_Update(&md5, data, length);
  MD5_Final(full_result, &md5);
  memcpy(signature, full_result, 8);
}


x86 assembly (clang, -O0):
<calculate_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1050 <MD5_Init@plt>
mov    -0x18(%rbp),%rsi
lea    -0x24(%rbp),%rdi
mov    $0x28,%edx
call   1060 <MD5_Update@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x24(%rbp),%rdi
call   1060 <MD5_Update@plt>
lea    -0x70(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1030 <MD5_Final@plt>
mov    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_signature>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <MD5_Init@plt>
mov    $0x28,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <MD5_Update@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <MD5_Update@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <MD5_Final@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calculate_signature(i32* %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [16 x i32]
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = call i32 @MD5_Init(i32* %9)
%12 = load i32*, i32** %7
%13 = call i32 @MD5_Update(i32* %9, i32* %12, i64 40)
%14 = load i32*, i32** %5
%15 = load i64, i64* %6
%16 = call i32 @MD5_Update(i32* %9, i32* %14, i64 %15)
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %10, i64 0, i64 0
%18 = call i32 @MD5_Final(i32* %17, i32* %9)
%19 = load i32*, i32** %8
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %10, i64 0, i64 0
%21 = call i32 @memcpy(i32* %19, i32* %20, i32 8)
ret void
}

LLVM IR (-O2):
define void @calculate_signature(i32* %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca [16 x i32]
%7 = bitcast i32* %5 to i8*
%8 = bitcast [16 x i32]* %6 to i8*
%9 = call i32 @MD5_Init(i32* %5)
%10 = call i32 @MD5_Update(i32* %5, i32* %2, i64 40)
%11 = call i32 @MD5_Update(i32* %5, i32* %0, i64 %1)
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%13 = call i32 @MD5_Final(i32* %12, i32* %5)
%14 = call i32 @memcpy(i32* %3, i32* %12, i32 8)
ret void
}