; LLVM IR from DionysiosB/CodeForces :: 1100-1199 (1156A-InscribedFigures)

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

10:                                               ; preds = %81, %0
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = icmp slt i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %84

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  %17 = load i64, ptr %8, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = icmp eq i64 %17, %18
  br i1 %19, label %32, label %20

20:                                               ; preds = %15
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 2
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = icmp eq i64 %24, 3
  br i1 %25, label %32, label %26

26:                                               ; preds = %23, %20
  %27 = load i64, ptr %8, align 8, !tbaa !5
  %28 = icmp eq i64 %27, 3
  br i1 %28, label %29, label %33

29:                                               ; preds = %26
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = icmp eq i64 %30, 2
  br i1 %31, label %32, label %33

32:                                               ; preds = %29, %23, %15
  store i64 -1, ptr %3, align 8, !tbaa !5
  store i32 2, ptr %7, align 4
  br label %78

33:                                               ; preds = %29, %26
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = icmp eq i64 %34, 1
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = icmp eq i64 %37, 2
  br i1 %38, label %45, label %39

39:                                               ; preds = %36, %33
  %40 = load i64, ptr %8, align 8, !tbaa !5
  %41 = icmp eq i64 %40, 2
  br i1 %41, label %42, label %48

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

45:                                               ; preds = %42, %36
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = add nsw i64 %46, 3
  store i64 %47, ptr %3, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %45, %42, %39
  %49 = load i64, ptr %8, align 8, !tbaa !5
  %50 = icmp eq i64 %49, 1
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = icmp eq i64 %52, 3
  br i1 %53, label %60, label %54

54:                                               ; preds = %51, %48
  %55 = load i64, ptr %8, align 8, !tbaa !5
  %56 = icmp eq i64 %55, 3
  br i1 %56, label %57, label %63

57:                                               ; preds = %54
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = icmp eq i64 %58, 1
  br i1 %59, label %60, label %63

60:                                               ; preds = %57, %51
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = add nsw i64 %61, 4
  store i64 %62, ptr %3, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %60, %57, %54
  %64 = load i64, ptr %8, align 8, !tbaa !5
  %65 = icmp eq i64 %64, 2
  br i1 %65, label %66, label %75

66:                                               ; preds = %63
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = icmp eq i64 %67, 1
  br i1 %68, label %69, label %75

69:                                               ; preds = %66
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = icmp eq i64 %70, 3
  br i1 %71, label %72, label %75

72:                                               ; preds = %69
  %73 = load i64, ptr %3, align 8, !tbaa !5
  %74 = sub nsw i64 %73, 1
  store i64 %74, ptr %3, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %72, %69, %66, %63
  %76 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %76, ptr %5, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %77, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %78

78:                                               ; preds = %75, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %79 = load i32, ptr %7, align 4
  switch i32 %79, label %84 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %6, align 8, !tbaa !5
  %83 = add nsw i64 %82, 1
  store i64 %83, ptr %6, align 8, !tbaa !5
  br label %10, !llvm.loop !9

84:                                               ; preds = %78, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %85

85:                                               ; preds = %84
  %86 = load i64, ptr %3, align 8, !tbaa !5
  %87 = icmp slt i64 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  %89 = call i32 @puts(ptr noundef @.str.1)
  br label %93

90:                                               ; preds = %85
  %91 = load i64, ptr %3, align 8, !tbaa !5
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %91)
  br label %93

93:                                               ; preds = %90, %88
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %94 = load i32, ptr %1, align 4
  ret i32 %94
}

; 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

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

declare i32 @puts(ptr noundef) #2

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

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


; 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 [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 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 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %0, %15
  %.03453 = phi i64 [ %22, %15 ], [ 0, %0 ]
  %.03552 = phi i64 [ %.03651, %15 ], [ -1, %0 ]
  %.03651 = phi i64 [ %7, %15 ], [ -1, %0 ]
  %.03850 = phi i64 [ %spec.select, %15 ], [ 0, %0 ]
  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 eq i64 %7, %.03651
  br i1 %8, label %.thread46, label %9

9:                                                ; preds = %.lr.ph
  %10 = icmp eq i64 %7, 2
  %11 = icmp eq i64 %.03651, 3
  %or.cond = and i1 %11, %10
  br i1 %or.cond, label %.thread46, label %12

12:                                               ; preds = %9
  %13 = icmp eq i64 %7, 3
  %14 = icmp eq i64 %.03651, 2
  %or.cond3 = and i1 %14, %13
  br i1 %or.cond3, label %.thread46, label %15

15:                                               ; preds = %12
  %16 = icmp eq i64 %7, 1
  %or.cond5 = and i1 %14, %16
  %17 = icmp eq i64 %.03651, 1
  %or.cond7 = and i1 %17, %10
  %or.cond41 = or i1 %or.cond5, %or.cond7
  %18 = add nsw i64 %.03850, 3
  %.139 = select i1 %or.cond41, i64 %18, i64 %.03850
  %or.cond9 = and i1 %11, %16
  %or.cond11 = and i1 %17, %13
  %or.cond48 = or i1 %or.cond9, %or.cond11
  %19 = add nsw i64 %.139, 4
  %.2 = select i1 %or.cond48, i64 %19, i64 %.139
  %20 = icmp eq i64 %.03552, 3
  %or.cond15 = and i1 %20, %or.cond7
  %21 = sext i1 %or.cond15 to i64
  %spec.select = add nsw i64 %.2, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %22 = add nuw nsw i64 %.03453, 1
  %23 = load i64, ptr %1, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.thread46:                                        ; preds = %.lr.ph, %9, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %26

._crit_edge:                                      ; preds = %15
  %25 = icmp slt i64 %spec.select, 0
  br i1 %25, label %26, label %._crit_edge.thread

26:                                               ; preds = %.thread46, %._crit_edge
  %27 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %29

._crit_edge.thread:                               ; preds = %0, %._crit_edge
  %.038.lcssa55 = phi i64 [ %spec.select, %._crit_edge ], [ 0, %0 ]
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.038.lcssa55)
  br label %29

29:                                               ; preds = %._crit_edge.thread, %26
  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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


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