; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef/DEC2020-Long/VACCINE2.ll (Z4testv)

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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4testv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %1, ptr noundef %2)
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = call ptr @llvm.stacksave.p0()
  store ptr %13, ptr %3, align 8
  %14 = alloca i32, i64 %12, align 16
  store i64 %12, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %25, %0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %28

20:                                               ; preds = %15
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %14, i64 %22
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %23)
  br label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !9

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %50, %28
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %53

34:                                               ; preds = %29
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %14, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp sge i32 %38, 80
  br i1 %39, label %46, label %40

40:                                               ; preds = %34
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %14, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sle i32 %44, 9
  br i1 %45, label %46, label %49

46:                                               ; preds = %40, %34
  %47 = load double, ptr %6, align 8, !tbaa !11
  %48 = fadd double %47, 1.000000e+00
  store double %48, ptr %6, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %46, %40
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %9, align 4, !tbaa !5
  br label %29, !llvm.loop !13

53:                                               ; preds = %33
  %54 = load double, ptr %6, align 8, !tbaa !11
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = sitofp i32 %55 to double
  %57 = fsub double %54, %56
  %58 = call noundef double @_ZSt3absd(double noundef %57)
  store double %58, ptr %7, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %62, %53
  %60 = load double, ptr %6, align 8, !tbaa !11
  %61 = fcmp ogt double %60, 0.000000e+00
  br i1 %61, label %62, label %69

62:                                               ; preds = %59
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sitofp i32 %65 to double
  %67 = load double, ptr %6, align 8, !tbaa !11
  %68 = fsub double %67, %66
  store double %68, ptr %6, align 8, !tbaa !11
  br label %59, !llvm.loop !14

69:                                               ; preds = %59
  br label %70

70:                                               ; preds = %73, %69
  %71 = load double, ptr %7, align 8, !tbaa !11
  %72 = fcmp ogt double %71, 0.000000e+00
  br i1 %72, label %73, label %80

73:                                               ; preds = %70
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !5
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sitofp i32 %76 to double
  %78 = load double, ptr %7, align 8, !tbaa !11
  %79 = fsub double %78, %77
  store double %79, ptr %7, align 8, !tbaa !11
  br label %70, !llvm.loop !15

80:                                               ; preds = %70
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %81)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %83 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %83)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #4

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

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

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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4testv() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = call ptr @llvm.stacksave.p0()
  %7 = alloca i32, i64 %5, align 16
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.preheader23:                                     ; preds = %.lr.ph
  %10 = icmp sgt i32 %14, 0
  br i1 %10, label %.lr.ph27.preheader, label %._crit_edge

.lr.ph27.preheader:                               ; preds = %.preheader23
  %wide.trip.count = zext nneg i32 %14 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %14, 1
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph27.preheader.new

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

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph27, %.lr.ph27.preheader
  %.119.lcssa.ph = phi double [ poison, %.lr.ph27.preheader ], [ %.119.1, %.lr.ph27 ]
  %indvars.iv43.unr = phi i64 [ 0, %.lr.ph27.preheader ], [ %indvars.iv.next44.1, %.lr.ph27 ]
  %.01825.unr = phi double [ 0.000000e+00, %.lr.ph27.preheader ], [ %.119.1, %.lr.ph27 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph27.epil

.lr.ph27.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %17 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv43.unr
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add i32 %18, -80
  %or.cond.epil = icmp ult i32 %19, -70
  %20 = fadd double %.01825.unr, 1.000000e+00
  %.119.epil = select i1 %or.cond.epil, double %20, double %.01825.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph27.epil, %._crit_edge.loopexit.unr-lcssa, %0, %.preheader23
  %.lcssa47 = phi i32 [ %14, %.preheader23 ], [ %8, %0 ], [ %14, %._crit_edge.loopexit.unr-lcssa ], [ %14, %.lr.ph27.epil ]
  %.018.lcssa = phi double [ 0.000000e+00, %.preheader23 ], [ 0.000000e+00, %0 ], [ %.119.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.119.epil, %.lr.ph27.epil ]
  %21 = sitofp i32 %.lcssa47 to double
  %22 = fsub double %.018.lcssa, %21
  %23 = call noundef double @_ZSt3absd(double noundef %22)
  %24 = fcmp ogt double %.018.lcssa, 0.000000e+00
  br i1 %24, label %.lr.ph32, label %.preheader

.lr.ph32:                                         ; preds = %._crit_edge
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sitofp i32 %25 to double
  br label %38

.lr.ph27:                                         ; preds = %.lr.ph27, %.lr.ph27.preheader.new
  %indvars.iv43 = phi i64 [ 0, %.lr.ph27.preheader.new ], [ %indvars.iv.next44.1, %.lr.ph27 ]
  %.01825 = phi double [ 0.000000e+00, %.lr.ph27.preheader.new ], [ %.119.1, %.lr.ph27 ]
  %niter = phi i64 [ 0, %.lr.ph27.preheader.new ], [ %niter.next.1, %.lr.ph27 ]
  %27 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv43
  %28 = load i32, ptr %27, align 8, !tbaa !5
  %29 = add i32 %28, -80
  %or.cond = icmp ult i32 %29, -70
  %30 = fadd double %.01825, 1.000000e+00
  %.119 = select i1 %or.cond, double %30, double %.01825
  %indvars.iv.next44 = or disjoint i64 %indvars.iv43, 1
  %31 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next44
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add i32 %32, -80
  %or.cond.1 = icmp ult i32 %33, -70
  %34 = fadd double %.119, 1.000000e+00
  %.119.1 = select i1 %or.cond.1, double %34, double %.119
  %indvars.iv.next44.1 = add nuw nsw i64 %indvars.iv43, 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_edge.loopexit.unr-lcssa, label %.lr.ph27, !llvm.loop !11

.preheader:                                       ; preds = %38, %._crit_edge
  %.016.lcssa = phi i32 [ 0, %._crit_edge ], [ %39, %38 ]
  %35 = fcmp ogt double %23, 0.000000e+00
  br i1 %35, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %.preheader
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sitofp i32 %36 to double
  br label %42

38:                                               ; preds = %.lr.ph32, %38
  %.01630 = phi i32 [ 0, %.lr.ph32 ], [ %39, %38 ]
  %.229 = phi double [ %.018.lcssa, %.lr.ph32 ], [ %40, %38 ]
  %39 = add nuw nsw i32 %.01630, 1
  %40 = fsub double %.229, %26
  %41 = fcmp ogt double %40, 0.000000e+00
  br i1 %41, label %38, label %.preheader, !llvm.loop !12

42:                                               ; preds = %.lr.ph36, %42
  %.135 = phi i32 [ %.016.lcssa, %.lr.ph36 ], [ %43, %42 ]
  %.01734 = phi double [ %23, %.lr.ph36 ], [ %44, %42 ]
  %43 = add nuw nsw i32 %.135, 1
  %44 = fsub double %.01734, %37
  %45 = fcmp ogt double %44, 0.000000e+00
  br i1 %45, label %42, label %._crit_edge37, !llvm.loop !13

._crit_edge37:                                    ; preds = %42, %.preheader
  %.1.lcssa = phi i32 [ %.016.lcssa, %.preheader ], [ %43, %42 ]
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.1.lcssa)
  call void @llvm.stackrestore.p0(ptr %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret void
}

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

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #4

; 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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #5 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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