; LLVM IR from DionysiosB/CodeForces :: 2037C-SuperultrasFavoritePermutation (main)

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 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 i64, align 8
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %8

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

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = icmp slt i64 %14, 5
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = call i32 @puts(ptr noundef @.str.1)
  store i32 2, ptr %4, align 4
  br label %53, !llvm.loop !9

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

19:                                               ; preds = %31, %18
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = icmp sle i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %34

24:                                               ; preds = %19
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = icmp eq i64 %25, 5
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  br label %31

28:                                               ; preds = %24
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %29)
  br label %31

31:                                               ; preds = %28, %27
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = add nsw i64 %32, 2
  store i64 %33, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !11

34:                                               ; preds = %23
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 2, ptr %6, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %48, %34
  %37 = load i64, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = icmp sle i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %51

41:                                               ; preds = %36
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = icmp eq i64 %42, 4
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  br label %48

45:                                               ; preds = %41
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %46)
  br label %48

48:                                               ; preds = %45, %44
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = add nsw i64 %49, 2
  store i64 %50, ptr %6, align 8, !tbaa !5
  br label %36, !llvm.loop !12

51:                                               ; preds = %40
  %52 = call i32 @puts(ptr noundef @.str.4)
  store i32 0, ptr %4, align 4
  br label %53

53:                                               ; preds = %51, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %54 = load i32, ptr %4, align 4
  switch i32 %54, label %58 [
    i32 0, label %55
    i32 2, label %8
  ]

55:                                               ; preds = %53
  br label %8, !llvm.loop !9

56:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %57 = load i32, ptr %1, align 4
  ret i32 %57

58:                                               ; preds = %53
  unreachable
}

; 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

declare i32 @puts(ptr noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 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
  %.not19 = icmp eq i64 %4, 0
  br i1 %.not19, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %0, %._crit_edge18
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = icmp slt i64 %7, 5
  br i1 %8, label %._crit_edge18, label %9, !llvm.loop !9

9:                                                ; preds = %.lr.ph21
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef 1)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  %.not10.peel = icmp slt i64 %.pre, 3
  br i1 %.not10.peel, label %._crit_edge, label %11

11:                                               ; preds = %9
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef 3)
  %.pre34 = load i64, ptr %2, align 8, !tbaa !5
  %or.cond = icmp slt i64 %.pre34, 7
  br i1 %or.cond, label %._crit_edge, label %.lr.ph.peel.next26

._crit_edge:                                      ; preds = %.lr.ph.peel.next26, %9, %11
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %.not1114 = icmp slt i64 %14, 2
  br i1 %.not1114, label %._crit_edge18, label %15

15:                                               ; preds = %._crit_edge
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef 2)
  %.pre36 = load i64, ptr %2, align 8, !tbaa !5
  %or.cond38 = icmp slt i64 %.pre36, 6
  br i1 %or.cond38, label %._crit_edge18, label %.lr.ph17.peel.next30

.lr.ph.peel.next26:                               ; preds = %11, %.lr.ph.peel.next26
  %.0913 = phi i64 [ %18, %.lr.ph.peel.next26 ], [ 7, %11 ]
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.0913)
  %.pre35 = load i64, ptr %2, align 8, !tbaa !5
  %18 = add nuw nsw i64 %.0913, 2
  %.not10 = icmp sgt i64 %18, %.pre35
  br i1 %.not10, label %._crit_edge, label %.lr.ph.peel.next26, !llvm.loop !11

.lr.ph17.peel.next30:                             ; preds = %15, %.lr.ph17.peel.next30
  %.015 = phi i64 [ %20, %.lr.ph17.peel.next30 ], [ 6, %15 ]
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.015)
  %.pre37 = load i64, ptr %2, align 8, !tbaa !5
  %20 = add nuw nsw i64 %.015, 2
  %.not11 = icmp sgt i64 %20, %.pre37
  br i1 %.not11, label %._crit_edge18, label %.lr.ph17.peel.next30, !llvm.loop !13

._crit_edge18:                                    ; preds = %.lr.ph17.peel.next30, %._crit_edge, %15, %.lr.ph21
  %.str.4.sink = phi ptr [ @.str.1, %.lr.ph21 ], [ @.str.4, %15 ], [ @.str.4, %._crit_edge ], [ @.str.4, %.lr.ph17.peel.next30 ]
  %21 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %22 = load i64, ptr %1, align 8, !tbaa !5
  %23 = add nsw i64 %22, -1
  store i64 %23, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %._crit_edge22, label %.lr.ph21

._crit_edge22:                                    ; preds = %._crit_edge18, %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: 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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12}
!12 = !{!"llvm.loop.peeled.count", i32 3}
!13 = distinct !{!13, !10, !14}
!14 = !{!"llvm.loop.peeled.count", i32 2}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass