; LLVM IR from DionysiosB/CodeForces :: 0200-0299 (235A-LCMChallenge)

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

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

8:                                                ; preds = %0
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 2
  br i1 %10, label %11, label %13

11:                                               ; preds = %8
  %12 = call i32 @puts(ptr noundef @.str.2)
  br label %81

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = icmp eq i64 %14, 3
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = call i32 @puts(ptr noundef @.str.3)
  br label %80

18:                                               ; preds = %13
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = icmp sgt i64 %19, 3
  br i1 %20, label %21, label %34

21:                                               ; preds = %18
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = srem i64 %22, 2
  %24 = icmp eq i64 %23, 1
  br i1 %24, label %25, label %34

25:                                               ; preds = %21
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = sub nsw i64 %27, 1
  %29 = mul nsw i64 %26, %28
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = sub nsw i64 %30, 2
  %32 = mul nsw i64 %29, %31
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %32)
  br label %79

34:                                               ; preds = %21, %18
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = icmp sgt i64 %35, 3
  br i1 %36, label %37, label %55

37:                                               ; preds = %34
  %38 = load i64, ptr %2, align 8, !tbaa !5
  %39 = srem i64 %38, 2
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %55

41:                                               ; preds = %37
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = srem i64 %42, 3
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %55

45:                                               ; preds = %41
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = sub nsw i64 %46, 1
  %48 = load i64, ptr %2, align 8, !tbaa !5
  %49 = sub nsw i64 %48, 2
  %50 = mul nsw i64 %47, %49
  %51 = load i64, ptr %2, align 8, !tbaa !5
  %52 = sub nsw i64 %51, 3
  %53 = mul nsw i64 %50, %52
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %53)
  br label %78

55:                                               ; preds = %41, %37, %34
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = icmp sgt i64 %56, 3
  br i1 %57, label %58, label %75

58:                                               ; preds = %55
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = srem i64 %59, 2
  %61 = icmp eq i64 %60, 0
  br i1 %61, label %62, label %75

62:                                               ; preds = %58
  %63 = load i64, ptr %2, align 8, !tbaa !5
  %64 = srem i64 %63, 3
  %65 = icmp ne i64 %64, 0
  br i1 %65, label %66, label %75

66:                                               ; preds = %62
  %67 = load i64, ptr %2, align 8, !tbaa !5
  %68 = load i64, ptr %2, align 8, !tbaa !5
  %69 = sub nsw i64 %68, 1
  %70 = mul nsw i64 %67, %69
  %71 = load i64, ptr %2, align 8, !tbaa !5
  %72 = sub nsw i64 %71, 3
  %73 = mul nsw i64 %70, %72
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %73)
  br label %77

75:                                               ; preds = %62, %58, %55
  %76 = call i32 @puts(ptr noundef @.str.5)
  br label %77

77:                                               ; preds = %75, %66
  br label %78

78:                                               ; preds = %77, %45
  br label %79

79:                                               ; preds = %78, %25
  br label %80

80:                                               ; preds = %79, %16
  br label %81

81:                                               ; preds = %80, %11
  br label %82

82:                                               ; preds = %81, %6
  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

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


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

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

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

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

10:                                               ; preds = %0
  %11 = icmp slt i64 %3, 4
  %12 = and i64 %3, 1
  %.not = icmp eq i64 %12, 0
  %or.cond = or i1 %11, %.not
  br i1 %or.cond, label %19, label %13

13:                                               ; preds = %10
  %14 = add nsw i64 %3, -1
  %15 = mul nuw nsw i64 %14, %3
  %16 = add nsw i64 %3, -2
  %17 = mul nsw i64 %15, %16
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %17)
  br label %39

19:                                               ; preds = %10
  %20 = icmp sgt i64 %3, 3
  %or.cond5 = and i1 %20, %.not
  %21 = urem i64 %3, 3
  %22 = icmp eq i64 %21, 0
  %or.cond7 = and i1 %22, %or.cond5
  br i1 %or.cond7, label %23, label %30

23:                                               ; preds = %19
  %24 = add nsw i64 %3, -1
  %25 = add nsw i64 %3, -2
  %26 = mul nsw i64 %24, %25
  %27 = add nsw i64 %3, -3
  %28 = mul nsw i64 %26, %27
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %28)
  br label %39

30:                                               ; preds = %19
  %or.cond9.not = xor i1 %or.cond5, true
  %or.cond10 = or i1 %22, %or.cond9.not
  br i1 %or.cond10, label %37, label %31

31:                                               ; preds = %30
  %32 = add nsw i64 %3, -1
  %33 = mul nsw i64 %32, %3
  %34 = add nsw i64 %3, -3
  %35 = mul nsw i64 %33, %34
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %35)
  br label %39

37:                                               ; preds = %30
  %38 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %39

39:                                               ; preds = %6, %13, %31, %37, %23, %8, %4
  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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass