; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Educational Codeforces Round 126 (Rated for Div. 2)/B. Getting Zero.ll (Z3prev)

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

@dp = external dso_local global [32768 x i64], align 16
@_ZL3INF = external hidden constant i64, align 8

; 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: mustprogress uwtable
declare dso_local noundef i64 @_Z7findMinl(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3prev() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @_ZSt4fillIPllEvT_S1_RKT0_(ptr noundef @dp, ptr noundef getelementptr inbounds (i64, ptr @dp, i64 32768), ptr noundef nonnull align 8 dereferenceable(8) @_ZL3INF)
  store i64 0, ptr @dp, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([32768 x i64], ptr @dp, i64 0, i64 32767), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 14, ptr %1, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %15, %0
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = icmp sge i64 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %18

7:                                                ; preds = %3
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = sub nsw i64 15, %8
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = trunc i64 %10 to i32
  %12 = shl i32 1, %11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [32768 x i64], ptr @dp, i64 0, i64 %13
  store i64 %9, ptr %14, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %7
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = add nsw i64 %16, -1
  store i64 %17, ptr %1, align 8, !tbaa !5
  br label %3, !llvm.loop !9

18:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %26, %18
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = icmp slt i64 %20, 32768
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %29

23:                                               ; preds = %19
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = call noundef i64 @_Z7findMinl(i64 noundef %24)
  br label %26

26:                                               ; preds = %23
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %2, align 8, !tbaa !5
  br label %19, !llvm.loop !11

29:                                               ; preds = %22
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPllEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@dp = external dso_local global [32768 x i64], align 16
@_ZL3INF = external hidden constant i64, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z7findMinl(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
.preheader.preheader:
  tail call void @_ZSt4fillIPllEvT_S1_RKT0_(ptr noundef nonnull @dp, ptr noundef nonnull getelementptr inbounds (i8, ptr @dp, i64 262144), ptr noundef nonnull align 8 dereferenceable(8) @_ZL3INF)
  store i64 0, ptr @dp, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @dp, i64 262136), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @dp, i64 131072), align 16, !tbaa !5
  store i64 2, ptr getelementptr inbounds (i8, ptr @dp, i64 65536), align 16, !tbaa !5
  store i64 3, ptr getelementptr inbounds (i8, ptr @dp, i64 32768), align 16, !tbaa !5
  store i64 4, ptr getelementptr inbounds (i8, ptr @dp, i64 16384), align 16, !tbaa !5
  store i64 5, ptr getelementptr inbounds (i8, ptr @dp, i64 8192), align 16, !tbaa !5
  store i64 6, ptr getelementptr inbounds (i8, ptr @dp, i64 4096), align 16, !tbaa !5
  store i64 7, ptr getelementptr inbounds (i8, ptr @dp, i64 2048), align 16, !tbaa !5
  store i64 8, ptr getelementptr inbounds (i8, ptr @dp, i64 1024), align 16, !tbaa !5
  store i64 9, ptr getelementptr inbounds (i8, ptr @dp, i64 512), align 16, !tbaa !5
  store i64 10, ptr getelementptr inbounds (i8, ptr @dp, i64 256), align 16, !tbaa !5
  store i64 11, ptr getelementptr inbounds (i8, ptr @dp, i64 128), align 16, !tbaa !5
  store i64 12, ptr getelementptr inbounds (i8, ptr @dp, i64 64), align 16, !tbaa !5
  store i64 13, ptr getelementptr inbounds (i8, ptr @dp, i64 32), align 16, !tbaa !5
  store i64 14, ptr getelementptr inbounds (i8, ptr @dp, i64 16), align 16, !tbaa !5
  store i64 15, ptr getelementptr inbounds (i8, ptr @dp, i64 8), align 8, !tbaa !5
  br label %.preheader

0:                                                ; preds = %.preheader
  ret void

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.09 = phi i64 [ %2, %.preheader ], [ 0, %.preheader.preheader ]
  %1 = tail call noundef i64 @_Z7findMinl(i64 noundef %.09)
  %2 = add nuw nsw i64 %.09, 1
  %exitcond.not = icmp eq i64 %2, 32768
  br i1 %exitcond.not, label %0, label %.preheader, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPllEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass