; LLVM IR from kojiba/purge :: purge (roundKeyForStep)

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

@purgeSubstitutionBlock = external hidden constant [256 x i8], align 16
@"purgeKey\D0\90mplificationConstans" = external hidden constant [8 x i64], align 16

; Function Attrs: nounwind uwtable
declare dso_local i64 @substitute(i64 noundef, ptr noundef) #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

; Function Attrs: nounwind uwtable
declare dso_local void @rotateBytes(ptr noundef, i8 noundef zeroext) #0

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

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

7:                                                ; preds = %105, %2
  %8 = load i8, ptr %5, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = load i8, ptr %4, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %13, label %108

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds i64, ptr %14, i64 7
  %16 = load i64, ptr %15, align 8, !tbaa !10
  store i64 %16, ptr %6, align 8, !tbaa !10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i64, ptr %17, i64 2
  %19 = load i64, ptr %18, align 8, !tbaa !10
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds i64, ptr %20, i64 7
  store i64 %19, ptr %21, align 8, !tbaa !10
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds i64, ptr %22, i64 5
  %24 = load i64, ptr %23, align 8, !tbaa !10
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr %25, i64 2
  store i64 %24, ptr %26, align 8, !tbaa !10
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds i64, ptr %27, i64 0
  %29 = load i64, ptr %28, align 8, !tbaa !10
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %30, i64 5
  store i64 %29, ptr %31, align 8, !tbaa !10
  %32 = load i64, ptr %6, align 8, !tbaa !10
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %33, i64 0
  store i64 %32, ptr %34, align 8, !tbaa !10
  store i64 0, ptr %6, align 8, !tbaa !10
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %35, i64 1
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = call i64 @substitute(i64 noundef %37, ptr noundef @purgeSubstitutionBlock)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %39, i64 1
  store i64 %38, ptr %40, align 8, !tbaa !10
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds i64, ptr %41, i64 3
  %43 = load i64, ptr %42, align 8, !tbaa !10
  %44 = call i64 @substitute(i64 noundef %43, ptr noundef @purgeSubstitutionBlock)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds i64, ptr %45, i64 3
  store i64 %44, ptr %46, align 8, !tbaa !10
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds i64, ptr %47, i64 4
  %49 = load i64, ptr %48, align 8, !tbaa !10
  %50 = call i64 @substitute(i64 noundef %49, ptr noundef @purgeSubstitutionBlock)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds i64, ptr %51, i64 4
  store i64 %50, ptr %52, align 8, !tbaa !10
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds i64, ptr %53, i64 6
  %55 = load i64, ptr %54, align 8, !tbaa !10
  %56 = call i64 @substitute(i64 noundef %55, ptr noundef @purgeSubstitutionBlock)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds i64, ptr %57, i64 6
  store i64 %56, ptr %58, align 8, !tbaa !10
  %59 = load i64, ptr @"purgeKey\D0\90mplificationConstans", align 16, !tbaa !10
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds i64, ptr %60, i64 0
  %62 = load i64, ptr %61, align 8, !tbaa !10
  %63 = add i64 %62, %59
  store i64 %63, ptr %61, align 8, !tbaa !10
  %64 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 1), align 8, !tbaa !10
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds i64, ptr %65, i64 1
  %67 = load i64, ptr %66, align 8, !tbaa !10
  %68 = add i64 %67, %64
  store i64 %68, ptr %66, align 8, !tbaa !10
  %69 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 2), align 16, !tbaa !10
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds i64, ptr %70, i64 2
  %72 = load i64, ptr %71, align 8, !tbaa !10
  %73 = add i64 %72, %69
  store i64 %73, ptr %71, align 8, !tbaa !10
  %74 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 3), align 8, !tbaa !10
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds i64, ptr %75, i64 3
  %77 = load i64, ptr %76, align 8, !tbaa !10
  %78 = add i64 %77, %74
  store i64 %78, ptr %76, align 8, !tbaa !10
  %79 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 4), align 16, !tbaa !10
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds i64, ptr %80, i64 4
  %82 = load i64, ptr %81, align 8, !tbaa !10
  %83 = add i64 %82, %79
  store i64 %83, ptr %81, align 8, !tbaa !10
  %84 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 5), align 8, !tbaa !10
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds i64, ptr %85, i64 5
  %87 = load i64, ptr %86, align 8, !tbaa !10
  %88 = add i64 %87, %84
  store i64 %88, ptr %86, align 8, !tbaa !10
  %89 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 6), align 16, !tbaa !10
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds i64, ptr %90, i64 6
  %92 = load i64, ptr %91, align 8, !tbaa !10
  %93 = add i64 %92, %89
  store i64 %93, ptr %91, align 8, !tbaa !10
  %94 = load i64, ptr getelementptr inbounds ([8 x i64], ptr @"purgeKey\D0\90mplificationConstans", i64 0, i64 7), align 8, !tbaa !10
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds i64, ptr %95, i64 7
  %97 = load i64, ptr %96, align 8, !tbaa !10
  %98 = add i64 %97, %94
  store i64 %98, ptr %96, align 8, !tbaa !10
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = load i8, ptr %5, align 1, !tbaa !9
  %101 = zext i8 %100 to i32
  %102 = srem i32 %101, 32
  %103 = add nsw i32 %102, 1
  %104 = trunc i32 %103 to i8
  call void @rotateBytes(ptr noundef %99, i8 noundef zeroext %104)
  br label %105

105:                                              ; preds = %13
  %106 = load i8, ptr %5, align 1, !tbaa !9
  %107 = add i8 %106, 1
  store i8 %107, ptr %5, align 1, !tbaa !9
  br label %7, !llvm.loop !12

108:                                              ; preds = %7
  call void @llvm.memset.p0.i64(ptr align 1 %5, i8 0, i64 1, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  ret void
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@purgeSubstitutionBlock = external hidden constant [256 x i8], align 16
@"purgeKey\D0\90mplificationConstans" = external hidden local_unnamed_addr constant [8 x i64], align 16

; Function Attrs: nounwind uwtable
declare dso_local i64 @substitute(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @rotateBytes(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @roundKeyForStep(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load <2 x i64>, ptr @"purgeKey\D0\90mplificationConstans", align 16
  %11 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @"purgeKey\D0\90mplificationConstans", i64 16), align 16
  %12 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @"purgeKey\D0\90mplificationConstans", i64 32), align 16
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @"purgeKey\D0\90mplificationConstans", i64 48), align 16
  %14 = load i64, ptr getelementptr inbounds (i8, ptr @"purgeKey\D0\90mplificationConstans", i64 56), align 8
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %.030 = phi i8 [ 0, %.lr.ph ], [ %38, %15 ]
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %17, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %18, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %0, align 8, !tbaa !5
  store i64 %19, ptr %5, align 8, !tbaa !5
  store i64 %16, ptr %0, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = tail call i64 @substitute(i64 noundef %20, ptr noundef nonnull @purgeSubstitutionBlock)
  store i64 %21, ptr %6, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = tail call i64 @substitute(i64 noundef %22, ptr noundef nonnull @purgeSubstitutionBlock)
  store i64 %23, ptr %7, align 8, !tbaa !5
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = tail call i64 @substitute(i64 noundef %24, ptr noundef nonnull @purgeSubstitutionBlock)
  store i64 %25, ptr %8, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = tail call i64 @substitute(i64 noundef %26, ptr noundef nonnull @purgeSubstitutionBlock)
  %28 = load <2 x i64>, ptr %0, align 8, !tbaa !5
  %29 = add <2 x i64> %28, %10
  store <2 x i64> %29, ptr %0, align 8, !tbaa !5
  %30 = load <2 x i64>, ptr %4, align 8, !tbaa !5
  %31 = add <2 x i64> %30, %11
  store <2 x i64> %31, ptr %4, align 8, !tbaa !5
  %32 = load <2 x i64>, ptr %8, align 8, !tbaa !5
  %33 = add <2 x i64> %32, %12
  store <2 x i64> %33, ptr %8, align 8, !tbaa !5
  %34 = add i64 %13, %27
  store i64 %34, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = add i64 %35, %14
  store i64 %36, ptr %3, align 8, !tbaa !5
  %37 = and i8 %.030, 31
  %narrow = add nuw nsw i8 %37, 1
  tail call void @rotateBytes(ptr noundef nonnull %0, i8 noundef zeroext %narrow)
  %38 = add nuw i8 %.030, 1
  %exitcond.not = icmp eq i8 %38, %1
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !9

._crit_edge:                                      ; preds = %15, %2
  ret void
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass