; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef (LCKYST)

; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

10:                                               ; preds = %53, %0
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = add nsw i64 %11, -1
  store i64 %12, ptr %2, align 8, !tbaa !5
  %13 = icmp ne i64 %11, 0
  br i1 %13, label %14, label %56

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = load i64, ptr %3, align 8, !tbaa !11
  store i64 %16, ptr %6, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %21, %14
  %18 = load i64, ptr %6, align 8, !tbaa !11
  %19 = srem i64 %18, 2
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %5, align 4, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !11
  %25 = sdiv i64 %24, 2
  store i64 %25, ptr %6, align 8, !tbaa !11
  br label %17, !llvm.loop !13

26:                                               ; preds = %17
  br label %27

27:                                               ; preds = %31, %26
  %28 = load i64, ptr %6, align 8, !tbaa !11
  %29 = srem i64 %28, 5
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %4, align 4, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !11
  %35 = sdiv i64 %34, 5
  store i64 %35, ptr %6, align 8, !tbaa !11
  br label %27, !llvm.loop !15

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sub nsw i32 %37, %38
  store i32 %39, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %50, %36
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  %44 = sdiv i32 %43, 2
  %45 = icmp slt i32 %41, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %53

47:                                               ; preds = %40
  %48 = load i64, ptr %3, align 8, !tbaa !11
  %49 = mul nsw i64 %48, 4
  store i64 %49, ptr %3, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %47
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !16

53:                                               ; preds = %46
  %54 = load i64, ptr %3, align 8, !tbaa !11
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %54)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %10, !llvm.loop !17

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

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

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

attributes #0 = { mustprogress norecurse 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 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

.lr.ph27:                                         ; preds = %0, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %7 = load i64, ptr %2, align 8, !tbaa !9
  %8 = and i64 %7, 1
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %.lr.ph, label %.preheader

.preheader.loopexit:                              ; preds = %.lr.ph
  %.neg = xor i32 %.01314, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.lr.ph27
  %.013.lcssa.neg = phi i32 [ 0, %.lr.ph27 ], [ %.neg, %.preheader.loopexit ]
  %.012.lcssa = phi i64 [ %7, %.lr.ph27 ], [ %13, %.preheader.loopexit ]
  %10 = srem i64 %.012.lcssa, 5
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.lr.ph19, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph27, %.lr.ph
  %.01215 = phi i64 [ %13, %.lr.ph ], [ %7, %.lr.ph27 ]
  %.01314 = phi i32 [ %12, %.lr.ph ], [ 0, %.lr.ph27 ]
  %12 = add nuw nsw i32 %.01314, 1
  %13 = ashr exact i64 %.01215, 1
  %14 = and i64 %.01215, 2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !11

.lr.ph19:                                         ; preds = %.preheader, %.lr.ph19
  %.01118 = phi i32 [ %16, %.lr.ph19 ], [ 0, %.preheader ]
  %.117 = phi i64 [ %17, %.lr.ph19 ], [ %.012.lcssa, %.preheader ]
  %16 = add nuw nsw i32 %.01118, 1
  %17 = sdiv i64 %.117, 5
  %18 = srem i64 %17, 5
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %.lr.ph19, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph19, %.preheader
  %.011.lcssa = phi i32 [ 0, %.preheader ], [ %16, %.lr.ph19 ]
  %20 = add i32 %.013.lcssa.neg, 1
  %21 = add i32 %20, %.011.lcssa
  %22 = sdiv i32 %21, 2
  %23 = icmp sgt i32 %21, 1
  br i1 %23, label %.lr.ph23.preheader, label %28

.lr.ph23.preheader:                               ; preds = %._crit_edge
  %24 = add nsw i32 %22, -1
  %xtraiter = and i32 %22, 7
  %25 = icmp ult i32 %24, 7
  br i1 %25, label %._crit_edge24.unr-lcssa, label %.lr.ph23.preheader.new

.lr.ph23.preheader.new:                           ; preds = %.lr.ph23.preheader
  %unroll_iter = and i32 %22, 1073741816
  br label %.lr.ph23

._crit_edge24.unr-lcssa:                          ; preds = %.lr.ph23, %.lr.ph23.preheader
  %.lcssa36.ph = phi i64 [ poison, %.lr.ph23.preheader ], [ %34, %.lr.ph23 ]
  %.unr = phi i64 [ %7, %.lr.ph23.preheader ], [ %34, %.lr.ph23 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge24, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %._crit_edge24.unr-lcssa, %.lr.ph23.epil
  %26 = phi i64 [ %27, %.lr.ph23.epil ], [ %.unr, %._crit_edge24.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph23.epil ], [ 0, %._crit_edge24.unr-lcssa ]
  %27 = shl nsw i64 %26, 2
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge24, label %.lr.ph23.epil, !llvm.loop !14

._crit_edge24:                                    ; preds = %.lr.ph23.epil, %._crit_edge24.unr-lcssa
  %.lcssa36 = phi i64 [ %.lcssa36.ph, %._crit_edge24.unr-lcssa ], [ %27, %.lr.ph23.epil ]
  store i64 %.lcssa36, ptr %2, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %._crit_edge24, %._crit_edge
  %29 = phi i64 [ %.lcssa36, %._crit_edge24 ], [ %7, %._crit_edge ]
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %29)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = add nsw i64 %31, -1
  store i64 %32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %31, 0
  br i1 %.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !16

.lr.ph23:                                         ; preds = %.lr.ph23, %.lr.ph23.preheader.new
  %33 = phi i64 [ %7, %.lr.ph23.preheader.new ], [ %34, %.lr.ph23 ]
  %niter = phi i32 [ 0, %.lr.ph23.preheader.new ], [ %niter.next.7, %.lr.ph23 ]
  %34 = shl i64 %33, 16
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge24.unr-lcssa, label %.lr.ph23, !llvm.loop !17

._crit_edge28:                                    ; preds = %28, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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", !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}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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