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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @gostcrypt(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @gostofb(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [2 x i64], align 16
  %12 = alloca [2 x i64], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #2
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  call void @gostcrypt(ptr noundef %13, ptr noundef %14, ptr noundef %15)
  br label %16

16:                                               ; preds = %42, %5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %8, align 4, !tbaa !9
  %19 = icmp ne i32 %17, 0
  br i1 %19, label %20, label %62

20:                                               ; preds = %16
  %21 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %22 = load i64, ptr %21, align 16, !tbaa !11
  %23 = add i64 %22, 16843009
  store i64 %23, ptr %21, align 16, !tbaa !11
  %24 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %25 = load i64, ptr %24, align 16, !tbaa !11
  %26 = icmp ult i64 %25, 16843009
  br i1 %26, label %27, label %31

27:                                               ; preds = %20
  %28 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %29 = load i64, ptr %28, align 16, !tbaa !11
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 16, !tbaa !11
  br label %31

31:                                               ; preds = %27, %20
  %32 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 1
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = add i64 %33, 16843012
  store i64 %34, ptr %32, align 8, !tbaa !11
  %35 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 1
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = icmp ult i64 %36, 16843012
  br i1 %37, label %38, label %42

38:                                               ; preds = %31
  %39 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 1
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = add i64 %40, 1
  store i64 %41, ptr %39, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %38, %31
  %43 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %44 = getelementptr inbounds [2 x i64], ptr %12, i64 0, i64 0
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  call void @gostcrypt(ptr noundef %43, ptr noundef %44, ptr noundef %45)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %46, i32 1
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %46, align 8, !tbaa !11
  %49 = getelementptr inbounds [2 x i64], ptr %12, i64 0, i64 0
  %50 = load i64, ptr %49, align 16, !tbaa !11
  %51 = xor i64 %48, %50
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %52, i32 1
  store ptr %53, ptr %7, align 8, !tbaa !5
  store i64 %51, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds i64, ptr %54, i32 1
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = load i64, ptr %54, align 8, !tbaa !11
  %57 = getelementptr inbounds [2 x i64], ptr %12, i64 0, i64 1
  %58 = load i64, ptr %57, align 8, !tbaa !11
  %59 = xor i64 %56, %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds i64, ptr %60, i32 1
  store ptr %61, ptr %7, align 8, !tbaa !5
  store i64 %59, ptr %60, align 8, !tbaa !11
  br label %16, !llvm.loop !13

62:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @gostcrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gostofb(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca [2 x i64], align 16
  %7 = alloca [2 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #2
  call void @gostcrypt(ptr noundef %3, ptr noundef nonnull %6, ptr noundef %4)
  %.not12 = icmp eq i32 %2, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %.015 = phi ptr [ %0, %.lr.ph ], [ %21, %10 ]
  %.0714 = phi ptr [ %1, %.lr.ph ], [ %25, %10 ]
  %.0813 = phi i32 [ %2, %.lr.ph ], [ %11, %10 ]
  %11 = add nsw i32 %.0813, -1
  %12 = load i64, ptr %6, align 16, !tbaa !5
  %13 = icmp ugt i64 %12, -16843010
  %spec.select.v = select i1 %13, i64 16843010, i64 16843009
  %spec.select = add i64 %spec.select.v, %12
  store i64 %spec.select, ptr %6, align 16, !tbaa !5
  %14 = load i64, ptr %8, align 8, !tbaa !5
  %15 = icmp ugt i64 %14, -16843013
  %storemerge11.v = select i1 %15, i64 16843013, i64 16843012
  %storemerge11 = add i64 %storemerge11.v, %14
  store i64 %storemerge11, ptr %8, align 8, !tbaa !5
  call void @gostcrypt(ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef %4)
  %16 = getelementptr inbounds i8, ptr %.015, i64 8
  %17 = load i64, ptr %.015, align 8, !tbaa !5
  %18 = load i64, ptr %7, align 16, !tbaa !5
  %19 = xor i64 %18, %17
  %20 = getelementptr inbounds i8, ptr %.0714, i64 8
  store i64 %19, ptr %.0714, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.015, i64 16
  %22 = load i64, ptr %16, align 8, !tbaa !5
  %23 = load i64, ptr %9, align 8, !tbaa !5
  %24 = xor i64 %23, %22
  %25 = getelementptr inbounds i8, ptr %.0714, i64 16
  store i64 %24, ptr %20, align 8, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !9

._crit_edge:                                      ; preds = %10, %5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass