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

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

@k8 = external hidden constant [16 x i8], align 16
@k7 = external hidden constant [16 x i8], align 16
@k87 = external hidden global [256 x i8], align 16
@k6 = external hidden constant [16 x i8], align 16
@k5 = external hidden constant [16 x i8], align 16
@k65 = external hidden global [256 x i8], align 16
@k4 = external hidden constant [16 x i8], align 16
@k3 = external hidden constant [16 x i8], align 16
@k43 = external hidden global [256 x i8], align 16
@k2 = external hidden constant [16 x i8], align 16
@k1 = external hidden constant [16 x i8], align 16
@k21 = external hidden global [256 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @kboxinit() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %78, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 256
  br i1 %4, label %5, label %81

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = ashr i32 %6, 4
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [16 x i8], ptr @k8, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = shl i32 %11, 4
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = and i32 %13, 15
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [16 x i8], ptr @k7, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = or i32 %12, %18
  %20 = trunc i32 %19 to i8
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [256 x i8], ptr @k87, i64 0, i64 %22
  store i8 %20, ptr %23, align 1, !tbaa !9
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = ashr i32 %24, 4
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [16 x i8], ptr @k6, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = shl i32 %29, 4
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = and i32 %31, 15
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [16 x i8], ptr @k5, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = or i32 %30, %36
  %38 = trunc i32 %37 to i8
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i8], ptr @k65, i64 0, i64 %40
  store i8 %38, ptr %41, align 1, !tbaa !9
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = ashr i32 %42, 4
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [16 x i8], ptr @k4, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = zext i8 %46 to i32
  %48 = shl i32 %47, 4
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = and i32 %49, 15
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [16 x i8], ptr @k3, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = or i32 %48, %54
  %56 = trunc i32 %55 to i8
  %57 = load i32, ptr %1, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [256 x i8], ptr @k43, i64 0, i64 %58
  store i8 %56, ptr %59, align 1, !tbaa !9
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = ashr i32 %60, 4
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [16 x i8], ptr @k2, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !9
  %65 = zext i8 %64 to i32
  %66 = shl i32 %65, 4
  %67 = load i32, ptr %1, align 4, !tbaa !5
  %68 = and i32 %67, 15
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [16 x i8], ptr @k1, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !9
  %72 = zext i8 %71 to i32
  %73 = or i32 %66, %72
  %74 = trunc i32 %73 to i8
  %75 = load i32, ptr %1, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [256 x i8], ptr @k21, i64 0, i64 %76
  store i8 %74, ptr %77, align 1, !tbaa !9
  br label %78

78:                                               ; preds = %5
  %79 = load i32, ptr %1, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !10

81:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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: 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@k8 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k7 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k87 = external hidden local_unnamed_addr global [256 x i8], align 16
@k6 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k5 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k65 = external hidden local_unnamed_addr global [256 x i8], align 16
@k4 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k3 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k43 = external hidden local_unnamed_addr global [256 x i8], align 16
@k2 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k1 = external hidden local_unnamed_addr constant [16 x i8], align 16
@k21 = external hidden local_unnamed_addr global [256 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @kboxinit() local_unnamed_addr #0 {
vector.scevcheck:
  br label %0

0:                                                ; preds = %vector.scevcheck, %0
  %indvars.iv = phi i64 [ 0, %vector.scevcheck ], [ %indvars.iv.next, %0 ]
  %1 = lshr i64 %indvars.iv, 4
  %2 = and i64 %1, 268435455
  %3 = getelementptr inbounds [16 x i8], ptr @k8, i64 0, i64 %2
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = shl i8 %4, 4
  %6 = and i64 %indvars.iv, 15
  %7 = getelementptr inbounds [16 x i8], ptr @k7, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = or i8 %5, %8
  %10 = getelementptr inbounds [256 x i8], ptr @k87, i64 0, i64 %indvars.iv
  store i8 %9, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds [16 x i8], ptr @k6, i64 0, i64 %2
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = shl i8 %12, 4
  %14 = getelementptr inbounds [16 x i8], ptr @k5, i64 0, i64 %6
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = or i8 %13, %15
  %17 = getelementptr inbounds [256 x i8], ptr @k65, i64 0, i64 %indvars.iv
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = getelementptr inbounds [16 x i8], ptr @k4, i64 0, i64 %2
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = shl i8 %19, 4
  %21 = getelementptr inbounds [16 x i8], ptr @k3, i64 0, i64 %6
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = or i8 %20, %22
  %24 = getelementptr inbounds [256 x i8], ptr @k43, i64 0, i64 %indvars.iv
  store i8 %23, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds [16 x i8], ptr @k2, i64 0, i64 %2
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = shl i8 %26, 4
  %28 = getelementptr inbounds [16 x i8], ptr @k1, i64 0, i64 %6
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = or i8 %27, %29
  %31 = getelementptr inbounds [256 x i8], ptr @k21, i64 0, i64 %indvars.iv
  store i8 %30, ptr %31, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %.loopexit, label %0, !llvm.loop !8

.loopexit:                                        ; preds = %0
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) 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, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}


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