; LLVM IR from gost-engine/engine :: gost89 (gost_mac_iv)

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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
declare dso_local void @mac_block(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @get_mac(ptr noundef, i32 noundef, ptr noundef) #3

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

18:                                               ; preds = %30, %6
  %19 = load i32, ptr %15, align 4, !tbaa !9
  %20 = add i32 %19, 8
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = icmp ule i32 %20, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %18
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = load i32, ptr %15, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  call void @mac_block(ptr noundef %24, ptr noundef %25, ptr noundef %29)
  br label %30

30:                                               ; preds = %23
  %31 = load i32, ptr %15, align 4, !tbaa !9
  %32 = add i32 %31, 8
  store i32 %32, ptr %15, align 4, !tbaa !9
  br label %18, !llvm.loop !11

33:                                               ; preds = %18
  %34 = load i32, ptr %15, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %53

37:                                               ; preds = %33
  %38 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %38, i8 0, i64 8, i1 false)
  %39 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = sub i32 %44, %45
  %47 = zext i32 %46 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 1 %43, i64 %47, i1 false)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %50 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  call void @mac_block(ptr noundef %48, ptr noundef %49, ptr noundef %50)
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = add i32 %51, 8
  store i32 %52, ptr %15, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %37, %33
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 8
  br i1 %55, label %56, label %61

56:                                               ; preds = %53
  %57 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %57, i8 0, i64 8, i1 false)
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %60 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  call void @mac_block(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  br label %61

61:                                               ; preds = %56, %53
  %62 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  call void @get_mac(ptr noundef %62, i32 noundef %63, ptr noundef %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret i32 1
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @get_mac(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @gost_mac_iv(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca [8 x i8], align 8
  %8 = alloca [8 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  %9 = load i64, ptr %2, align 1
  store i64 %9, ptr %7, align 8
  %.not21 = icmp ult i32 %4, 8
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.lr.ph
  %10 = phi i32 [ %13, %.lr.ph ], [ 8, %6 ]
  %.022 = phi i32 [ %10, %.lr.ph ], [ 0, %6 ]
  %11 = zext i32 %.022 to i64
  %12 = getelementptr inbounds i8, ptr %3, i64 %11
  call void @mac_block(ptr noundef %0, ptr noundef nonnull %7, ptr noundef %12)
  %13 = add i32 %10, 8
  %.not = icmp ugt i32 %13, %4
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.0.lcssa = phi i32 [ 0, %6 ], [ %10, %.lr.ph ]
  %.lcssa = phi i32 [ 8, %6 ], [ %13, %.lr.ph ]
  %14 = icmp ult i32 %.0.lcssa, %4
  br i1 %14, label %15, label %20

15:                                               ; preds = %._crit_edge
  store i64 0, ptr %8, align 8
  %16 = zext i32 %.0.lcssa to i64
  %17 = getelementptr inbounds i8, ptr %3, i64 %16
  %18 = sub i32 %4, %.0.lcssa
  %19 = zext i32 %18 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %8, ptr align 1 %17, i64 %19, i1 false)
  call void @mac_block(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %8)
  br label %20

20:                                               ; preds = %15, %._crit_edge
  %.1 = phi i32 [ %.lcssa, %15 ], [ %.0.lcssa, %._crit_edge ]
  %21 = icmp eq i32 %.1, 8
  br i1 %21, label %22, label %23

22:                                               ; preds = %20
  store i64 0, ptr %8, align 8
  call void @mac_block(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %8)
  br label %23

23:                                               ; preds = %22, %20
  call void @get_mac(ptr noundef nonnull %7, i32 noundef %1, ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  ret i32 1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass