#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 */

/* Variables and functions */
int /*<<< orphan*/ EVP_sha256();
unsigned char *HMAC(int /*<<< orphan*/, unsigned char *, unsigned int,
                    unsigned char const *, int, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ read_whole_file(char *, unsigned char **, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  unsigned char *key;
  unsigned int key_l, i;
  char data[2 * SHA256_DIGEST_LENGTH + 2],
      hmac_text[2 * SHA256_DIGEST_LENGTH + 1];
  unsigned char *hmac;
  read_whole_file(argv[1], &key, &key_l);
  while (!feof(stdin)) {
    if (!fgets(data, 2 * SHA256_DIGEST_LENGTH + 2, stdin))
      break;
    data[2 * SHA256_DIGEST_LENGTH] = '\0';
    hmac = HMAC(EVP_sha256(), key, key_l, (unsigned char const *)data,
                2 * SHA256_DIGEST_LENGTH, NULL, NULL);
    for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
      sprintf(&hmac_text[2 * i], "%02hhx", hmac[i]);
    printf("%s %s\n", hmac_text, data);
  }
  if (ferror(stdin)) {
    perror("stdin");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    %edx,%ecx
lea    0x2(%rcx,%rcx,1),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <read_whole_file@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1234 <main+0xa4>
jmp    1320 <main+0x190>
mov    -0x58(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
shl    $0x1,%esi
add    $0x2,%esi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    1263 <main+0xd3>
jmp    1320 <main+0x190>
mov    -0x58(%rbp),%rax
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   10b0 <EVP_sha256@plt>
mov    -0x58(%rbp),%rcx
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    0x2d43(%rip),%rax
mov    (%rax),%r8d
shl    $0x1,%r8d
xor    %eax,%eax
mov    %eax,%r9d
sub    $0x10,%rsp
movq   $0x0,(%rsp)
call   1080 <HMAC@plt>
add    $0x10,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2d0d(%rip),%rcx
cmp    (%rcx),%eax
jae    1307 <main+0x177>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%ecx
lea    0xd10(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12c1 <main+0x131>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rsi
lea    0xcf1(%rip),%rdi
call   1040 <printf@plt>
jmp    1211 <main+0x81>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1357 <main+0x1c7>
lea    0xccf(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1365 <main+0x1d5>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,-0x38(%rbp)
mov    0x2e2c(%rip),%r14
mov    (%r14),%eax
add    %eax,%eax
add    $0x2,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    (%r14),%eax
add    %eax,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    0x8(%rsi),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <read_whole_file@plt>
mov    0x2df2(%rip),%rbx
mov    (%rbx),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1229 <main+0x99>
mov    (%rbx),%edi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1301 <main+0x171>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,-0x40(%rbp)
jmp    125f <main+0xcf>
nop
lea    0xdd0(%rip),%rdi
mov    %r12,%rsi
mov    -0x40(%rbp),%r15
mov    %r15,%rdx
call   1040 <printf@plt>
mov    0x2d9b(%rip),%rbx
mov    (%rbx),%edi
call   1070 <feof@plt>
test   %eax,%eax
mov    0x2d7b(%rip),%r14
jne    1201 <main+0x71>
mov    (%r14),%eax
lea    (%rax,%rax,1),%esi
add    $0x2,%esi
mov    (%rbx),%edx
mov    %r15,%rdi
call   1060 <fgets@plt>
test   %eax,%eax
je     1201 <main+0x71>
movslq (%r14),%rax
movb   $0x0,(%r15,%rax,2)
xor    %eax,%eax
call   10b0 <EVP_sha256@plt>
mov    -0x48(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    (%r14),%r8d
add    %r8d,%r8d
sub    $0x8,%rsp
mov    %eax,%edi
mov    %r15,%rcx
xor    %r9d,%r9d
push   $0x0
call   1080 <HMAC@plt>
add    $0x10,%rsp
cmpl   $0x0,(%r14)
lea    0xd4c(%rip),%r13
je     1230 <main+0xa0>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%edi
and    $0xfffffffe,%edi
add    %r12,%rdi
movzbl (%rbx,%r15,1),%edx
mov    %r13,%rsi
call   10a0 <sprintf@plt>
add    $0x1,%r15
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
add    $0x2,%r14
cmp    %rax,%r15
jb     12d0 <main+0x140>
jmp    1230 <main+0xa0>
lea    0xd06(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    1216 <main+0x86>

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
@stdin = global i32 0
@.str = [7 x i8] c"%02hhx\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @SHA256_DIGEST_LENGTH
%15 = mul nsw i32 2, %14
%16 = add nsw i32 %15, 2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %9
%19 = alloca i8, i64 %17
store i64 %17, i64* %10
%20 = load i32, i32* @SHA256_DIGEST_LENGTH
%21 = mul nsw i32 2, %20
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %11
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @read_whole_file(i8* %27, i8** %6, i32* %7)
br label %29
29: ; preds = %71, %2
%30 = load i32, i32* @stdin
%31 = call i32 @feof(i32 %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %73
34: ; preds = %29
%35 = load i32, i32* @SHA256_DIGEST_LENGTH
%36 = mul nsw i32 2, %35
%37 = add nsw i32 %36, 2
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %19, i32 %37, i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %34
br label %73
42: ; preds = %34
%43 = load i32, i32* @SHA256_DIGEST_LENGTH
%44 = mul nsw i32 2, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %19, i64 %45
store i8 0, i8* %46
%47 = call i32 (...) @EVP_sha256()
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = load i32, i32* @SHA256_DIGEST_LENGTH
%51 = mul nsw i32 2, %50
%52 = call i8* @HMAC(i32 %47, i8* %48, i32 %49, i8* %19, i32 %51, i32* null, i32* null)
store i8* %52, i8** %12
store i32 0, i32* %8
br label %53
53: ; preds = %68, %42
%54 = load i32, i32* %8
%55 = load i32, i32* @SHA256_DIGEST_LENGTH
%56 = icmp ult i32 %54, %55
br i1 %56, label %57, label %71
57: ; preds = %53
%58 = load i32, i32* %8
%59 = mul i32 2, %58
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %24, i64 %60
%62 = load i8*, i8** %12
%63 = load i32, i32* %8
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %66)
br label %68
68: ; preds = %57
%69 = load i32, i32* %8
%70 = add i32 %69, 1
store i32 %70, i32* %8
br label %53
71: ; preds = %53
%72 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %19)
br label %29
73: ; preds = %41, %29
%74 = load i32, i32* @stdin
%75 = call i64 @ferror(i32 %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %13
br label %80
79: ; preds = %73
store i32 0, i32* %3
store i32 1, i32* %13
br label %80
80: ; preds = %79, %77
%81 = load i8*, i8** %9
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@stdin = global i32 0
@.str = [7 x i8] c"%02hhx\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @SHA256_DIGEST_LENGTH
%8 = shl nsw i32 %7, 1
%9 = add nsw i32 %8, 2
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = load i32, i32* @SHA256_DIGEST_LENGTH
%14 = shl nsw i32 %13, 1
%15 = or i32 %14, 1
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @read_whole_file(i8* %19, i8** %3, i32* %4)
%21 = load i32, i32* @stdin
%22 = call i32 @feof(i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %61
24: ; preds = %2, %56
%25 = load i32, i32* @SHA256_DIGEST_LENGTH
%26 = shl nsw i32 %25, 1
%27 = add nsw i32 %26, 2
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %12, i32 %27, i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %61, label %31
31: ; preds = %24
%32 = load i32, i32* @SHA256_DIGEST_LENGTH
%33 = shl nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %12, i64 %34
store i8 0, i8* %35
%36 = call i32 (...) @EVP_sha256()
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = load i32, i32* @SHA256_DIGEST_LENGTH
%40 = shl nsw i32 %39, 1
%41 = call i8* @HMAC(i32 %36, i8* %37, i32 %38, i8* %12, i32 %40, i32* null, i32* null)
%42 = load i32, i32* @SHA256_DIGEST_LENGTH
%43 = icmp eq i32 %42, 0
br i1 %43, label %56, label %44
44: ; preds = %31, %44
%45 = phi i64 [ %52, %44 ], [ 0, %31 ]
%46 = shl nuw i64 %45, 1
%47 = and i64 %46, 4294967294
%48 = getelementptr inbounds i8, i8* %17, i64 %47
%49 = getelementptr inbounds i8, i8* %41, i64 %45
%50 = load i8, i8* %49
%51 = call i32 @sprintf(i8* %48, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %50)
%52 = add nuw nsw i64 %45, 1
%53 = load i32, i32* @SHA256_DIGEST_LENGTH
%54 = zext i32 %53 to i64
%55 = icmp ult i64 %52, %54
br i1 %55, label %44, label %56
56: ; preds = %44, %31
%57 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %12)
%58 = load i32, i32* @stdin
%59 = call i32 @feof(i32 %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %24, label %61
61: ; preds = %56, %24, %2
%62 = load i32, i32* @stdin
%63 = call i64 @ferror(i32 %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %61, %65
%68 = phi i32 [ -1, %65 ], [ 0, %61 ]
ret i32 %68
}