; LLVM IR from Mohammed-Shoaib/Coding-Problems :: HackerRank/Algorithms/Easy/E0083.ll (Z13maximizingXorii)

; 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::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { i64 }
%"class.std::bitset<32>::reference" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z13maximizingXorii(i32 noundef %0, i32 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.std::bitset", align 8
  %8 = alloca %"class.std::bitset", align 8
  %9 = alloca %"class.std::bitset<32>::reference", align 8
  %10 = alloca i1, align 1
  %11 = alloca i1, align 1
  %12 = alloca %"class.std::bitset<32>::reference", align 8
  %13 = alloca i1, align 1
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i1, align 1
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  call void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  call void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8) %8, i64 noundef %20) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 31, ptr %6, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %49, %2
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp sge i32 %22, 0
  store i1 false, ptr %10, align 1
  store i1 false, ptr %11, align 1
  store i1 false, ptr %13, align 1
  store i1 false, ptr %16, align 1
  br i1 %23, label %24, label %35

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  store i1 true, ptr %10, align 1
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  call void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<32>::reference") align 8 %9, ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %26)
  store i1 true, ptr %11, align 1
  %27 = call noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  %28 = zext i1 %27 to i32
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #3
  store i1 true, ptr %13, align 1
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  invoke void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<32>::reference") align 8 %12, ptr noundef nonnull align 8 dereferenceable(8) %8, i64 noundef %30)
          to label %31 unwind label %52

31:                                               ; preds = %24
  store i1 true, ptr %16, align 1
  %32 = call noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %12) #3
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %28, %33
  br label %35

35:                                               ; preds = %31, %21
  %36 = phi i1 [ false, %21 ], [ %34, %31 ]
  %37 = load i1, ptr %16, align 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @_ZNSt6bitsetILm32EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %12) #3
  br label %39

39:                                               ; preds = %38, %35
  %40 = load i1, ptr %13, align 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  br label %42

42:                                               ; preds = %41, %39
  %43 = load i1, ptr %11, align 1
  br i1 %43, label %44, label %45

44:                                               ; preds = %42
  call void @_ZNSt6bitsetILm32EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  br label %45

45:                                               ; preds = %44, %42
  %46 = load i1, ptr %10, align 1
  br i1 %46, label %47, label %48

47:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %48

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

49:                                               ; preds = %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %6, align 4, !tbaa !5
  br label %21, !llvm.loop !9

52:                                               ; preds = %24
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %14, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %15, align 4
  %56 = load i1, ptr %13, align 1
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  br label %58

58:                                               ; preds = %57, %52
  %59 = load i1, ptr %11, align 1
  br i1 %59, label %60, label %61

60:                                               ; preds = %58
  call void @_ZNSt6bitsetILm32EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  br label %61

61:                                               ; preds = %60, %58
  %62 = load i1, ptr %10, align 1
  br i1 %62, label %63, label %64

63:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %64

64:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %78

65:                                               ; preds = %48
  br label %66

66:                                               ; preds = %69, %65
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = icmp sge i32 %67, 0
  br i1 %68, label %69, label %76

69:                                               ; preds = %66
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = shl i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = xor i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %6, align 4, !tbaa !5
  br label %66, !llvm.loop !11

76:                                               ; preds = %66
  %77 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %77

78:                                               ; preds = %64
  %79 = load ptr, ptr %14, align 8
  %80 = load i32, ptr %15, align 4
  %81 = insertvalue { ptr, i32 } poison, ptr %79, 0
  %82 = insertvalue { ptr, i32 } %81, i32 %80, 1
  resume { ptr, i32 } %82
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<32>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"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::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { i64 }
%"class.std::bitset<32>::reference" = type { ptr, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z13maximizingXorii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.std::bitset", align 8
  %4 = alloca %"class.std::bitset", align 8
  %5 = alloca %"class.std::bitset<32>::reference", align 8
  %6 = alloca %"class.std::bitset<32>::reference", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %7 = sext i32 %0 to i64
  call void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %8 = sext i32 %1 to i64
  call void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %8) #2
  br label %.critedge

.critedge20.preheader:                            ; preds = %.critedge
  %9 = icmp sgt i64 %indvars.iv, -1
  br i1 %9, label %.critedge20.preheader31, label %.critedge20._crit_edge

.critedge20.preheader31:                          ; preds = %.critedge20.preheader
  %10 = trunc i64 %indvars.iv to i32
  %11 = sub i32 32, %indvar
  %xtraiter = and i32 %11, 7
  %12 = icmp ult i32 %10, 7
  br i1 %12, label %.critedge20._crit_edge.loopexit.unr-lcssa, label %.critedge20.preheader31.new

.critedge20.preheader31.new:                      ; preds = %.critedge20.preheader31
  %unroll_iter = and i32 %11, -8
  br label %.critedge20

.critedge:                                        ; preds = %2, %16
  %indvar = phi i32 [ 0, %2 ], [ %indvar.next, %16 ]
  %indvars.iv = phi i64 [ 31, %2 ], [ %indvars.iv.next, %16 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #2
  call void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<32>::reference") align 8 %5, ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %indvars.iv)
  %13 = call noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  call void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<32>::reference") align 8 %6, ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %indvars.iv)
  %14 = call noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #2
  %15 = xor i1 %13, %14
  call void @_ZNSt6bitsetILm32EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  call void @_ZNSt6bitsetILm32EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #2
  br i1 %15, label %.critedge20.preheader, label %16

16:                                               ; preds = %.critedge
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not = icmp eq i64 %indvars.iv, 0
  %indvar.next = add i32 %indvar, 1
  br i1 %.not, label %.critedge20._crit_edge, label %.critedge, !llvm.loop !5

.critedge20:                                      ; preds = %.critedge20, %.critedge20.preheader31.new
  %.01822 = phi i32 [ 0, %.critedge20.preheader31.new ], [ %18, %.critedge20 ]
  %niter = phi i32 [ 0, %.critedge20.preheader31.new ], [ %niter.next.7, %.critedge20 ]
  %17 = shl i32 %.01822, 8
  %18 = or disjoint i32 %17, 255
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.critedge20._crit_edge.loopexit.unr-lcssa, label %.critedge20, !llvm.loop !7

.critedge20._crit_edge.loopexit.unr-lcssa:        ; preds = %.critedge20, %.critedge20.preheader31
  %.lcssa.ph = phi i32 [ poison, %.critedge20.preheader31 ], [ %18, %.critedge20 ]
  %.01822.unr = phi i32 [ 0, %.critedge20.preheader31 ], [ %18, %.critedge20 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.critedge20._crit_edge, label %.critedge20.epil

.critedge20.epil:                                 ; preds = %.critedge20._crit_edge.loopexit.unr-lcssa, %.critedge20.epil
  %.01822.epil = phi i32 [ %20, %.critedge20.epil ], [ %.01822.unr, %.critedge20._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.critedge20.epil ], [ 0, %.critedge20._crit_edge.loopexit.unr-lcssa ]
  %19 = shl i32 %.01822.epil, 1
  %20 = or disjoint i32 %19, 1
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.critedge20._crit_edge, label %.critedge20.epil, !llvm.loop !8

.critedge20._crit_edge:                           ; preds = %16, %.critedge20._crit_edge.loopexit.unr-lcssa, %.critedge20.epil, %.critedge20.preheader
  %.018.lcssa = phi i32 [ 0, %.critedge20.preheader ], [ %.lcssa.ph, %.critedge20._crit_edge.loopexit.unr-lcssa ], [ %20, %.critedge20.epil ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i32 %.018.lcssa
}

; 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 nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm32EEC2Ey(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm32EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<32>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm32EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

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

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass