; LLVM IR from reyadussalahin/problem-solving :: math/combinatorics/loj/F1117 (Solution)

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

@d = external dso_local global [128 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3lcmxx(i64 noundef, i64 noundef) #1

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

14:                                               ; preds = %98, %0
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %101

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %32, %19
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %35

27:                                               ; preds = %22
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [128 x i64], ptr @d, i64 0, i64 %29
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %30)
  br label %32

32:                                               ; preds = %27
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !5
  br label %22, !llvm.loop !9

35:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %88, %35
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = shl i32 1, %38
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %91

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 1, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %64, %42
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %67

48:                                               ; preds = %43
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = shl i32 1, %50
  %52 = and i32 %49, %51
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %63

54:                                               ; preds = %48
  %55 = load i64, ptr %10, align 8, !tbaa !11
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [128 x i64], ptr @d, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !11
  %60 = call noundef i64 @_Z3lcmxx(i64 noundef %55, i64 noundef %59)
  store i64 %60, ptr %10, align 8, !tbaa !11
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %54, %48
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %12, align 4, !tbaa !5
  br label %43, !llvm.loop !13

67:                                               ; preds = %47
  %68 = load i32, ptr %11, align 4, !tbaa !5
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %87

70:                                               ; preds = %67
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = and i32 %71, 1
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %70
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = load i64, ptr %5, align 8, !tbaa !11
  %77 = load i64, ptr %10, align 8, !tbaa !11
  %78 = sdiv i64 %76, %77
  %79 = add nsw i64 %75, %78
  store i64 %79, ptr %8, align 8, !tbaa !11
  br label %86

80:                                               ; preds = %70
  %81 = load i64, ptr %8, align 8, !tbaa !11
  %82 = load i64, ptr %5, align 8, !tbaa !11
  %83 = load i64, ptr %10, align 8, !tbaa !11
  %84 = sdiv i64 %82, %83
  %85 = sub nsw i64 %81, %84
  store i64 %85, ptr %8, align 8, !tbaa !11
  br label %86

86:                                               ; preds = %80, %74
  br label %87

87:                                               ; preds = %86, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %9, align 4, !tbaa !5
  br label %36, !llvm.loop !14

91:                                               ; preds = %41
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  %94 = load i64, ptr %5, align 8, !tbaa !11
  %95 = load i64, ptr %8, align 8, !tbaa !11
  %96 = sub nsw i64 %94, %95
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %93, i64 noundef %96)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %98

98:                                               ; preds = %91
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !15

101:                                              ; preds = %18
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %102 = load i32, ptr %1, align 4
  ret i32 %102
}

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

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

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

@d = external dso_local global [128 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3lcmxx(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph46, label %._crit_edge47

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

.lr.ph46:                                         ; preds = %0, %._crit_edge42
  %.03044 = phi i32 [ %18, %._crit_edge42 ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader.preheader

.preheader33:                                     ; preds = %.lr.ph
  %.not48 = icmp eq i32 %13, 31
  br i1 %.not48, label %._crit_edge42, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph46, %.preheader33
  %.ph = phi i32 [ %9, %.lr.ph46 ], [ %13, %.preheader33 ]
  br label %.preheader

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

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge.thread
  %16 = phi i32 [ %47, %._crit_edge.thread ], [ %.ph, %.preheader.preheader ]
  %.02641 = phi i32 [ %48, %._crit_edge.thread ], [ 0, %.preheader.preheader ]
  %.02740 = phi i64 [ %.128, %._crit_edge.thread ], [ 0, %.preheader.preheader ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph38, label %._crit_edge.thread

._crit_edge42:                                    ; preds = %._crit_edge.thread, %.preheader33
  %.027.lcssa = phi i64 [ 0, %.preheader33 ], [ %.128, %._crit_edge.thread ]
  %18 = add nuw nsw i32 %.03044, 1
  %19 = load i64, ptr %2, align 8, !tbaa !11
  %20 = sub nsw i64 %19, %.027.lcssa
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %18, i64 noundef %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp slt i32 %18, %22
  br i1 %23, label %.lr.ph46, label %._crit_edge47, !llvm.loop !13

._crit_edge:                                      ; preds = %34
  %.not = icmp eq i32 %.1, 0
  br i1 %.not, label %._crit_edge.thread, label %39

.lr.ph38:                                         ; preds = %.preheader, %34
  %24 = phi i32 [ %35, %34 ], [ %16, %.preheader ]
  %25 = phi i32 [ %36, %34 ], [ %16, %.preheader ]
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %34 ], [ 0, %.preheader ]
  %.02336 = phi i32 [ %.1, %34 ], [ 0, %.preheader ]
  %.02435 = phi i64 [ %.125, %34 ], [ 1, %.preheader ]
  %26 = trunc nuw nsw i64 %indvars.iv50 to i32
  %27 = shl nuw i32 1, %26
  %28 = and i32 %27, %.02641
  %.not32 = icmp eq i32 %28, 0
  br i1 %.not32, label %34, label %29

29:                                               ; preds = %.lr.ph38
  %30 = getelementptr inbounds [128 x i64], ptr @d, i64 0, i64 %indvars.iv50
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = call noundef i64 @_Z3lcmxx(i64 noundef %.02435, i64 noundef %31)
  %33 = add nsw i32 %.02336, 1
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %.lr.ph38, %29
  %35 = phi i32 [ %.pre, %29 ], [ %24, %.lr.ph38 ]
  %36 = phi i32 [ %.pre, %29 ], [ %25, %.lr.ph38 ]
  %.125 = phi i64 [ %32, %29 ], [ %.02435, %.lr.ph38 ]
  %.1 = phi i32 [ %33, %29 ], [ %.02336, %.lr.ph38 ]
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next51, %37
  br i1 %38, label %.lr.ph38, label %._crit_edge, !llvm.loop !14

39:                                               ; preds = %._crit_edge
  %40 = and i32 %.1, 1
  %.not31 = icmp eq i32 %40, 0
  %41 = load i64, ptr %2, align 8, !tbaa !11
  %42 = sdiv i64 %41, %.125
  br i1 %.not31, label %45, label %43

43:                                               ; preds = %39
  %44 = add nsw i64 %42, %.02740
  br label %._crit_edge.thread

45:                                               ; preds = %39
  %46 = sub nsw i64 %.02740, %42
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader, %43, %45, %._crit_edge
  %47 = phi i32 [ %35, %43 ], [ %35, %45 ], [ %35, %._crit_edge ], [ %16, %.preheader ]
  %.128 = phi i64 [ %44, %43 ], [ %46, %45 ], [ %.02740, %._crit_edge ], [ %.02740, %.preheader ]
  %48 = add nuw nsw i32 %.02641, 1
  %49 = shl nuw i32 1, %47
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %.preheader, label %._crit_edge42, !llvm.loop !15
}

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

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

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


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