; LLVM IR from priyankchheda/algorithms :: _other_languages/cpp/Stack (deleteMiddleElement)

; 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::basic_ostream" = type { ptr, %"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 }
%"class.Stack::Stack" = type { ptr, i32, i32 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1

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

6:                                                ; preds = %14, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 11
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %11)
          to label %13 unwind label %17

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !9

17:                                               ; preds = %10
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %4, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %34

21:                                               ; preds = %9
  invoke void @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
          to label %22 unwind label %30

22:                                               ; preds = %21
  %23 = invoke noundef i32 @_ZN5Stack5StackIiE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
          to label %24 unwind label %30

24:                                               ; preds = %22
  invoke void @_Z12deleteMiddleRN5Stack5StackIiEEii(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %23, i32 noundef 0)
          to label %25 unwind label %30

25:                                               ; preds = %24
  %26 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
          to label %27 unwind label %30

27:                                               ; preds = %25
  invoke void @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
          to label %28 unwind label %30

28:                                               ; preds = %27
  call void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #5
  %29 = load i32, ptr %1, align 4
  ret i32 %29

30:                                               ; preds = %27, %25, %24, %22, %21
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %4, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %5, align 4
  br label %34

34:                                               ; preds = %30, %17
  call void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #5
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %4, align 8
  %37 = load i32, ptr %5, align 4
  %38 = insertvalue { ptr, i32 } poison, ptr %36, 0
  %39 = insertvalue { ptr, i32 } %38, i32 %37, 1
  resume { ptr, i32 } %39
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Stack5StackIiEC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

declare i32 @__gxx_personality_v0(...)

; 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 @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5Stack5StackIiE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

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


; 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::basic_ostream" = type { ptr, %"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 }
%"class.Stack::Stack" = type { ptr, i32, i32 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.Stack::Stack", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  call void @_ZN5Stack5StackIiEC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 10)
  %2 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 1)
          to label %3 unwind label %22

3:                                                ; preds = %0
  %4 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 2)
          to label %5 unwind label %22

5:                                                ; preds = %3
  %6 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 3)
          to label %7 unwind label %22

7:                                                ; preds = %5
  %8 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 4)
          to label %9 unwind label %22

9:                                                ; preds = %7
  %10 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 5)
          to label %11 unwind label %22

11:                                               ; preds = %9
  %12 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 6)
          to label %13 unwind label %22

13:                                               ; preds = %11
  %14 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 7)
          to label %15 unwind label %22

15:                                               ; preds = %13
  %16 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 8)
          to label %17 unwind label %22

17:                                               ; preds = %15
  %18 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 9)
          to label %19 unwind label %22

19:                                               ; preds = %17
  %20 = invoke noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef 10)
          to label %21 unwind label %22

21:                                               ; preds = %19
  invoke void @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
          to label %24 unwind label %30

22:                                               ; preds = %19, %17, %15, %13, %11, %9, %7, %5, %3, %0
  %23 = landingpad { ptr, i32 }
          cleanup
  br label %32

24:                                               ; preds = %21
  %25 = call noundef i32 @_ZN5Stack5StackIiE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  invoke void @_Z12deleteMiddleRN5Stack5StackIiEEii(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %25, i32 noundef 0)
          to label %26 unwind label %30

26:                                               ; preds = %24
  %27 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str)
          to label %28 unwind label %30

28:                                               ; preds = %26
  invoke void @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
          to label %29 unwind label %30

29:                                               ; preds = %28
  call void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  ret i32 0

30:                                               ; preds = %28, %26, %24, %21
  %31 = landingpad { ptr, i32 }
          cleanup
  br label %32

32:                                               ; preds = %30, %22
  %.pn = phi { ptr, i32 } [ %23, %22 ], [ %31, %30 ]
  call void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Stack5StackIiEC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5Stack5StackIiE4pushEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress 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 @_ZN5Stack5StackIiE7displayEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z12deleteMiddleRN5Stack5StackIiEEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5Stack5StackIiE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Stack5StackIiED2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3 align 2

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


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass