#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_sha1(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_sha1(const uint8_t *hashdata, size_t len, uint64_t time, char *dst,
                  size_t maxlen) {
  uint8_t buffer[20];
  uint64_t counter = htobe64(time);
  memset(buffer, 0, sizeof(buffer));
  calculate_hmac_sha1(hashdata, len, (uint8_t *)&counter, sizeof(counter),
                      buffer, sizeof(buffer));
  return get_truncate(buffer, sizeof(buffer), dst, maxlen);
}


x86 assembly (clang, -O0):
<get_totp_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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   1060 <htobe64@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x80(%rbp),%r8
lea    -0x84(%rbp),%rdx
mov    $0x4,%ecx
mov    $0x50,%r9d
call   1050 <calculate_hmac_sha1@plt>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x50,%esi
call   1030 <get_truncate@plt>
add    $0x90,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @get_totp_sha1(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 [20 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 [20 x i32], [20 x i32]* %11, i64 0, i64 0
%16 = call i32 @memset(i32* %15, i32 0, i32 80)
%17 = load i32*, i32** %6
%18 = load i64, i64* %7
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %11, i64 0, i64 0
%20 = call i32 @calculate_hmac_sha1(i32* %17, i64 %18, i32* %12, i32 4, i32* %19, i32 80)
%21 = getelementptr inbounds [20 x i32], [20 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 80, i8* %22, i64 %23)
ret i32 %24
}

LLVM IR (-O2):
define i32 @get_totp_sha1(i32* %0, i64 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca [20 x i32]
%7 = alloca i32
%8 = bitcast [20 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 [20 x i32], [20 x i32]* %6, i64 0, i64 0
%12 = call i32 @memset(i32* %11, i32 0, i32 80)
%13 = call i32 @calculate_hmac_sha1(i32* %0, i64 %1, i32* %7, i32 4, i32* %11, i32 80)
%14 = call i32 @get_truncate(i32* %11, i32 80, i8* %3, i64 %4)
ret i32 %14
}