; LLVM IR from openssl/openssl :: crypto/siphash (siphash)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.siphash_st = type { i64, i64, i64, i64, i64, i32, i32, i32, i32, [8 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @SipHash_set_hash_size(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %7 = call i64 @siphash_adjust_hash_size(i64 noundef %6)
  store i64 %7, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = icmp ne i64 %8, 8
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ne i64 %11, 16
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i32 0, ptr %3, align 4
  br label %39

14:                                               ; preds = %10, %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.siphash_st, ptr %15, i32 0, i32 6
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = call i64 @siphash_adjust_hash_size(i64 noundef %18)
  %20 = trunc i64 %19 to i32
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.siphash_st, ptr %21, i32 0, i32 6
  store i32 %20, ptr %22, align 4, !tbaa !11
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.siphash_st, ptr %23, i32 0, i32 6
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = icmp ne i64 %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %14
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.siphash_st, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = xor i64 %32, 238
  store i64 %33, ptr %31, align 8, !tbaa !14
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.siphash_st, ptr %36, i32 0, i32 6
  store i32 %35, ptr %37, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %29, %14
  store i32 1, ptr %3, align 4
  br label %39

39:                                               ; preds = %38, %13
  %40 = load i32, ptr %3, align 4
  ret i32 %40
}

; Function Attrs: nounwind uwtable
declare hidden i64 @siphash_adjust_hash_size(i64 noundef) #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 44}
!12 = !{!"siphash_st", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !7, i64 56}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @SipHash_set_hash_size(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @siphash_adjust_hash_size(i64 noundef %1)
  switch i64 %3, label %16 [
    i64 16, label %4
    i64 8, label %4
  ]

4:                                                ; preds = %2, %2
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = tail call i64 @siphash_adjust_hash_size(i64 noundef %7)
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr %5, align 4, !tbaa !5
  %10 = and i64 %8, 4294967295
  %.not = icmp eq i64 %10, %3
  br i1 %.not, label %16, label %11

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = xor i64 %13, 238
  store i64 %14, ptr %12, align 8, !tbaa !11
  %15 = trunc nuw i64 %3 to i32
  store i32 %15, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %4, %11, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %11 ], [ 1, %4 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @siphash_adjust_hash_size(i64 noundef) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !10, i64 44}
!6 = !{!"siphash_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !8, i64 56}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass