; LLVM IR from ahr9n/psolving-paradigms :: 3.binary-search/UVa 10341 - Solve it.ll (Z2bsv)

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

@lef = external dso_local global x86_fp80, align 16
@rig = external dso_local global x86_fp80, align 16
@mid = external dso_local global x86_fp80, align 16
@ans = external dso_local global x86_fp80, align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z3gete(x86_fp80 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z2bsv() #0 {
  store x86_fp80 0xK00000000000000000000, ptr @lef, align 16, !tbaa !5
  store x86_fp80 0xK3FFF8000000000000000, ptr @rig, align 16, !tbaa !5
  br label %1

1:                                                ; preds = %20, %0
  %2 = load x86_fp80, ptr @lef, align 16, !tbaa !5
  %3 = load x86_fp80, ptr @rig, align 16, !tbaa !5
  %4 = fcmp ole x86_fp80 %2, %3
  br i1 %4, label %5, label %21

5:                                                ; preds = %1
  %6 = load x86_fp80, ptr @lef, align 16, !tbaa !5
  %7 = load x86_fp80, ptr @rig, align 16, !tbaa !5
  %8 = fadd x86_fp80 %6, %7
  %9 = fdiv x86_fp80 %8, 0xK40008000000000000000
  store x86_fp80 %9, ptr @mid, align 16, !tbaa !5
  %10 = load x86_fp80, ptr @mid, align 16, !tbaa !5
  %11 = call noundef x86_fp80 @_Z3gete(x86_fp80 noundef %10)
  %12 = fcmp ogt x86_fp80 %11, 0xK00000000000000000000
  br i1 %12, label %13, label %17

13:                                               ; preds = %5
  %14 = load x86_fp80, ptr @mid, align 16, !tbaa !5
  store x86_fp80 %14, ptr @ans, align 16, !tbaa !5
  %15 = load x86_fp80, ptr @mid, align 16, !tbaa !5
  %16 = fadd x86_fp80 %15, 0xK3FDDDBE6FECEBDEDD800
  store x86_fp80 %16, ptr @lef, align 16, !tbaa !5
  br label %20

17:                                               ; preds = %5
  %18 = load x86_fp80, ptr @mid, align 16, !tbaa !5
  %19 = fsub x86_fp80 %18, 0xK3FDDDBE6FECEBDEDD800
  store x86_fp80 %19, ptr @rig, align 16, !tbaa !5
  br label %20

20:                                               ; preds = %17, %13
  br label %1, !llvm.loop !9

21:                                               ; preds = %1
  %22 = load x86_fp80, ptr @ans, align 16, !tbaa !5
  ret x86_fp80 %22
}

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

!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 double", !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"

@lef = external dso_local local_unnamed_addr global x86_fp80, align 16
@rig = external dso_local local_unnamed_addr global x86_fp80, align 16
@mid = external dso_local local_unnamed_addr global x86_fp80, align 16
@ans = external dso_local local_unnamed_addr global x86_fp80, align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z3gete(x86_fp80 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z2bsv() local_unnamed_addr #0 {
.lr.ph.preheader:
  store x86_fp80 0xK00000000000000000000, ptr @lef, align 16, !tbaa !5
  store x86_fp80 0xK3FFF8000000000000000, ptr @rig, align 16, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %11
  %0 = phi x86_fp80 [ %12, %11 ], [ 0xK3FFF8000000000000000, %.lr.ph.preheader ]
  %1 = phi x86_fp80 [ %13, %11 ], [ 0xK00000000000000000000, %.lr.ph.preheader ]
  %2 = fadd x86_fp80 %1, %0
  %3 = fmul x86_fp80 %2, 0xK3FFE8000000000000000
  store x86_fp80 %3, ptr @mid, align 16, !tbaa !5
  %4 = tail call noundef x86_fp80 @_Z3gete(x86_fp80 noundef %3)
  %5 = fcmp ogt x86_fp80 %4, 0xK00000000000000000000
  %6 = load x86_fp80, ptr @mid, align 16, !tbaa !5
  br i1 %5, label %7, label %9

7:                                                ; preds = %.lr.ph
  store x86_fp80 %6, ptr @ans, align 16, !tbaa !5
  %8 = fadd x86_fp80 %6, 0xK3FDDDBE6FECEBDEDD800
  store x86_fp80 %8, ptr @lef, align 16, !tbaa !5
  %.pre2 = load x86_fp80, ptr @rig, align 16, !tbaa !5
  br label %11

9:                                                ; preds = %.lr.ph
  %10 = fadd x86_fp80 %6, 0xKBFDDDBE6FECEBDEDD800
  store x86_fp80 %10, ptr @rig, align 16, !tbaa !5
  %.pre = load x86_fp80, ptr @lef, align 16, !tbaa !5
  br label %11

11:                                               ; preds = %9, %7
  %12 = phi x86_fp80 [ %10, %9 ], [ %.pre2, %7 ]
  %13 = phi x86_fp80 [ %.pre, %9 ], [ %8, %7 ]
  %14 = fcmp ugt x86_fp80 %13, %12
  br i1 %14, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %11
  %15 = load x86_fp80, ptr @ans, align 16, !tbaa !5
  ret x86_fp80 %15
}

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

!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 double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SimplifyCFGPass,TailCallElimPass