; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/CODECRCK/A.ll (Z4fastex)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef x86_fp80 @_Z4fastex(x86_fp80 noundef %0, i64 noundef %1) #0 {
  %3 = alloca x86_fp80, align 16
  %4 = alloca i64, align 8
  %5 = alloca x86_fp80, align 16
  store x86_fp80 %0, ptr %3, align 16, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #2
  store x86_fp80 0xK3FFF8000000000000000, ptr %5, align 16, !tbaa !5
  %6 = load i64, ptr %4, align 8, !tbaa !9
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %8, label %27

8:                                                ; preds = %2
  br label %9

9:                                                ; preds = %20, %8
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %26

12:                                               ; preds = %9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = and i64 %13, 1
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %18 = load x86_fp80, ptr %5, align 16, !tbaa !5
  %19 = fmul x86_fp80 %18, %17
  store x86_fp80 %19, ptr %5, align 16, !tbaa !5
  br label %20

20:                                               ; preds = %16, %12
  %21 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %22 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %23 = fmul x86_fp80 %22, %21
  store x86_fp80 %23, ptr %3, align 16, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = ashr i64 %24, 1
  store i64 %25, ptr %4, align 8, !tbaa !9
  br label %9, !llvm.loop !11

26:                                               ; preds = %9
  br label %52

27:                                               ; preds = %2
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %30, label %51

30:                                               ; preds = %27
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = sub nsw i64 0, %31
  store i64 %32, ptr %4, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %44, %30
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %33
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = and i64 %37, 1
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %36
  %41 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %42 = load x86_fp80, ptr %5, align 16, !tbaa !5
  %43 = fdiv x86_fp80 %42, %41
  store x86_fp80 %43, ptr %5, align 16, !tbaa !5
  br label %44

44:                                               ; preds = %40, %36
  %45 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %46 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %47 = fmul x86_fp80 %46, %45
  store x86_fp80 %47, ptr %3, align 16, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = ashr i64 %48, 1
  store i64 %49, ptr %4, align 8, !tbaa !9
  br label %33, !llvm.loop !13

50:                                               ; preds = %33
  br label %51

51:                                               ; preds = %50, %27
  br label %52

52:                                               ; preds = %51, %26
  %53 = load x86_fp80, ptr %5, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #2
  ret x86_fp80 %53
}

; 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

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


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef x86_fp80 @_Z4fastex(x86_fp80 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, 0
  br i1 %3, label %.preheader, label %8

.preheader:                                       ; preds = %2, %.preheader
  %.032 = phi x86_fp80 [ %spec.select, %.preheader ], [ 0xK3FFF8000000000000000, %2 ]
  %.01731 = phi x86_fp80 [ %6, %.preheader ], [ %0, %2 ]
  %.01930 = phi i64 [ %7, %.preheader ], [ %1, %2 ]
  %4 = and i64 %.01930, 1
  %.not25 = icmp eq i64 %4, 0
  %5 = fmul x86_fp80 %.01731, %.032
  %spec.select = select i1 %.not25, x86_fp80 %.032, x86_fp80 %5
  %6 = fmul x86_fp80 %.01731, %.01731
  %7 = lshr i64 %.01930, 1
  %.not24 = icmp ult i64 %.01930, 2
  br i1 %.not24, label %.loopexit, label %.preheader, !llvm.loop !5

8:                                                ; preds = %2
  %9 = icmp slt i64 %1, 0
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %8
  %11 = sub nsw i64 0, %1
  br label %12

12:                                               ; preds = %10, %12
  %.229 = phi x86_fp80 [ 0xK3FFF8000000000000000, %10 ], [ %.3, %12 ]
  %.11828 = phi x86_fp80 [ %0, %10 ], [ %15, %12 ]
  %.12027 = phi i64 [ %11, %10 ], [ %16, %12 ]
  %13 = and i64 %.12027, 1
  %.not23 = icmp eq i64 %13, 0
  %14 = fdiv x86_fp80 %.229, %.11828
  %.3 = select i1 %.not23, x86_fp80 %.229, x86_fp80 %14
  %15 = fmul x86_fp80 %.11828, %.11828
  %16 = lshr i64 %.12027, 1
  %.not = icmp ult i64 %.12027, 2
  br i1 %.not, label %.loopexit, label %12, !llvm.loop !7

.loopexit:                                        ; preds = %12, %.preheader, %8
  %.4 = phi x86_fp80 [ 0xK3FFF8000000000000000, %8 ], [ %spec.select, %.preheader ], [ %.3, %12 ]
  ret x86_fp80 %.4
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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