; LLVM IR from gost-engine/engine :: gost_crypt (decrement_sequence)

; 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
define dso_local i32 @decrement_sequence(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %12, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %2
  store i32 0, ptr %3, align 4
  br label %46

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %45

16:                                               ; preds = %13
  store i32 7, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %41, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %44

20:                                               ; preds = %17
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %20
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = add i8 %33, -1
  store i8 %34, ptr %32, align 1, !tbaa !11
  br label %44

35:                                               ; preds = %20
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  store i8 -1, ptr %39, align 1, !tbaa !11
  br label %40

40:                                               ; preds = %35
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !12

44:                                               ; preds = %28, %17
  br label %45

45:                                               ; preds = %44, %13
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %46

46:                                               ; preds = %45, %12
  %47 = load i32, ptr %3, align 4
  ret i32 %47
}

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 = !{!7, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @decrement_sequence(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %or.cond = icmp ugt i32 %1, 1
  br i1 %or.cond, label %.loopexit, label %3

3:                                                ; preds = %2
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 7
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %.not14 = icmp eq i8 %5, 0
  br i1 %.not14, label %.preheader.1, label %6

6:                                                ; preds = %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.lcssa18 = phi ptr [ %4, %.preheader.preheader ], [ %8, %.preheader.1 ], [ %10, %.preheader.2 ], [ %12, %.preheader.3 ], [ %14, %.preheader.4 ], [ %16, %.preheader.5 ], [ %18, %.preheader.6 ], [ %0, %.preheader.7 ]
  %.lcssa = phi i8 [ %5, %.preheader.preheader ], [ %9, %.preheader.1 ], [ %11, %.preheader.2 ], [ %13, %.preheader.3 ], [ %15, %.preheader.4 ], [ %17, %.preheader.5 ], [ %19, %.preheader.6 ], [ %20, %.preheader.7 ]
  %7 = add i8 %.lcssa, -1
  store i8 %7, ptr %.lcssa18, align 1, !tbaa !5
  br label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  store i8 -1, ptr %4, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 6
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %.not14.1 = icmp eq i8 %9, 0
  br i1 %.not14.1, label %.preheader.2, label %6

.preheader.2:                                     ; preds = %.preheader.1
  store i8 -1, ptr %8, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 5
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %.not14.2 = icmp eq i8 %11, 0
  br i1 %.not14.2, label %.preheader.3, label %6

.preheader.3:                                     ; preds = %.preheader.2
  store i8 -1, ptr %10, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not14.3 = icmp eq i8 %13, 0
  br i1 %.not14.3, label %.preheader.4, label %6

.preheader.4:                                     ; preds = %.preheader.3
  store i8 -1, ptr %12, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 3
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %.not14.4 = icmp eq i8 %15, 0
  br i1 %.not14.4, label %.preheader.5, label %6

.preheader.5:                                     ; preds = %.preheader.4
  store i8 -1, ptr %14, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 2
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not14.5 = icmp eq i8 %17, 0
  br i1 %.not14.5, label %.preheader.6, label %6

.preheader.6:                                     ; preds = %.preheader.5
  store i8 -1, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %.not14.6 = icmp eq i8 %19, 0
  br i1 %.not14.6, label %.preheader.7, label %6

.preheader.7:                                     ; preds = %.preheader.6
  store i8 -1, ptr %18, align 1, !tbaa !5
  %20 = load i8, ptr %0, align 1, !tbaa !5
  %.not14.7 = icmp eq i8 %20, 0
  br i1 %.not14.7, label %.loopexit.loopexit, label %6

.loopexit.loopexit:                               ; preds = %.preheader.7
  store i8 -1, ptr %0, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %3, %6, %2
  %.012 = phi i32 [ 0, %2 ], [ 1, %6 ], [ 1, %3 ], [ 1, %.loopexit.loopexit ]
  ret i32 %.012
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass