#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 scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ hmac_sha1(unsigned char *, int /*<<< orphan*/, unsigned char *,
                     int /*<<< orphan*/, unsigned char **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main() {
  char *data = "Hello World!";
  char *key = "foobar";
  unsigned char digest[20];
  ssize_t len = hmac_sha1((unsigned char *)data, strlen(data),
                          (unsigned char *)key, strlen(key), &digest, 4);
  if (len < 0) {
    printf("Failed to compute hmac! (err=%d)\n");
    return len;
  }
  for (int i = 0; i < len; i++)
    printf("%02x", digest[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xebc(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    $0x4,%r9d
call   1050 <hmac_sha1@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    11bf <main+0x8f>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    120e <main+0xde>
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    11f9 <main+0xc9>
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c6 <main+0x96>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xeb1(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xead(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    $0x4,%r9d
call   1060 <hmac_sha1@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11c5 <main+0x85>
je     11b7 <main+0x77>
lea    0xea5(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rsp,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11a0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
jmp    11d3 <main+0x93>
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Hello World!\00"
@.str.1 = [7 x i8] c"foobar\00"
@.str.2 = [34 x i8] c"Failed to compute hmac! (err=%d)\0A\00"
@.str.3 = [5 x i8] c"%02x\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = bitcast [20 x i8]* %4 to i8**
%14 = call i64 @hmac_sha1(i8* %7, i32 %9, i8* %10, i32 %12, i8** %13, i32 4)
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%19 = load i64, i64* %5
%20 = trunc i64 %19 to i32
store i32 %20, i32* %1
br label %39
21: ; preds = %0
store i32 0, i32* %6
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = load i64, i64* %5
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %22
37: ; preds = %22
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %39
39: ; preds = %37, %17
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello World!\00"
@.str.1 = [7 x i8] c"foobar\00"
@.str.2 = [34 x i8] c"Failed to compute hmac! (err=%d)\0A\00"
@.str.3 = [5 x i8] c"%02x\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast [20 x i8]* %1 to i8**
%6 = call i64 @hmac_sha1(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %4, i8** %5, i32 4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = icmp eq i64 %6, 0
br i1 %9, label %13, label %15
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%12 = trunc i64 %6 to i32
br label %23
13: ; preds = %15, %8
%14 = call i32 @putchar(i32 10)
br label %23
15: ; preds = %8, %15
%16 = phi i64 [ %21, %15 ], [ 0, %8 ]
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %13, label %15
23: ; preds = %13, %10
%24 = phi i32 [ %12, %10 ], [ 0, %13 ]
ret i32 %24
}