; LLVM IR from stamparm/cryptospecs :: symmetrical/sources (sn3)

; 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"

@seed = external dso_local global [192 x i64], align 16
@keystream = external dso_local global [192 x i64], align 16

; Function Attrs: nounwind uwtable
define dso_local void @init_seed(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr @seed, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %6, align 8, !tbaa !9
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %24, %2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp ult i64 %9, 1536
  br i1 %10, label %11, label %29

11:                                               ; preds = %8
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp eq i64 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %15, %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %21, i64 %22
  store i8 %20, ptr %23, align 1, !tbaa !11
  br label %24

24:                                               ; preds = %16
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %5, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = add i64 %27, 1
  store i64 %28, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !12

29:                                               ; preds = %8
  call void @sn3()
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %49, %29
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = icmp ult i64 %31, 192
  br i1 %32, label %33, label %52

33:                                               ; preds = %30
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds [192 x i64], ptr @seed, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = shl i64 %36, 19
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds [192 x i64], ptr @seed, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = lshr i64 %40, 13
  %42 = or i64 %37, %41
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds [192 x i64], ptr @keystream, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = xor i64 %42, %45
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds [192 x i64], ptr @seed, i64 0, i64 %47
  store i64 %46, ptr %48, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %33
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %5, align 8, !tbaa !9
  br label %30, !llvm.loop !14

52:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @sn3() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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"

@seed = external dso_local local_unnamed_addr global [192 x i64], align 16
@keystream = external dso_local local_unnamed_addr global [192 x i64], align 16

; Function Attrs: nounwind uwtable
define dso_local void @init_seed(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %3, %2
  %.016 = phi i64 [ 0, %2 ], [ %16, %3 ]
  %.01415 = phi i64 [ 0, %2 ], [ %17, %3 ]
  %4 = icmp eq i64 %.01415, %1
  %spec.store.select = select i1 %4, i64 0, i64 %.01415
  %5 = getelementptr inbounds i8, ptr %0, i64 %spec.store.select
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr @seed, i64 %.016
  store i8 %6, ptr %7, align 1, !tbaa !5
  %8 = add i64 %spec.store.select, 1
  %9 = icmp eq i64 %8, %1
  %spec.store.select.1 = select i1 %9, i64 0, i64 %8
  %10 = getelementptr inbounds i8, ptr %0, i64 %spec.store.select.1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %gep = getelementptr inbounds i8, ptr getelementptr inbounds (i8, ptr @seed, i64 1), i64 %.016
  store i8 %11, ptr %gep, align 1, !tbaa !5
  %12 = add i64 %spec.store.select.1, 1
  %13 = icmp eq i64 %12, %1
  %spec.store.select.2 = select i1 %13, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %0, i64 %spec.store.select.2
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %gep22 = getelementptr inbounds i8, ptr getelementptr inbounds (i8, ptr @seed, i64 2), i64 %.016
  store i8 %15, ptr %gep22, align 1, !tbaa !5
  %16 = add nuw nsw i64 %.016, 3
  %17 = add i64 %spec.store.select.2, 1
  %exitcond.not.2 = icmp eq i64 %16, 1536
  br i1 %exitcond.not.2, label %vector.ph, label %3, !llvm.loop !8

vector.ph:                                        ; preds = %3
  tail call void @sn3()
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = getelementptr inbounds [192 x i64], ptr @seed, i64 0, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %wide.load = load <2 x i64>, ptr %18, align 16, !tbaa !10
  %wide.load19 = load <2 x i64>, ptr %19, align 16, !tbaa !10
  %20 = shl <2 x i64> %wide.load, <i64 19, i64 19>
  %21 = shl <2 x i64> %wide.load19, <i64 19, i64 19>
  %22 = lshr <2 x i64> %wide.load, <i64 13, i64 13>
  %23 = lshr <2 x i64> %wide.load19, <i64 13, i64 13>
  %24 = or <2 x i64> %20, %22
  %25 = or <2 x i64> %21, %23
  %26 = getelementptr inbounds [192 x i64], ptr @keystream, i64 0, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load20 = load <2 x i64>, ptr %26, align 16, !tbaa !10
  %wide.load21 = load <2 x i64>, ptr %27, align 16, !tbaa !10
  %28 = xor <2 x i64> %24, %wide.load20
  %29 = xor <2 x i64> %25, %wide.load21
  store <2 x i64> %28, ptr %18, align 16, !tbaa !10
  store <2 x i64> %29, ptr %19, align 16, !tbaa !10
  %index.next = add nuw i64 %index, 4
  %30 = icmp eq i64 %index.next, 192
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @sn3() 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = distinct !{!12, !9, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass