#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*/ hex;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ hmac_sha1(char *, int, char *, int, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tohex(char *, int, char *, int);
void check(char *k, int klen, char *text, int textlen, char *digst) {
  char buff[20];
  char hex[41];
  hmac_sha1(k, klen, text, textlen, buff, sizeof(buff));
  tohex(buff, sizeof(buff), hex, sizeof(hex));
  hex[sizeof(hex) - 1] = '\0';
  if (strcmp(digst, hex) != 0) {
    printf("sha1 cannot pass digst: %s, sha1: %s\n", digst, hex);
    return;
  }
  printf("sha1 pass digst: %s, sha1: %s\n", digst, hex);
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x40(%rbp),%r8
mov    $0x14,%r9d
call   1050 <hmac_sha1@plt>
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    $0x14,%esi
mov    $0x29,%ecx
call   1060 <tohex@plt>
movb   $0x0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11c2 <check+0x82>
mov    -0x28(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11d6 <check+0x96>
mov    -0x28(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %r8,%rbx
mov    %rsp,%r14
mov    %r14,%r8
mov    $0x14,%r9d
call   1050 <hmac_sha1@plt>
lea    0x20(%rsp),%r15
mov    %r14,%rdi
mov    $0x14,%esi
mov    %r15,%rdx
mov    $0x29,%ecx
call   1060 <tohex@plt>
movb   $0x0,0x48(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
lea    0xe95(%rip),%rax
lea    0xe68(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"sha1 cannot pass digst: %s, sha1: %s\0A\00"
@.str.1 = [31 x i8] c"sha1 pass digst: %s, sha1: %s\0A\00"
define void @check(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [20 x i8]
%12 = alloca [41 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%18 = call i32 @hmac_sha1(i8* %13, i32 %14, i8* %15, i32 %16, i8* %17, i32 20)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%20 = getelementptr inbounds [41 x i8], [41 x i8]* %12, i64 0, i64 0
%21 = call i32 @tohex(i8* %19, i32 20, i8* %20, i32 41)
%22 = getelementptr inbounds [41 x i8], [41 x i8]* %12, i64 0, i64 40
store i8 0, i8* %22
%23 = load i8*, i8** %10
%24 = getelementptr inbounds [41 x i8], [41 x i8]* %12, i64 0, i64 0
%25 = call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %5
%28 = load i8*, i8** %10
%29 = getelementptr inbounds [41 x i8], [41 x i8]* %12, i64 0, i64 0
%30 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
br label %35
31: ; preds = %5
%32 = load i8*, i8** %10
%33 = getelementptr inbounds [41 x i8], [41 x i8]* %12, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33)
br label %35
35: ; preds = %31, %27
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"sha1 cannot pass digst: %s, sha1: %s\0A\00"
@.str.1 = [31 x i8] c"sha1 pass digst: %s, sha1: %s\0A\00"
define void @check(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca [20 x i8]
%7 = alloca [41 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%10 = call i32 @hmac_sha1(i8* %0, i32 %1, i8* %2, i32 %3, i8* %8, i32 20)
%11 = call i32 @tohex(i8* %8, i32 20, i8* %9, i32 41)
%12 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 40
store i8 0, i8* %12
%13 = call i64 @strcmp(i8* %4, i8* %9)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0)
%16 = call i32 @printf(i8* %15, i8* %4, i8* %9)
ret void
}