#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*/ uint64_t;
typedef int /*<<< orphan*/ counter;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ calculate_hmac_sha512(int /*<<< orphan*/ const *, size_t,
                                         int /*<<< orphan*/ *, int,
                                         int /*<<< orphan*/ *, int);
int get_truncate(int /*<<< orphan*/ *, int, char *, size_t);
int /*<<< orphan*/ htobe64(int /*<<< orphan*/);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int get_totp_sha512(const uint8_t *hashdata, size_t len, uint64_t time,
                    char *dst, size_t maxlen) {
  uint8_t buffer[64];
  uint64_t counter = htobe64(time);
  memset(buffer, 0, sizeof(buffer));
  calculate_hmac_sha512(hashdata, len, (uint8_t *)&counter, sizeof(counter),
                        buffer, sizeof(buffer));
  return get_truncate(buffer, sizeof(buffer), dst, maxlen);
}


x86 assembly (clang, -O0):
<get_totp_sha512>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htobe64@plt>
mov    %eax,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x130(%rbp),%r8
lea    -0x134(%rbp),%rdx
mov    $0x4,%ecx
mov    $0x100,%r9d
call   1060 <calculate_hmac_sha512@plt>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x100,%esi
call   1030 <get_truncate@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_totp_sha512>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %edx,%edi
call   1050 <htobe64@plt>
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%ecx
mov    %r13,%r8
mov    $0x100,%r9d
call   1060 <calculate_hmac_sha512@plt>
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <get_truncate@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_totp_sha512(i32* %0, i64 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [64 x i32]
%12 = alloca i32
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%13 = load i32, i32* %8
%14 = call i32 @htobe64(i32 %13)
store i32 %14, i32* %12
%15 = getelementptr inbounds [64 x i32], [64 x i32]* %11, i64 0, i64 0
%16 = call i32 @memset(i32* %15, i32 0, i32 256)
%17 = load i32*, i32** %6
%18 = load i64, i64* %7
%19 = getelementptr inbounds [64 x i32], [64 x i32]* %11, i64 0, i64 0
%20 = call i32 @calculate_hmac_sha512(i32* %17, i64 %18, i32* %12, i32 4, i32* %19, i32 256)
%21 = getelementptr inbounds [64 x i32], [64 x i32]* %11, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = load i64, i64* %10
%24 = call i32 @get_truncate(i32* %21, i32 256, i8* %22, i64 %23)
ret i32 %24
}

LLVM IR (-O2):
define i32 @get_totp_sha512(i32* %0, i64 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca [64 x i32]
%7 = alloca i32
%8 = bitcast [64 x i32]* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = tail call i32 @htobe64(i32 %2)
store i32 %10, i32* %7
%11 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%12 = call i32 @memset(i32* %11, i32 0, i32 256)
%13 = call i32 @calculate_hmac_sha512(i32* %0, i64 %1, i32* %7, i32 4, i32* %11, i32 256)
%14 = call i32 @get_truncate(i32* %11, i32 256, i8* %3, i64 %4)
ret i32 %14
}