; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/278 Division 1/Problem C (C)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4fastxxx(i64 noundef, i64 noundef, i64 noundef) #0

; 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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %12

9:                                                ; preds = %0
  %10 = call i32 @puts(ptr noundef @.str.1)
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %77

12:                                               ; preds = %0
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 4
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = call i32 @puts(ptr noundef @.str.1)
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %76

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  store i8 1, ptr %2, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %33, %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = mul nsw i32 %20, %21
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %36

26:                                               ; preds = %19
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = srem i32 %27, %28
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i8 0, ptr %2, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %31, %26
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !11

36:                                               ; preds = %25
  %37 = load i8, ptr %2, align 1, !tbaa !9, !range !13, !noundef !14
  %38 = trunc i8 %37 to i1
  br i1 %38, label %41, label %39

39:                                               ; preds = %36
  %40 = call i32 @puts(ptr noundef @.str.4)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %73

41:                                               ; preds = %36
  %42 = call i32 @puts(ptr noundef @.str.1)
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 2, ptr %5, align 8, !tbaa !15
  br label %44

44:                                               ; preds = %67, %41
  %45 = load i64, ptr %5, align 8, !tbaa !15
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %44
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %70

50:                                               ; preds = %44
  %51 = load i64, ptr %5, align 8, !tbaa !15
  %52 = mul nsw i64 1, %51
  %53 = load i64, ptr %5, align 8, !tbaa !15
  %54 = sub nsw i64 %53, 1
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 2
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = call noundef i64 @_Z4fastxxx(i64 noundef %54, i64 noundef %57, i64 noundef %59)
  %61 = mul nsw i64 %52, %60
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = srem i64 %61, %63
  %65 = trunc i64 %64 to i32
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %65)
  br label %67

67:                                               ; preds = %50
  %68 = load i64, ptr %5, align 8, !tbaa !15
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %5, align 8, !tbaa !15
  br label %44, !llvm.loop !17

70:                                               ; preds = %49
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %71)
  store i32 0, ptr %4, align 4
  br label %73

73:                                               ; preds = %70, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #4
  %74 = load i32, ptr %4, align 4
  switch i32 %74, label %80 [
    i32 0, label %75
    i32 1, label %78
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %15
  br label %77

77:                                               ; preds = %76, %9
  store i32 0, ptr %1, align 4
  br label %78

78:                                               ; preds = %77, %73
  %79 = load i32, ptr %1, align 4
  ret i32 %79

80:                                               ; preds = %73
  unreachable
}

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

declare i32 @puts(ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !12}


; 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 global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4fastxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  switch i32 %2, label %.preheader [
    i32 1, label %3
    i32 4, label %6
  ]

.preheader:                                       ; preds = %0
  %.not19 = icmp slt i32 %2, 4
  br i1 %.not19, label %.critedge, label %.lr.ph

3:                                                ; preds = %0
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %37

6:                                                ; preds = %0
  %7 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %37

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %spec.select, label %.critedge, label %13

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01221 = phi i32 [ %11, %.lr.ph ], [ 2, %.preheader ]
  %.01320 = phi i1 [ %spec.select, %.lr.ph ], [ true, %.preheader ]
  %9 = urem i32 %2, %.01221
  %10 = icmp ne i32 %9, 0
  %spec.select = select i1 %10, i1 %.01320, i1 false
  %11 = add nuw nsw i32 %.01221, 1
  %12 = mul nuw nsw i32 %11, %11
  %.not = icmp sgt i32 %12, %2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

13:                                               ; preds = %._crit_edge
  %14 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %37

.critedge:                                        ; preds = %.preheader, %._crit_edge
  %15 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 2
  br i1 %18, label %.lr.ph24.preheader, label %._crit_edge25

.lr.ph24.preheader:                               ; preds = %.critedge
  %19 = zext nneg i32 %17 to i64
  br label %.lr.ph24

._crit_edge25:                                    ; preds = %.lr.ph24, %.critedge
  %.lcssa = phi i32 [ %17, %.critedge ], [ %34, %.lr.ph24 ]
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %.lcssa)
  br label %37

.lr.ph24:                                         ; preds = %.lr.ph24.preheader, %.lr.ph24
  %21 = phi i64 [ %35, %.lr.ph24 ], [ %19, %.lr.ph24.preheader ]
  %22 = phi i32 [ %34, %.lr.ph24 ], [ %17, %.lr.ph24.preheader ]
  %.022 = phi i64 [ %33, %.lr.ph24 ], [ 2, %.lr.ph24.preheader ]
  %23 = add nsw i64 %.022, -1
  %24 = add nsw i32 %22, -2
  %25 = sext i32 %24 to i64
  %26 = tail call noundef i64 @_Z4fastxxx(i64 noundef %23, i64 noundef %25, i64 noundef %21)
  %27 = mul nsw i64 %26, %.022
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = srem i64 %27, %29
  %31 = trunc nsw i64 %30 to i32
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %31)
  %33 = add nuw nsw i64 %.022, 1
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %33, %35
  br i1 %36, label %.lr.ph24, label %._crit_edge25, !llvm.loop !11

37:                                               ; preds = %13, %._crit_edge25, %3, %6
  ret i32 0
}

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

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

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

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 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 #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" }

!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}


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