; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions (PIE)

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

@n = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @func(x86_fp80 noundef, ptr 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: nounwind uwtable
define dso_local x86_fp80 @bs(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca x86_fp80, align 16
  %4 = alloca x86_fp80, align 16
  %5 = alloca x86_fp80, align 16
  %6 = alloca x86_fp80, align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #2
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !11
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds x86_fp80, ptr %7, i64 %10
  %12 = load x86_fp80, ptr %11, align 16, !tbaa !9
  store x86_fp80 %12, ptr %4, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #2
  store x86_fp80 0xK00000000000000000000, ptr %5, align 16, !tbaa !9
  br label %13

13:                                               ; preds = %31, %1
  %14 = load x86_fp80, ptr %4, align 16, !tbaa !9
  %15 = load x86_fp80, ptr %3, align 16, !tbaa !9
  %16 = fsub x86_fp80 %14, %15
  %17 = fcmp oge x86_fp80 %16, 0xK3FEB8637BD05AF6C6800
  br i1 %17, label %18, label %32

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  %19 = load x86_fp80, ptr %3, align 16, !tbaa !9
  %20 = load x86_fp80, ptr %4, align 16, !tbaa !9
  %21 = fadd x86_fp80 %19, %20
  %22 = fdiv x86_fp80 %21, 0xK40008000000000000000
  store x86_fp80 %22, ptr %6, align 16, !tbaa !9
  %23 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @func(x86_fp80 noundef %23, ptr noundef %24)
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %29

27:                                               ; preds = %18
  %28 = load x86_fp80, ptr %6, align 16, !tbaa !9
  store x86_fp80 %28, ptr %3, align 16, !tbaa !9
  br label %31

29:                                               ; preds = %18
  %30 = load x86_fp80, ptr %6, align 16, !tbaa !9
  store x86_fp80 %30, ptr %4, align 16, !tbaa !9
  br label %31

31:                                               ; preds = %29, %27
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  br label %13, !llvm.loop !13

32:                                               ; preds = %13
  %33 = load x86_fp80, ptr %3, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #2
  ret x86_fp80 %33
}

attributes #0 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @func(x86_fp80 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local x86_fp80 @bs(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr x86_fp80, ptr %0, i64 %3
  %5 = getelementptr i8, ptr %4, i64 -16
  %6 = load x86_fp80, ptr %5, align 16, !tbaa !9
  %7 = fcmp ult x86_fp80 %6, 0xK3FEB8637BD05AF6C6800
  br i1 %7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.014 = phi x86_fp80 [ %..0, %.lr.ph ], [ 0xK00000000000000000000, %1 ]
  %.01113 = phi x86_fp80 [ %.011., %.lr.ph ], [ %6, %1 ]
  %8 = fadd x86_fp80 %.01113, %.014
  %9 = fmul x86_fp80 %8, 0xK3FFE8000000000000000
  %10 = tail call i32 @func(x86_fp80 noundef %9, ptr noundef %0)
  %11 = icmp eq i32 %10, 1
  %.011. = select i1 %11, x86_fp80 %.01113, x86_fp80 %9
  %..0 = select i1 %11, x86_fp80 %9, x86_fp80 %.014
  %12 = fsub x86_fp80 %.011., %..0
  %13 = fcmp ult x86_fp80 %12, 0xK3FEB8637BD05AF6C6800
  br i1 %13, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.0.lcssa = phi x86_fp80 [ 0xK00000000000000000000, %1 ], [ %..0, %.lr.ph ]
  ret x86_fp80 %.0.lcssa
}

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

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


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