; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1155. Heap Paths (30) (main)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@v = external dso_local global %"class.std::vector", align 8
@a = external dso_local global [1009 x i32], align 16
@n = external dso_local global i32, align 4
@isMin = external dso_local global i32, align 4
@isMax = external dso_local global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

declare i32 @printf(ptr noundef, ...) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %18

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %13)
  br label %15

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) getelementptr inbounds ([1009 x i32], ptr @a, i64 0, i64 1))
  call void @_Z3dfsi(i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %49, %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %52

24:                                               ; preds = %19
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sdiv i32 %25, 2
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp sgt i32 %29, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %24
  store i32 0, ptr @isMin, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %35, %24
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sdiv i32 %37, 2
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp slt i32 %41, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %36
  store i32 0, ptr @isMax, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %47, %36
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !11

52:                                               ; preds = %23
  %53 = load i32, ptr @isMin, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 1
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %66

57:                                               ; preds = %52
  %58 = load i32, ptr @isMax, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  br label %62

61:                                               ; preds = %57
  br label %62

62:                                               ; preds = %61, %60
  %63 = phi ptr [ @.str.7, %60 ], [ @.str.8, %61 ]
  %64 = getelementptr inbounds [9 x i8], ptr %63, i64 0, i64 0
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %64)
  br label %66

66:                                               ; preds = %62, %55
  ret i32 0
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { mustprogress norecurse 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 = !{!"int", !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@v = external dso_local global %"class.std::vector", align 8
@a = external dso_local global [1009 x i32], align 16
@n = external dso_local global i32, align 4
@isMin = external dso_local local_unnamed_addr global i32, align 4
@isMax = external dso_local local_unnamed_addr global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not11 = icmp slt i32 %2, 1
  br i1 %.not11, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) getelementptr inbounds (i8, ptr @a, i64 4))
  tail call void @_Z3dfsi(i32 noundef 1)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not1013 = icmp slt i32 %3, 2
  br i1 %.not1013, label %._crit_edge17, label %.lr.ph16.preheader

.lr.ph16.preheader:                               ; preds = %._crit_edge
  %4 = add nuw i32 %3, 1
  %wide.trip.count = zext i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %5 = icmp eq i32 %4, 3
  br i1 %5, label %._crit_edge17.loopexit.unr-lcssa, label %.lr.ph16.preheader.new

.lr.ph16.preheader.new:                           ; preds = %.lr.ph16.preheader
  %6 = and i64 %wide.trip.count, 4294967294
  %7 = add nsw i64 %6, -4
  br label %.lr.ph16

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %8 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %.not.not = icmp slt i64 %indvars.iv, %11
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge17.loopexit.unr-lcssa:                 ; preds = %47, %.lr.ph16.preheader
  %indvars.iv19.unr = phi i64 [ 2, %.lr.ph16.preheader ], [ %indvars.iv.next20.1, %47 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge17, label %.lr.ph16.epil

.lr.ph16.epil:                                    ; preds = %._crit_edge17.loopexit.unr-lcssa
  %12 = lshr i64 %indvars.iv19.unr, 1
  %13 = and i64 %12, 2147483647
  %14 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %indvars.iv19.unr
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp sgt i32 %15, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %.lr.ph16.epil
  store i32 0, ptr @isMin, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %.lr.ph16.epil
  %21 = icmp slt i32 %15, %17
  br i1 %21, label %22, label %._crit_edge17

22:                                               ; preds = %20
  store i32 0, ptr @isMax, align 4, !tbaa !5
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %._crit_edge17.loopexit.unr-lcssa, %22, %20, %._crit_edge
  %23 = load i32, ptr @isMin, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %48, label %50

.lr.ph16:                                         ; preds = %47, %.lr.ph16.preheader.new
  %indvars.iv19 = phi i64 [ 2, %.lr.ph16.preheader.new ], [ %indvars.iv.next20.1, %47 ]
  %niter = phi i64 [ 0, %.lr.ph16.preheader.new ], [ %niter.next.1, %47 ]
  %25 = lshr exact i64 %indvars.iv19, 1
  %26 = and i64 %25, 2147483647
  %27 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %indvars.iv19
  %30 = load i32, ptr %29, align 8, !tbaa !5
  %31 = icmp sgt i32 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %.lr.ph16
  store i32 0, ptr @isMin, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %.lr.ph16
  %34 = icmp slt i32 %28, %30
  br i1 %34, label %35, label %.lr.ph16.1

35:                                               ; preds = %33
  store i32 0, ptr @isMax, align 4, !tbaa !5
  br label %.lr.ph16.1

.lr.ph16.1:                                       ; preds = %33, %35
  %indvars.iv.next20 = or disjoint i64 %indvars.iv19, 1
  %36 = lshr exact i64 %indvars.iv19, 1
  %37 = and i64 %36, 2147483647
  %38 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = getelementptr inbounds [1009 x i32], ptr @a, i64 0, i64 %indvars.iv.next20
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp sgt i32 %39, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %.lr.ph16.1
  store i32 0, ptr @isMin, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %43, %.lr.ph16.1
  %45 = icmp slt i32 %39, %41
  br i1 %45, label %46, label %47

46:                                               ; preds = %44
  store i32 0, ptr @isMax, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %46, %44
  %indvars.iv.next20.1 = add nuw nsw i64 %indvars.iv19, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %7
  br i1 %niter.ncmp.1, label %._crit_edge17.loopexit.unr-lcssa, label %.lr.ph16, !llvm.loop !11

48:                                               ; preds = %._crit_edge17
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %54

50:                                               ; preds = %._crit_edge17
  %51 = load i32, ptr @isMax, align 4, !tbaa !5
  %52 = icmp eq i32 %51, 1
  %.str.7..str.8 = select i1 %52, ptr @.str.7, ptr @.str.8
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %.str.7..str.8)
  br label %54

54:                                               ; preds = %50, %48
  ret i32 0
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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 = { nofree nounwind "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 = { mustprogress norecurse 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 = { "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 = !{!"int", !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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass