#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 long uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EVP_sha1();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/, unsigned char *, int,
                        unsigned char *, int, unsigned char *, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, long);
void hotp(unsigned char challenge[], unsigned char keyblock[], int keylen,
          unsigned char response[]) {
  uint32_t dbc;
  unsigned char md[20];
  unsigned md_len;
  (void)HMAC(EVP_sha1(), keyblock, keylen, challenge, 8, md, &md_len);
  {
    int offset;
    offset = md[19] & 0x0F;
    dbc = (md[offset] & 0x7F) << 24 | md[offset + 1] << 16 |
          md[offset + 2] << 8 | md[offset + 3];
  }
  (void)sprintf((char *)response, "%06lu", dbc % 1000000L);
}


x86 assembly (clang, -O0):
<hotp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <EVP_sha1@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    -0x40(%rbp),%r9
mov    $0x8,%r8d
lea    -0x44(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <HMAC@plt>
movzbl -0x2d(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x48(%rbp)
movslq -0x48(%rbp),%rax
movzbl -0x40(%rbp,%rax,1),%eax
and    $0x7f,%eax
shl    $0x18,%eax
mov    -0x48(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x48(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x48(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movzbl -0x40(%rbp,%rcx,1),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
lea    0xe20(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hotp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <EVP_sha1@plt>
lea    0xc(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
mov    $0x8,%r8d
mov    %rbx,%r9
call   1040 <HMAC@plt>
movzbl 0x23(%rsp),%eax
and    $0xf,%eax
movzbl (%rax,%rbx,1),%ecx
and    $0x7f,%ecx
shl    $0x18,%rcx
movzbl 0x1(%rax,%rbx,1),%edx
shl    $0x10,%rdx
or     %rcx,%rdx
movzbl 0x2(%rax,%rbx,1),%ecx
shl    $0x8,%rcx
or     %rdx,%rcx
movzbl 0x3(%rax,%rbx,1),%edx
or     %rcx,%rdx
imul   $0x431bde83,%rdx,%rax
shr    $0x32,%rax
imul   $0xf4240,%eax,%eax
sub    %eax,%edx
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%06lu\00"
define void @hotp(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [20 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = call i32 (...) @EVP_sha1()
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%18 = call i32 @HMAC(i32 %13, i8* %14, i32 %15, i8* %16, i32 8, i8* %17, i32* %11)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 19
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 15
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 %27, 127
%29 = shl i32 %28, 24
%30 = load i32, i32* %12
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = shl i32 %35, 16
%37 = or i32 %29, %36
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = shl i32 %43, 8
%45 = or i32 %37, %44
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = or i32 %45, %51
%53 = sext i32 %52 to i64
store i64 %53, i64* %9
%54 = load i8*, i8** %8
%55 = load i64, i64* %9
%56 = srem i64 %55, 1000000
%57 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %56)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%06lu\00"
define void @hotp(i8* %0, i8* %1, i32 %2, i8* nocapture writeonly %3) {
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = bitcast i32* %6 to i8*
%9 = tail call i32 (...) @EVP_sha1()
%10 = call i32 @HMAC(i32 %9, i8* %1, i32 %2, i8* %0, i32 8, i8* %7, i32* %6)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 19
%12 = load i8, i8* %11
%13 = and i8 %12, 15
%14 = zext i8 %13 to i32
%15 = zext i8 %13 to i64
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = and i8 %17, 127
%19 = zext i8 %18 to i64
%20 = shl nuw nsw i64 %19, 24
%21 = add nuw nsw i32 %14, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i64
%26 = shl nuw nsw i64 %25, 16
%27 = or i64 %20, %26
%28 = add nuw nsw i32 %14, 2
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i64
%33 = shl nuw nsw i64 %32, 8
%34 = or i64 %27, %33
%35 = add nuw nsw i32 %14, 3
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i64
%40 = or i64 %34, %39
%41 = urem i64 %40, 1000000
%42 = call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %41)
ret void
}