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

@pi = external dso_local global x86_fp80, align 16
@n = external dso_local global i32, align 4
@f = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local x86_fp80 @bs(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @sort(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca x86_fp80, align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %9

9:                                                ; preds = %61, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %2, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %66

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @f)
  %15 = load i32, ptr @f, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @f, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = call ptr @llvm.stacksave.p0()
  store ptr %19, ptr %4, align 8
  %20 = alloca i32, i64 %18, align 16
  store i64 %18, ptr %5, align 8
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %30, %13
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %33

25:                                               ; preds = %21
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %20, i64 %27
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %28)
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !9

33:                                               ; preds = %21
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = alloca x86_fp80, i64 %35, align 16
  store i64 %35, ptr %6, align 8
  %37 = load i32, ptr @n, align 4, !tbaa !5
  call void @sort(ptr noundef %20, i32 noundef %37)
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %58, %33
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %61

42:                                               ; preds = %38
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %20, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %20, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = mul nsw i32 %46, %50
  %52 = sitofp i32 %51 to x86_fp80
  %53 = load x86_fp80, ptr @pi, align 16, !tbaa !11
  %54 = fmul x86_fp80 %52, %53
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds x86_fp80, ptr %36, i64 %56
  store x86_fp80 %54, ptr %57, align 16, !tbaa !11
  br label %58

58:                                               ; preds = %42
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %38, !llvm.loop !13

61:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %62 = call x86_fp80 @bs(ptr noundef %36)
  store x86_fp80 %62, ptr %7, align 16, !tbaa !11
  %63 = load x86_fp80, ptr %7, align 16, !tbaa !11
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, x86_fp80 noundef %63)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  %65 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %65)
  br label %9, !llvm.loop !14

66:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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

@pi = external dso_local local_unnamed_addr global x86_fp80, align 16
@n = external dso_local global i32, align 4
@f = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local x86_fp80 @bs(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @sort(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr %1, align 4, !tbaa !5
  %.not15 = icmp eq i32 %3, 0
  br i1 %.not15, label %._crit_edge18, label %.lr.ph17

.lr.ph17:                                         ; preds = %0, %._crit_edge14
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @f)
  %6 = load i32, ptr @f, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @f, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = call ptr @llvm.stacksave.p0()
  %11 = alloca i32, i64 %9, align 16
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph17, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph17 ]
  %14 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph17
  %.lcssa = phi i32 [ %12, %.lr.ph17 ], [ %16, %.lr.ph ]
  %19 = zext i32 %.lcssa to i64
  %20 = alloca x86_fp80, i64 %19, align 16
  call void @sort(ptr noundef nonnull %11, i32 noundef %.lcssa)
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph13, label %._crit_edge14

.lr.ph13:                                         ; preds = %._crit_edge
  %23 = load x86_fp80, ptr @pi, align 16, !tbaa !11
  %wide.trip.count = zext nneg i32 %21 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %24 = icmp eq i32 %21, 1
  br i1 %24, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13.new

.lr.ph13.new:                                     ; preds = %.lr.ph13
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %25

25:                                               ; preds = %25, %.lr.ph13.new
  %indvars.iv21 = phi i64 [ 0, %.lr.ph13.new ], [ %indvars.iv.next22.1, %25 ]
  %niter = phi i64 [ 0, %.lr.ph13.new ], [ %niter.next.1, %25 ]
  %26 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv21
  %27 = load i32, ptr %26, align 8, !tbaa !5
  %28 = mul nsw i32 %27, %27
  %29 = uitofp nneg i32 %28 to x86_fp80
  %30 = fmul x86_fp80 %23, %29
  %31 = getelementptr inbounds x86_fp80, ptr %20, i64 %indvars.iv21
  store x86_fp80 %30, ptr %31, align 16, !tbaa !11
  %indvars.iv.next22 = or disjoint i64 %indvars.iv21, 1
  %32 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv.next22
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = mul nsw i32 %33, %33
  %35 = uitofp nneg i32 %34 to x86_fp80
  %36 = fmul x86_fp80 %23, %35
  %37 = getelementptr inbounds x86_fp80, ptr %20, i64 %indvars.iv.next22
  store x86_fp80 %36, ptr %37, align 16, !tbaa !11
  %indvars.iv.next22.1 = add nuw nsw i64 %indvars.iv21, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge14.loopexit.unr-lcssa, label %25, !llvm.loop !13

._crit_edge14.loopexit.unr-lcssa:                 ; preds = %25, %.lr.ph13
  %indvars.iv21.unr = phi i64 [ 0, %.lr.ph13 ], [ %indvars.iv.next22.1, %25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge14, label %._crit_edge14.loopexit.epilog-lcssa

._crit_edge14.loopexit.epilog-lcssa:              ; preds = %._crit_edge14.loopexit.unr-lcssa
  %38 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv21.unr
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = mul nsw i32 %39, %39
  %41 = uitofp nneg i32 %40 to x86_fp80
  %42 = fmul x86_fp80 %23, %41
  %43 = getelementptr inbounds x86_fp80, ptr %20, i64 %indvars.iv21.unr
  store x86_fp80 %42, ptr %43, align 16, !tbaa !11
  br label %._crit_edge14

._crit_edge14:                                    ; preds = %._crit_edge14.loopexit.epilog-lcssa, %._crit_edge14.loopexit.unr-lcssa, %._crit_edge
  %44 = call x86_fp80 @bs(ptr noundef nonnull %20)
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, x86_fp80 noundef %44)
  call void @llvm.stackrestore.p0(ptr %10)
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %46, 0
  br i1 %.not, label %._crit_edge18, label %.lr.ph17, !llvm.loop !14

._crit_edge18:                                    ; preds = %._crit_edge14, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nofree nounwind "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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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