; 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
@f = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @func(x86_fp80 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca x86_fp80, align 16
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store x86_fp80 %0, ptr %4, align 16, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %10 = fcmp oeq x86_fp80 %9, 0xK00000000000000000000
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %37

12:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %28, %12
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = load i32, ptr @n, align 4, !tbaa !11
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %31

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds x86_fp80, ptr %18, i64 %20
  %22 = load x86_fp80, ptr %21, align 16, !tbaa !5
  %23 = load x86_fp80, ptr %4, align 16, !tbaa !5
  %24 = fdiv x86_fp80 %22, %23
  %25 = fptosi x86_fp80 %24 to i32
  %26 = load i32, ptr %6, align 4, !tbaa !11
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %6, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %17
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !11
  br label %13, !llvm.loop !13

31:                                               ; preds = %13
  %32 = load i32, ptr %6, align 4, !tbaa !11
  %33 = load i32, ptr @f, align 4, !tbaa !11
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %37

36:                                               ; preds = %31
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %37

37:                                               ; preds = %36, %35, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

; 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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
@f = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @func(x86_fp80 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = fcmp oeq x86_fp80 %0, 0xK00000000000000000000
  br i1 %3, label %33, label %.preheader

.preheader:                                       ; preds = %2
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %6 = icmp ult i32 %4, 4
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.0811 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %7 = getelementptr inbounds x86_fp80, ptr %1, i64 %indvars.iv
  %8 = load x86_fp80, ptr %7, align 16, !tbaa !9
  %9 = fdiv x86_fp80 %8, %0
  %10 = fptosi x86_fp80 %9 to i32
  %11 = add nsw i32 %.0811, %10
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = getelementptr inbounds x86_fp80, ptr %1, i64 %indvars.iv.next
  %13 = load x86_fp80, ptr %12, align 16, !tbaa !9
  %14 = fdiv x86_fp80 %13, %0
  %15 = fptosi x86_fp80 %14 to i32
  %16 = add nsw i32 %11, %15
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %17 = getelementptr inbounds x86_fp80, ptr %1, i64 %indvars.iv.next.1
  %18 = load x86_fp80, ptr %17, align 16, !tbaa !9
  %19 = fdiv x86_fp80 %18, %0
  %20 = fptosi x86_fp80 %19 to i32
  %21 = add nsw i32 %16, %20
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %22 = getelementptr inbounds x86_fp80, ptr %1, i64 %indvars.iv.next.2
  %23 = load x86_fp80, ptr %22, align 16, !tbaa !9
  %24 = fdiv x86_fp80 %23, %0
  %25 = fptosi x86_fp80 %24 to i32
  %26 = add nsw i32 %21, %25
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.0811.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0811.epil = phi i32 [ %31, %.lr.ph.epil ], [ %.0811.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %27 = getelementptr inbounds x86_fp80, ptr %1, i64 %indvars.iv.epil
  %28 = load x86_fp80, ptr %27, align 16, !tbaa !9
  %29 = fdiv x86_fp80 %28, %0
  %30 = fptosi x86_fp80 %29 to i32
  %31 = add nsw i32 %.0811.epil, %30
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader
  %.08.lcssa = phi i32 [ 0, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %31, %.lr.ph.epil ]
  %32 = load i32, ptr @f, align 4, !tbaa !5
  %.not = icmp sge i32 %.08.lcssa, %32
  %. = zext i1 %.not to i32
  br label %33

33:                                               ; preds = %._crit_edge, %2
  %.09 = phi i32 [ 0, %2 ], [ %., %._crit_edge ]
  ret i32 %.09
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: 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 = !{!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"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


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