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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_totp_sha512(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   unsigned int const, char *, int);
scalar_t__ is_valid(int /*<<< orphan*/ *, int /*<<< orphan*/,
                    unsigned int const, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int run_valid_tests() {
  int i;
  const unsigned j = 1 * 2;
  char buffer[9];
  int valid = 0;
  for (i = -0; i <= 1; ++i, valid = 0) {
    get_totp_sha512(
        (uint8_t *)"12345678901234567890123456789012345678901234567890123456789"
                   "01234",
        strlen(
            "1234567890123456789012345678901234567890123456789012345678901234"),
        j - i, buffer, sizeof(buffer));
    if (is_valid((uint8_t *)"12345678901234567890123456789012345678901234567890"
                            "12345678901234",
                 strlen("123456789012345678901234567890123456789012345678901234"
                        "5678901234"),
                 j, buffer))
      valid = 1;
    if (!valid) {
      fprintf(stderr, "Did not validate totp in window\n");
      return 0;
    }
  }
  fprintf(stdout, "Validates all in window\n");
  get_totp_sha512(
      (uint8_t
           *)"1234567890123456789012345678901234567890123456789012345678901234",
      strlen(
          "1234567890123456789012345678901234567890123456789012345678901234"),
      j - i, buffer, sizeof(buffer));
  if (is_valid((uint8_t *)"1234567890123456789012345678901234567890123456789012"
                          "345678901234",
               strlen("12345678901234567890123456789012345678901234567890123456"
                      "78901234"),
               j, buffer)) {
    fprintf(stderr, "Validated totp before window\n");
    return 0;
  }
  fprintf(stdout, "Does not validate before window\n");
  get_totp_sha512(
      (uint8_t
           *)"1234567890123456789012345678901234567890123456789012345678901234",
      strlen(
          "1234567890123456789012345678901234567890123456789012345678901234"),
      j + 0 + 1, buffer, sizeof(buffer));
  if (is_valid((uint8_t *)"1234567890123456789012345678901234567890123456789012"
                          "345678901234",
               strlen("12345678901234567890123456789012345678901234567890123456"
                      "78901234"),
               j, buffer)) {
    fprintf(stderr, "Validated totp after window\n");
    return 0;
  }
  fprintf(stdout, "Validates only in window\n");
  return 1;
}


x86 assembly (clang, -O0):
<run_valid_tests>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     120c <run_valid_tests+0xcc>
lea    0xe92(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    $0x2,%edx
sub    -0x8(%rbp),%edx
lea    -0x15(%rbp),%rcx
lea    0xe78(%rip),%rdi
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
lea    0xe66(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x15(%rbp),%rcx
lea    0xe54(%rip),%rdi
mov    $0x2,%edx
call   1060 <is_valid@plt>
cmp    $0x0,%rax
je     11c7 <run_valid_tests+0x87>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f2 <run_valid_tests+0xb2>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <run_valid_tests+0x203>
jmp    11f7 <run_valid_tests+0xb7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    115d <run_valid_tests+0x1d>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xdd8(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    $0x2,%edx
sub    -0x8(%rbp),%edx
lea    -0x15(%rbp),%rcx
lea    0xdbe(%rip),%rdi
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
lea    0xdac(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x15(%rbp),%rcx
lea    0xd9a(%rip),%rdi
mov    $0x2,%edx
call   1060 <is_valid@plt>
cmp    $0x0,%rax
je     129b <run_valid_tests+0x15b>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <run_valid_tests+0x203>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xd49(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x15(%rbp),%rcx
lea    0xd37(%rip),%rdi
mov    $0x3,%edx
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
lea    0xd20(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x15(%rbp),%rcx
lea    0xd0e(%rip),%rdi
mov    $0x2,%edx
call   1060 <is_valid@plt>
cmp    $0x0,%rax
je     1327 <run_valid_tests+0x1e7>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <run_valid_tests+0x203>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_valid_tests>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x7(%rsp),%rbp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
mov    %rbp,%rcx
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
mov    %rbp,%rcx
call   1060 <is_valid@plt>
xor    %r14d,%r14d
lea    0xea5(%rip),%rbx
mov    0x2e3d(%rip),%r12
test   %rax,%rax
je     12e1 <run_valid_tests+0x1a1>
lea    0xe4d(%rip),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x7(%rsp),%r15
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x2,%edx
mov    %r15,%rcx
call   1060 <is_valid@plt>
test   %rax,%rax
je     12e1 <run_valid_tests+0x1a1>
mov    0x2dd6(%rip),%r15
mov    (%r15),%edi
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xde8(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
lea    0x7(%rsp),%rbp
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %rbp,%rcx
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
mov    %rbp,%rcx
call   1060 <is_valid@plt>
test   %rax,%rax
je     1265 <run_valid_tests+0x125>
lea    0xe18(%rip),%rbx
jmp    12e1 <run_valid_tests+0x1a1>
mov    (%r15),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xd85(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x7(%rsp),%rbp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
mov    %rbp,%rcx
mov    $0x9,%r8d
call   1050 <get_totp_sha512@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
mov    %rbp,%rcx
call   1060 <is_valid@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
cmovne 0x2d14(%rip),%r15
lea    0xe04(%rip),%rax
lea    0xde0(%rip),%rbx
cmove  %rax,%rbx
mov    %r15,%r12
mov    (%r12),%edi
mov    %rbx,%rsi
call   1040 <fprintf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"1234567890123456789012345678901234567890123456789012345678901234\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Did not validate totp in window\0A\00"
@stdout = global i32 0
@.str.2 = [25 x i8] c"Validates all in window\0A\00"
@.str.3 = [30 x i8] c"Validated totp before window\0A\00"
@.str.4 = [33 x i8] c"Does not validate before window\0A\00"
@.str.5 = [29 x i8] c"Validated totp after window\0A\00"
@.str.6 = [26 x i8] c"Validates only in window\0A\00"
define i32 @run_valid_tests() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [9 x i8]
%5 = alloca i32
store i32 2, i32* %3
store i32 0, i32* %5
store i32 0, i32* %2
br label %6
6: ; preds = %27, %0
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = sub i32 2, %11
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%14 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %10, i32 %12, i8* %13, i32 9)
%15 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%17 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %15, i32 2, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %9
store i32 1, i32* %5
br label %20
20: ; preds = %19, %9
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %61
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
store i32 0, i32* %5
br label %6
30: ; preds = %6
%31 = load i32, i32* @stdout
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* %2
%35 = sub i32 2, %34
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%37 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %33, i32 %35, i8* %36, i32 9)
%38 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%39 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%40 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %38, i32 2, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %30
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %61
45: ; preds = %30
%46 = load i32, i32* @stdout
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%49 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%50 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %48, i32 3, i8* %49, i32 9)
%51 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%52 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%53 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %51, i32 2, i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %45
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %61
58: ; preds = %45
%59 = load i32, i32* @stdout
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %61
61: ; preds = %58, %55, %42, %23
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [65 x i8] c"1234567890123456789012345678901234567890123456789012345678901234\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Did not validate totp in window\0A\00"
@stdout = global i32 0
@.str.2 = [25 x i8] c"Validates all in window\0A\00"
@.str.3 = [30 x i8] c"Validated totp before window\0A\00"
@.str.4 = [33 x i8] c"Does not validate before window\0A\00"
@.str.5 = [29 x i8] c"Validated totp after window\0A\00"
@.str.6 = [26 x i8] c"Validates only in window\0A\00"
define i32 @run_valid_tests() {
%1 = alloca [9 x i8]
%2 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %3, i32 2, i8* %2, i32 9)
%5 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %5, i32 2, i8* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %0
%9 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %9, i32 1, i8* %2, i32 9)
%11 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %11, i32 2, i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %33, label %14
14: ; preds = %8
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %17, i32 0, i8* %2, i32 9)
%19 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%20 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %19, i32 2, i8* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %14
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @get_totp_sha512(i32* bitcast ([65 x i8]* @.str to i32*), i32 %25, i32 3, i8* %2, i32 9)
%27 = call i32 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%28 = call i64 @is_valid(i32* bitcast ([65 x i8]* @.str to i32*), i32 %27, i32 2, i8* %2)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i32* @stdout, i32* @stderr
%31 = select i1 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0)
%32 = zext i1 %29 to i32
br label %33
33: ; preds = %22, %14, %0, %8
%34 = phi i32* [ @stderr, %8 ], [ @stderr, %0 ], [ @stderr, %14 ], [ %30, %22 ]
%35 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %14 ], [ %31, %22 ]
%36 = phi i32 [ 0, %8 ], [ 0, %0 ], [ 0, %14 ], [ %32, %22 ]
%37 = load i32, i32* %34
%38 = call i32 @fprintf(i32 %37, i8* %35)
ret i32 %36
}