; LLVM IR from VAR-solutions/Algorithms :: Searching/ternarySearch/cpp (ternarySearch)

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

@arr = external dso_local global [10000005 x i32], align 16
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14ternary_searchiii(i32 noundef, i32 noundef, i32 noundef) #0

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

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

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

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

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

10:                                               ; preds = %5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = mul nsw i32 %11, 2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10000005 x i32], ptr @arr, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !5
  br label %16

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

19:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = call noundef i32 @_Z14ternary_searchiii(i32 noundef 0, i32 noundef %20, i32 noundef 10)
  store i32 %21, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  br label %32

26:                                               ; preds = %19
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.1)
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %27, i32 noundef %29)
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %30, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %32

32:                                               ; preds = %26, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

; 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) #3

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #4

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

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 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 = { 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 #4 = { "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 }

@arr = external dso_local local_unnamed_addr global [10000005 x i32], align 16
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
vector.ph:
  store <4 x i32> <i32 0, i32 2, i32 4, i32 6>, ptr @arr, align 16, !tbaa !5
  store <4 x i32> <i32 8, i32 10, i32 12, i32 14>, ptr getelementptr inbounds (i8, ptr @arr, i64 16), align 16, !tbaa !5
  store <4 x i32> <i32 16, i32 18, i32 20, i32 22>, ptr getelementptr inbounds (i8, ptr @arr, i64 32), align 16, !tbaa !5
  store <4 x i32> <i32 24, i32 26, i32 28, i32 30>, ptr getelementptr inbounds (i8, ptr @arr, i64 48), align 16, !tbaa !5
  store <4 x i32> <i32 32, i32 34, i32 36, i32 38>, ptr getelementptr inbounds (i8, ptr @arr, i64 64), align 16, !tbaa !5
  store <4 x i32> <i32 40, i32 42, i32 44, i32 46>, ptr getelementptr inbounds (i8, ptr @arr, i64 80), align 16, !tbaa !5
  store <4 x i32> <i32 48, i32 50, i32 52, i32 54>, ptr getelementptr inbounds (i8, ptr @arr, i64 96), align 16, !tbaa !5
  store <4 x i32> <i32 56, i32 58, i32 60, i32 62>, ptr getelementptr inbounds (i8, ptr @arr, i64 112), align 16, !tbaa !5
  store <4 x i32> <i32 64, i32 66, i32 68, i32 70>, ptr getelementptr inbounds (i8, ptr @arr, i64 128), align 16, !tbaa !5
  store <4 x i32> <i32 72, i32 74, i32 76, i32 78>, ptr getelementptr inbounds (i8, ptr @arr, i64 144), align 16, !tbaa !5
  store <4 x i32> <i32 80, i32 82, i32 84, i32 86>, ptr getelementptr inbounds (i8, ptr @arr, i64 160), align 16, !tbaa !5
  store <4 x i32> <i32 88, i32 90, i32 92, i32 94>, ptr getelementptr inbounds (i8, ptr @arr, i64 176), align 16, !tbaa !5
  store <4 x i32> <i32 96, i32 98, i32 100, i32 102>, ptr getelementptr inbounds (i8, ptr @arr, i64 192), align 16, !tbaa !5
  store <4 x i32> <i32 104, i32 106, i32 108, i32 110>, ptr getelementptr inbounds (i8, ptr @arr, i64 208), align 16, !tbaa !5
  store <4 x i32> <i32 112, i32 114, i32 116, i32 118>, ptr getelementptr inbounds (i8, ptr @arr, i64 224), align 16, !tbaa !5
  store <4 x i32> <i32 120, i32 122, i32 124, i32 126>, ptr getelementptr inbounds (i8, ptr @arr, i64 240), align 16, !tbaa !5
  store <4 x i32> <i32 128, i32 130, i32 132, i32 134>, ptr getelementptr inbounds (i8, ptr @arr, i64 256), align 16, !tbaa !5
  store <4 x i32> <i32 136, i32 138, i32 140, i32 142>, ptr getelementptr inbounds (i8, ptr @arr, i64 272), align 16, !tbaa !5
  store <4 x i32> <i32 144, i32 146, i32 148, i32 150>, ptr getelementptr inbounds (i8, ptr @arr, i64 288), align 16, !tbaa !5
  store <4 x i32> <i32 152, i32 154, i32 156, i32 158>, ptr getelementptr inbounds (i8, ptr @arr, i64 304), align 16, !tbaa !5
  store <4 x i32> <i32 160, i32 162, i32 164, i32 166>, ptr getelementptr inbounds (i8, ptr @arr, i64 320), align 16, !tbaa !5
  store <4 x i32> <i32 168, i32 170, i32 172, i32 174>, ptr getelementptr inbounds (i8, ptr @arr, i64 336), align 16, !tbaa !5
  store <4 x i32> <i32 176, i32 178, i32 180, i32 182>, ptr getelementptr inbounds (i8, ptr @arr, i64 352), align 16, !tbaa !5
  store <4 x i32> <i32 184, i32 186, i32 188, i32 190>, ptr getelementptr inbounds (i8, ptr @arr, i64 368), align 16, !tbaa !5
  store i32 192, ptr getelementptr inbounds (i8, ptr @arr, i64 384), align 16, !tbaa !5
  store i32 194, ptr getelementptr inbounds (i8, ptr @arr, i64 388), align 4, !tbaa !5
  store i32 196, ptr getelementptr inbounds (i8, ptr @arr, i64 392), align 8, !tbaa !5
  store i32 198, ptr getelementptr inbounds (i8, ptr @arr, i64 396), align 4, !tbaa !5
  %0 = tail call noundef i32 @_Z14ternary_searchiii(i32 noundef 0, i32 noundef 100, i32 noundef 10)
  %1 = icmp eq i32 %0, -1
  br i1 %1, label %2, label %4

2:                                                ; preds = %vector.ph
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str)
  br label %9

4:                                                ; preds = %vector.ph
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.1)
  %6 = add nuw nsw i32 %0, 1
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %5, i32 noundef %6)
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %9

9:                                                ; preds = %4, %2
  ret i32 0
}

; 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 #2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #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 = { 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 #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 = { "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"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass