; LLVM IR from tangjz/acm-icpc :: codeforces (487C)

; 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
@inv = external dso_local global [131072 x i64], align 16
@.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 [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

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

8:                                                ; preds = %0
  %9 = call i32 @puts(ptr noundef @.str.1)
  br label %82

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

13:                                               ; preds = %10
  %14 = call i32 @puts(ptr noundef @.str.2)
  br label %81

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %31, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = mul nsw i32 %17, %18
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 2, ptr %3, align 4
  br label %34

23:                                               ; preds = %16
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = srem i32 %24, %25
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = call i32 @puts(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %34

30:                                               ; preds = %23
  br label %31

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

34:                                               ; preds = %28, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %35 = load i32, ptr %3, align 4
  switch i32 %35, label %85 [
    i32 2, label %36
    i32 1, label %83
  ]

36:                                               ; preds = %34
  %37 = call i32 @puts(ptr noundef @.str.1)
  store i64 1, ptr getelementptr inbounds ([131072 x i64], ptr @inv, i64 0, i64 1), align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %75, %36
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %78

43:                                               ; preds = %38
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [131072 x i64], ptr @inv, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = mul nsw i64 %45, %50
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = srem i64 %51, %53
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %54)
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sdiv i32 %57, %58
  %60 = sub nsw i32 %56, %59
  %61 = sext i32 %60 to i64
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = srem i32 %62, %63
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [131072 x i64], ptr @inv, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = mul nsw i64 %61, %67
  %69 = load i32, ptr @n, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = srem i64 %68, %70
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [131072 x i64], ptr @inv, i64 0, i64 %73
  store i64 %71, ptr %74, align 8, !tbaa !11
  br label %75

75:                                               ; preds = %43
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !13

78:                                               ; preds = %42
  %79 = load i32, ptr @n, align 4, !tbaa !5
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %79)
  br label %81

81:                                               ; preds = %78, %13
  br label %82

82:                                               ; preds = %81, %8
  store i32 0, ptr %1, align 4
  br label %83

83:                                               ; preds = %82, %34
  %84 = load i32, ptr %1, align 4
  ret i32 %84

85:                                               ; preds = %34
  unreachable
}

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

declare i32 @puts(ptr noundef) #1

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

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

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}


; 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
@inv = external dso_local local_unnamed_addr global [131072 x i64], align 16
@.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 [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %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 %5
  ]

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

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

5:                                                ; preds = %0
  %6 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %38

7:                                                ; preds = %.lr.ph
  %8 = add nuw nsw i32 %.01423, 1
  %9 = mul nuw nsw i32 %8, %8
  %.not = icmp sgt i32 %9, %2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %7
  %.01423 = phi i32 [ %8, %7 ], [ 2, %.preheader ]
  %10 = urem i32 %2, %.01423
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %7

12:                                               ; preds = %.lr.ph
  %13 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %38

._crit_edge:                                      ; preds = %7, %.preheader
  %14 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  store i64 1, ptr getelementptr inbounds (i8, ptr @inv, i64 8), align 8, !tbaa !11
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 2
  br i1 %16, label %.lr.ph26, label %._crit_edge27

._crit_edge27:                                    ; preds = %.lr.ph26, %._crit_edge
  %.lcssa = phi i32 [ %15, %._crit_edge ], [ %24, %.lr.ph26 ]
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %.lcssa)
  br label %38

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %18 = phi i64 [ %35, %.lr.ph26 ], [ 1, %._crit_edge ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph26 ], [ 2, %._crit_edge ]
  %19 = phi i32 [ %24, %.lr.ph26 ], [ %15, %._crit_edge ]
  %20 = mul nsw i64 %18, %indvars.iv
  %21 = sext i32 %19 to i64
  %22 = srem i64 %20, %21
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %22)
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = sdiv i32 %24, %25
  %27 = sub nsw i32 %24, %26
  %28 = sext i32 %27 to i64
  %29 = srem i32 %24, %25
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [131072 x i64], ptr @inv, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = mul nsw i64 %32, %28
  %34 = sext i32 %24 to i64
  %35 = srem i64 %33, %34
  %36 = getelementptr inbounds [131072 x i64], ptr @inv, i64 0, i64 %indvars.iv
  store i64 %35, ptr %36, align 8, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = icmp slt i64 %indvars.iv.next, %34
  br i1 %37, label %.lr.ph26, label %._crit_edge27, !llvm.loop !13

38:                                               ; preds = %12, %3, %._crit_edge27, %5
  ret i32 0
}

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

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

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

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}


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