; LLVM IR from guanzhi/GmSSL :: src (zuc_modes)

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

; Function Attrs: nounwind uwtable
define dso_local void @zuc_eea_encrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct.ZUC_STATE, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !11
  store i32 %5, ptr %13, align 4, !tbaa !11
  store i32 %6, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 72, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %18 = load i64, ptr %10, align 8, !tbaa !9
  %19 = add i64 %18, 31
  %20 = udiv i64 %19, 32
  store i64 %20, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = load i32, ptr %12, align 4, !tbaa !11
  %23 = load i32, ptr %13, align 4, !tbaa !11
  %24 = load i32, ptr %14, align 4, !tbaa !11
  call void @zuc_set_eea_key(ptr noundef %15, ptr noundef %21, i32 noundef %22, i32 noundef %23, i32 noundef %24)
  %25 = load i64, ptr %16, align 8, !tbaa !9
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  call void @zuc_generate_keystream(ptr noundef %15, i64 noundef %25, ptr noundef %26)
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %41, %7
  %28 = load i64, ptr %17, align 8, !tbaa !9
  %29 = load i64, ptr %16, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %31, label %44

31:                                               ; preds = %27
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %17, align 8, !tbaa !9
  %34 = getelementptr inbounds i32, ptr %32, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %17, align 8, !tbaa !9
  %38 = getelementptr inbounds i32, ptr %36, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = xor i32 %39, %35
  store i32 %40, ptr %38, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %31
  %42 = load i64, ptr %17, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %17, align 8, !tbaa !9
  br label %27, !llvm.loop !13

44:                                               ; preds = %27
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = urem i64 %45, 32
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %60

48:                                               ; preds = %44
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = urem i64 %49, 32
  %51 = sub i64 32, %50
  %52 = trunc i64 %51 to i32
  %53 = shl i32 -1, %52
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i64, ptr %16, align 8, !tbaa !9
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = and i32 %58, %53
  store i32 %59, ptr %57, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %48, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %15) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @zuc_set_eea_key(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

declare void @zuc_generate_keystream(ptr noundef, i64 noundef, ptr noundef) #2

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


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

%struct.ZUC_STATE = type { [16 x i32], i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @zuc_eea_encrypt(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = alloca %struct.ZUC_STATE, align 4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %8) #3
  %9 = add i64 %2, 31
  %10 = lshr i64 %9, 5
  call void @zuc_set_eea_key(ptr noundef nonnull %8, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6)
  call void @zuc_generate_keystream(ptr noundef nonnull %8, i64 noundef %10, ptr noundef %1) #3
  %.not20 = icmp ult i64 %9, 32
  br i1 %.not20, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %min.iters.check = icmp ult i64 %9, 256
  br i1 %min.iters.check, label %.lr.ph.preheader25, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %11 = shl nuw nsw i64 %10, 2
  %scevgep = getelementptr i8, ptr %1, i64 %11
  %scevgep21 = getelementptr i8, ptr %0, i64 %11
  %bound0 = icmp ugt ptr %scevgep21, %1
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader25, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %10, 576460752303423480
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = getelementptr inbounds i32, ptr %0, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load = load <4 x i32>, ptr %12, align 4, !tbaa !5, !alias.scope !9
  %wide.load22 = load <4 x i32>, ptr %13, align 4, !tbaa !5, !alias.scope !9
  %14 = getelementptr inbounds i32, ptr %1, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load23 = load <4 x i32>, ptr %14, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load24 = load <4 x i32>, ptr %15, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %16 = xor <4 x i32> %wide.load23, %wide.load
  %17 = xor <4 x i32> %wide.load24, %wide.load22
  store <4 x i32> %16, ptr %14, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x i32> %17, ptr %15, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %10, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader25

.lr.ph.preheader25:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.019.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %10, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader25, %.lr.ph.prol
  %.019.prol = phi i64 [ %24, %.lr.ph.prol ], [ %.019.ph, %.lr.ph.preheader25 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader25 ]
  %19 = getelementptr inbounds i32, ptr %0, i64 %.019.prol
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds i32, ptr %1, i64 %.019.prol
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = xor i32 %22, %20
  store i32 %23, ptr %21, align 4, !tbaa !5
  %24 = add nuw nsw i64 %.019.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !18

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader25
  %.019.unr = phi i64 [ %.019.ph, %.lr.ph.preheader25 ], [ %24, %.lr.ph.prol ]
  %25 = sub nsw i64 %.019.ph, %10
  %26 = icmp ugt i64 %25, -4
  br i1 %26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.019 = phi i64 [ %50, %.lr.ph ], [ %.019.unr, %.lr.ph.prol.loopexit ]
  %27 = getelementptr inbounds i32, ptr %0, i64 %.019
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %1, i64 %.019
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = xor i32 %30, %28
  store i32 %31, ptr %29, align 4, !tbaa !5
  %32 = add nuw nsw i64 %.019, 1
  %33 = getelementptr inbounds i32, ptr %0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %1, i64 %32
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = xor i32 %36, %34
  store i32 %37, ptr %35, align 4, !tbaa !5
  %38 = add nuw nsw i64 %.019, 2
  %39 = getelementptr inbounds i32, ptr %0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds i32, ptr %1, i64 %38
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = xor i32 %42, %40
  store i32 %43, ptr %41, align 4, !tbaa !5
  %44 = add nuw nsw i64 %.019, 3
  %45 = getelementptr inbounds i32, ptr %0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = getelementptr inbounds i32, ptr %1, i64 %44
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = xor i32 %48, %46
  store i32 %49, ptr %47, align 4, !tbaa !5
  %50 = add nuw nsw i64 %.019, 4
  %exitcond.not.3 = icmp eq i64 %50, %10
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %7
  %51 = and i64 %2, 31
  %.not = icmp eq i64 %51, 0
  br i1 %.not, label %60, label %52

52:                                               ; preds = %._crit_edge
  %53 = trunc nuw nsw i64 %51 to i32
  %54 = sub nuw nsw i32 32, %53
  %55 = shl nsw i32 -1, %54
  %56 = getelementptr i32, ptr %1, i64 %10
  %57 = getelementptr i8, ptr %56, i64 -4
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = and i32 %58, %55
  store i32 %59, ptr %57, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %52, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %8) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @zuc_set_eea_key(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @zuc_generate_keystream(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass