; LLVM IR from CROSS-signature/CROSS-implementation :: Additional_Implementations/KAT_Generation/lib (KAT_NIST_rng)

; 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.KAT_NIST_AES_XOF_struct = type { [16 x i8], i32, i64, [32 x i8], [16 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @KAT_NIST_seedexpander_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = icmp uge i64 %10, 4294967296
  br i1 %11, label %12, label %13

12:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  br label %64

13:                                               ; preds = %4
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %15, i32 0, i32 2
  store i64 %14, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr align 1 %20, i64 32, i1 false)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds [16 x i8], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 1 %24, i64 8, i1 false)
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = urem i64 %25, 256
  %27 = trunc i64 %26 to i8
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %28, i32 0, i32 4
  %30 = getelementptr inbounds [16 x i8], ptr %29, i64 0, i64 11
  store i8 %27, ptr %30, align 1, !tbaa !14
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = lshr i64 %31, 8
  store i64 %32, ptr %9, align 8, !tbaa !9
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = urem i64 %33, 256
  %35 = trunc i64 %34 to i8
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds [16 x i8], ptr %37, i64 0, i64 10
  store i8 %35, ptr %38, align 2, !tbaa !14
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = lshr i64 %39, 8
  store i64 %40, ptr %9, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = urem i64 %41, 256
  %43 = trunc i64 %42 to i8
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %44, i32 0, i32 4
  %46 = getelementptr inbounds [16 x i8], ptr %45, i64 0, i64 9
  store i8 %43, ptr %46, align 1, !tbaa !14
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = lshr i64 %47, 8
  store i64 %48, ptr %9, align 8, !tbaa !9
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = urem i64 %49, 256
  %51 = trunc i64 %50 to i8
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %52, i32 0, i32 4
  %54 = getelementptr inbounds [16 x i8], ptr %53, i64 0, i64 8
  store i8 %51, ptr %54, align 8, !tbaa !14
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %55, i32 0, i32 4
  %57 = getelementptr inbounds [16 x i8], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds i8, ptr %57, i64 12
  call void @llvm.memset.p0.i64(ptr align 1 %58, i8 0, i64 4, i1 false)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %59, i32 0, i32 1
  store i32 16, ptr %60, align 8, !tbaa !15
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.KAT_NIST_AES_XOF_struct, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds [16 x i8], ptr %62, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %63, i8 0, i64 16, i1 false)
  store i32 0, ptr %5, align 4
  br label %64

64:                                               ; preds = %13, %12
  %65 = load i32, ptr %5, align 4
  ret i32 %65
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !10, i64 24}
!12 = !{!"", !7, i64 0, !13, i64 16, !10, i64 24, !7, i64 32, !7, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !13, 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 -1, 1) i32 @KAT_NIST_seedexpander_init(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp ugt i64 %3, 4294967295
  br i1 %5, label %24, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false)
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load i64, ptr %2, align 1
  store i64 %10, ptr %9, align 8
  %11 = trunc i64 %3 to i8
  %12 = getelementptr inbounds i8, ptr %0, i64 75
  store i8 %11, ptr %12, align 1, !tbaa !11
  %13 = lshr i64 %3, 8
  %14 = trunc i64 %13 to i8
  %15 = getelementptr inbounds i8, ptr %0, i64 74
  store i8 %14, ptr %15, align 2, !tbaa !11
  %16 = lshr i64 %3, 16
  %17 = trunc i64 %16 to i8
  %18 = getelementptr inbounds i8, ptr %0, i64 73
  store i8 %17, ptr %18, align 1, !tbaa !11
  %19 = lshr i64 %3, 24
  %20 = trunc nuw i64 %19 to i8
  %21 = getelementptr inbounds i8, ptr %0, i64 72
  store i8 %20, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %0, i64 76
  store i32 0, ptr %22, align 1
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 16, ptr %23, align 8, !tbaa !12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br label %24

24:                                               ; preds = %4, %6
  %.0 = phi i32 [ 0, %6 ], [ -1, %4 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 24}
!6 = !{!"", !7, i64 0, !9, i64 16, !10, i64 24, !7, i64 32, !7, i64 64}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !9, i64 16}


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