; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Educational Codeforces Round 117 (Rated for Div. 2)/D. X-Magic Pair/_6ca1ed64 (Z5solvev)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.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 [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp eq i64 %10, %11
  br i1 %12, label %17, label %13

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

17:                                               ; preds = %13, %0
  %18 = phi i1 [ true, %0 ], [ %16, %13 ]
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %4, align 1, !tbaa !9
  br label %20

20:                                               ; preds = %89, %17
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %20
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %28 = trunc i8 %27 to i1
  %29 = xor i1 %28, true
  br label %30

30:                                               ; preds = %26, %23, %20
  %31 = phi i1 [ false, %23 ], [ false, %20 ], [ %29, %26 ]
  br i1 %31, label %32, label %90

32:                                               ; preds = %30
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %1, align 8, !tbaa !5
  %35 = icmp sgt i64 %33, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %32
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %2, align 8, !tbaa !5
  %39 = icmp sgt i64 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %90

41:                                               ; preds = %36, %32
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = load i64, ptr %1, align 8, !tbaa !5
  %44 = icmp sgt i64 %42, %43
  br i1 %44, label %45, label %67

45:                                               ; preds = %41
  %46 = load i64, ptr %1, align 8, !tbaa !5
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = srem i64 %47, %46
  store i64 %48, ptr %2, align 8, !tbaa !5
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = icmp eq i64 %49, %50
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %4, align 1, !tbaa !9
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr %2, align 8, !tbaa !5
  %55 = icmp sgt i64 %53, %54
  br i1 %55, label %56, label %66

56:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = load i64, ptr %2, align 8, !tbaa !5
  %59 = sub nsw i64 %57, %58
  store i64 %59, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = load i64, ptr %1, align 8, !tbaa !5
  %62 = srem i64 %60, %61
  %63 = icmp eq i64 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %56
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %65

65:                                               ; preds = %64, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %66

66:                                               ; preds = %65, %45
  br label %89

67:                                               ; preds = %41
  %68 = load i64, ptr %2, align 8, !tbaa !5
  %69 = load i64, ptr %1, align 8, !tbaa !5
  %70 = srem i64 %69, %68
  store i64 %70, ptr %1, align 8, !tbaa !5
  %71 = load i64, ptr %1, align 8, !tbaa !5
  %72 = load i64, ptr %3, align 8, !tbaa !5
  %73 = icmp eq i64 %71, %72
  %74 = zext i1 %73 to i8
  store i8 %74, ptr %4, align 1, !tbaa !9
  %75 = load i64, ptr %3, align 8, !tbaa !5
  %76 = load i64, ptr %1, align 8, !tbaa !5
  %77 = icmp sgt i64 %75, %76
  br i1 %77, label %78, label %88

78:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %79 = load i64, ptr %3, align 8, !tbaa !5
  %80 = load i64, ptr %1, align 8, !tbaa !5
  %81 = sub nsw i64 %79, %80
  store i64 %81, ptr %6, align 8, !tbaa !5
  %82 = load i64, ptr %6, align 8, !tbaa !5
  %83 = load i64, ptr %2, align 8, !tbaa !5
  %84 = srem i64 %82, %83
  %85 = icmp eq i64 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %78
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %87

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

88:                                               ; preds = %87, %67
  br label %89

89:                                               ; preds = %88, %66
  br label %20, !llvm.loop !13

90:                                               ; preds = %40, %30
  %91 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %92 = trunc i8 %91 to i1
  %93 = zext i1 %92 to i64
  %94 = select i1 %92, ptr @.str, ptr @.str.1
  %95 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef %94)
  %96 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %95, ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 1, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.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 [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8
  %9 = icmp eq i64 %7, %8
  %10 = load i64, ptr %2, align 8
  %11 = icmp eq i64 %10, %8
  %12 = select i1 %9, i1 true, i1 %11
  %13 = icmp slt i64 %7, 1
  %14 = icmp slt i64 %10, 1
  %or.cond.not1821 = select i1 %13, i1 true, i1 %14
  %.not22 = select i1 %or.cond.not1821, i1 true, i1 %12
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %32
  %15 = phi i64 [ %34, %32 ], [ %7, %0 ]
  %16 = phi i64 [ %33, %32 ], [ %10, %0 ]
  %17 = icmp sgt i64 %8, %15
  %18 = icmp sgt i64 %8, %16
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %._crit_edge.thread, label %19

19:                                               ; preds = %.lr.ph
  %20 = icmp ugt i64 %16, %15
  br i1 %20, label %21, label %25

21:                                               ; preds = %19
  %22 = urem i64 %16, %15
  store i64 %22, ptr %2, align 8, !tbaa !5
  %23 = icmp eq i64 %22, %8
  %24 = icmp sgt i64 %8, %22
  br i1 %24, label %.sink.split, label %32

25:                                               ; preds = %19
  %26 = urem i64 %15, %16
  store i64 %26, ptr %1, align 8, !tbaa !5
  %27 = icmp eq i64 %26, %8
  %28 = icmp sgt i64 %8, %26
  br i1 %28, label %.sink.split, label %32

.sink.split:                                      ; preds = %25, %21
  %.sink32 = phi i64 [ %22, %21 ], [ %26, %25 ]
  %.sink31 = phi i64 [ %15, %21 ], [ %16, %25 ]
  %.sink29 = phi i1 [ %23, %21 ], [ %27, %25 ]
  %.ph = phi i64 [ %22, %21 ], [ %16, %25 ]
  %.ph28 = phi i64 [ %15, %21 ], [ %26, %25 ]
  %29 = sub nsw i64 %8, %.sink32
  %30 = srem i64 %29, %.sink31
  %31 = icmp eq i64 %30, 0
  %spec.select19 = select i1 %31, i1 true, i1 %.sink29
  br label %32

32:                                               ; preds = %.sink.split, %25, %21
  %33 = phi i64 [ %22, %21 ], [ %16, %25 ], [ %.ph, %.sink.split ]
  %34 = phi i64 [ %15, %21 ], [ %26, %25 ], [ %.ph28, %.sink.split ]
  %.3 = phi i1 [ %23, %21 ], [ %27, %25 ], [ %spec.select19, %.sink.split ]
  %35 = icmp slt i64 %34, 1
  %36 = icmp slt i64 %33, 1
  %or.cond.not18 = select i1 %35, i1 true, i1 %36
  %.not = select i1 %or.cond.not18, i1 true, i1 %.3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %32, %0
  %.0.lcssa = phi i1 [ %12, %0 ], [ %.3, %32 ]
  %cond.fr = freeze i1 %.0.lcssa
  %spec.select = select i1 %cond.fr, ptr @.str, ptr @.str.1
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph, %._crit_edge
  %37 = phi ptr [ %spec.select, %._crit_edge ], [ @.str.1, %.lr.ph ]
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull %37)
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef nonnull @.str.2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 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: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass