#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__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int do_noop_min();
scalar_t__ do_test(char *, int, char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ siphash24(char *, int, char *);
scalar_t__ siphash24_asm(char *, int, char *);
int strlen(char *);
int main() {
  char key[16] = {0};
  uint64_t out1, out2;
  char *vector = "abcdefghabcdefghabcdefghabcdefgh";
  int vector_sz = strlen(vector);
  out1 = siphash24(vector, vector_sz, key);
  out2 = siphash24_asm(vector, vector_sz, key);
  printf("%016llx\n", out1);
  printf("%016llx\n", out2);
  assert(out1 == out2);
  int i;
  for (i = 0; i < 10000000; i++) {
    out1 = siphash24(vector, vector_sz, key);
    out1 = siphash24_asm(vector, vector_sz, key);
  }
  int noop_min = do_noop_min();
  printf("[+] empty run: %i cycles\n", noop_min);
  int sz = 0;
  for (; sz <= vector_sz; sz++) {
    out1 = siphash24(vector, sz, key);
    out2 = siphash24_asm(vector, sz, key);
    assert(out1 == out2);
    int retry;
    for (retry = 0; retry < 100; retry += 1)
      if (do_test(vector, sz, key, noop_min) != 0)
        break;
    if (retry == 100) {
      printf("FAILED!\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    0xe4a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <siphash24@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <siphash24_asm@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x40(%rbp)
cmpl   $0x989680,-0x40(%rbp)
jge    1271 <main+0xe1>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <siphash24@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <siphash24_asm@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    122e <main+0x9e>
mov    $0x0,%al
call   10a0 <do_noop_min@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jg     1357 <main+0x1c7>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <siphash24@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <siphash24_asm@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x64,-0x4c(%rbp)
jge    1322 <main+0x192>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    -0x44(%rbp),%ecx
call   1090 <do_test@plt>
cmp    $0x0,%rax
je     130f <main+0x17f>
jmp    1322 <main+0x192>
jmp    1314 <main+0x184>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    12e3 <main+0x153>
cmpl   $0x64,-0x4c(%rbp)
jne    1344 <main+0x1b4>
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1349 <main+0x1b9>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1293 <main+0x103>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe53(%rip),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <siphash24@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1050 <siphash24_asm@plt>
mov    %rax,%r12
lea    0xe3e(%rip),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
cmp    %r12,%r15
sete   %dil
call   1080 <assert@plt>
mov    $0x989680,%ebx
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <siphash24@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1050 <siphash24_asm@plt>
add    $0xffffffff,%ebx
jne    1210 <main+0x80>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <do_noop_min@plt>
mov    %eax,%r14d
lea    0xde8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,0xc(%rsp)
test   %ebp,%ebp
js     12e0 <main+0x150>
lea    0xda2(%rip),%r15
lea    0x10(%rsp),%r12
jmp    127b <main+0xeb>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
je     12e0 <main+0x150>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1030 <siphash24@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1050 <siphash24_asm@plt>
xor    %edi,%edi
cmp    %rax,%r13
sete   %dil
call   1080 <assert@plt>
mov    $0x64,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1090 <do_test@plt>
test   %rax,%rax
jne    1270 <main+0xe0>
add    $0xffffffff,%ebp
jne    12b0 <main+0x120>
lea    0xd73(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"abcdefghabcdefghabcdefghabcdefgh\00"
@.str.1 = [9 x i8] c"%016llx\0A\00"
@.str.2 = [26 x i8] c"[+] empty run: %i cycles\0A\00"
@.str.3 = [9 x i8] c"FAILED!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [16 x i8]* %2 to i8*
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%17 = call i64 @siphash24(i8* %14, i32 %15, i8* %16)
store i64 %17, i64* %3
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%21 = call i64 @siphash24_asm(i8* %18, i32 %19, i8* %20)
store i64 %21, i64* %4
%22 = load i64, i64* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = load i64, i64* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %3
%27 = load i64, i64* %4
%28 = icmp eq i64 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
store i32 0, i32* %7
br label %31
31: ; preds = %43, %0
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 10000000
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i8*, i8** %5
%36 = load i32, i32* %6
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%38 = call i64 @siphash24(i8* %35, i32 %36, i8* %37)
store i64 %38, i64* %3
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%42 = call i64 @siphash24_asm(i8* %39, i32 %40, i8* %41)
store i64 %42, i64* %3
br label %43
43: ; preds = %34
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %31
46: ; preds = %31
%47 = call i32 (...) @do_noop_min()
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 0, i32* %9
br label %50
50: ; preds = %90, %46
%51 = load i32, i32* %9
%52 = load i32, i32* %6
%53 = icmp sle i32 %51, %52
br i1 %53, label %54, label %93
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = load i32, i32* %9
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%58 = call i64 @siphash24(i8* %55, i32 %56, i8* %57)
store i64 %58, i64* %3
%59 = load i8*, i8** %5
%60 = load i32, i32* %9
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%62 = call i64 @siphash24_asm(i8* %59, i32 %60, i8* %61)
store i64 %62, i64* %4
%63 = load i64, i64* %3
%64 = load i64, i64* %4
%65 = icmp eq i64 %63, %64
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
store i32 0, i32* %10
br label %68
68: ; preds = %80, %54
%69 = load i32, i32* %10
%70 = icmp slt i32 %69, 100
br i1 %70, label %71, label %83
71: ; preds = %68
%72 = load i8*, i8** %5
%73 = load i32, i32* %9
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%75 = load i32, i32* %8
%76 = call i64 @do_test(i8* %72, i32 %73, i8* %74, i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %71
br label %83
79: ; preds = %71
br label %80
80: ; preds = %79
%81 = load i32, i32* %10
%82 = add nsw i32 %81, 1
store i32 %82, i32* %10
br label %68
83: ; preds = %78, %68
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 100
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %83
br label %90
90: ; preds = %89
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
store i32 %92, i32* %9
br label %50
93: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"abcdefghabcdefghabcdefghabcdefgh\00"
@.str.1 = [9 x i8] c"%016llx\0A\00"
@.str.2 = [26 x i8] c"[+] empty run: %i cycles\0A\00"
@str = [8 x i8] c"FAILED!\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @siphash24(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2)
%5 = call i64 @siphash24_asm(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%8 = icmp eq i64 %4, %5
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
br label %11
11: ; preds = %0, %11
%12 = phi i32 [ 0, %0 ], [ %15, %11 ]
%13 = call i64 @siphash24(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2)
%14 = call i64 @siphash24_asm(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2)
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, 10000000
br i1 %16, label %17, label %11
17: ; preds = %11
%18 = call i32 (...) @do_noop_min()
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %3, 0
br i1 %20, label %41, label %21
21: ; preds = %17, %38
%22 = phi i32 [ %39, %38 ], [ 0, %17 ]
%23 = call i64 @siphash24(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %2)
%24 = call i64 @siphash24_asm(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %2)
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
br label %28
28: ; preds = %21, %32
%29 = phi i32 [ 0, %21 ], [ %33, %32 ]
%30 = call i64 @do_test(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %2, i32 %18)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = add nuw nsw i32 %29, 1
%34 = icmp eq i32 %33, 100
br i1 %34, label %35, label %28
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = add nuw i32 %22, 1
%40 = icmp eq i32 %22, %3
br i1 %40, label %41, label %21
41: ; preds = %38, %17
ret i32 0
}