; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1607_B.ll (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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = 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
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %0
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %11)
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %12, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %128

14:                                               ; preds = %0
  %15 = load i64, ptr %1, align 8, !tbaa !5
  %16 = srem i64 %15, 2
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %73

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = srem i64 %19, 4
  store i64 %20, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  %24 = load i64, ptr %1, align 8, !tbaa !5
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %24)
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %25, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %72

27:                                               ; preds = %18
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = icmp eq i64 %28, 1
  br i1 %29, label %30, label %39

30:                                               ; preds = %27
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = sub nsw i64 %32, %33
  %35 = add nsw i64 %34, 1
  %36 = sub nsw i64 %31, %35
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %36)
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %37, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %72

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

42:                                               ; preds = %39
  %43 = load i64, ptr %1, align 8, !tbaa !5
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = sub nsw i64 %44, %45
  %47 = add nsw i64 %46, 1
  %48 = sub nsw i64 %43, %47
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = sub nsw i64 %49, %50
  %52 = add nsw i64 %51, 2
  %53 = add nsw i64 %48, %52
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %53)
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %54, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %72

56:                                               ; preds = %39
  %57 = load i64, ptr %1, align 8, !tbaa !5
  %58 = load i64, ptr %2, align 8, !tbaa !5
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = sub nsw i64 %58, %59
  %61 = add nsw i64 %60, 1
  %62 = sub nsw i64 %57, %61
  %63 = load i64, ptr %2, align 8, !tbaa !5
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = sub nsw i64 %63, %64
  %66 = add nsw i64 %65, 2
  %67 = add nsw i64 %62, %66
  %68 = load i64, ptr %2, align 8, !tbaa !5
  %69 = add nsw i64 %67, %68
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %69)
  %71 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %70, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %72

72:                                               ; preds = %56, %42, %30, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %128

73:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %74 = load i64, ptr %2, align 8, !tbaa !5
  %75 = srem i64 %74, 4
  store i64 %75, ptr %5, align 8, !tbaa !5
  %76 = load i64, ptr %5, align 8, !tbaa !5
  %77 = icmp eq i64 %76, 0
  br i1 %77, label %78, label %82

78:                                               ; preds = %73
  %79 = load i64, ptr %1, align 8, !tbaa !5
  %80 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %79)
  %81 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %80, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %127

82:                                               ; preds = %73
  %83 = load i64, ptr %5, align 8, !tbaa !5
  %84 = icmp eq i64 %83, 1
  br i1 %84, label %85, label %94

85:                                               ; preds = %82
  %86 = load i64, ptr %1, align 8, !tbaa !5
  %87 = load i64, ptr %2, align 8, !tbaa !5
  %88 = load i64, ptr %5, align 8, !tbaa !5
  %89 = sub nsw i64 %87, %88
  %90 = add nsw i64 %89, 1
  %91 = add nsw i64 %86, %90
  %92 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %91)
  %93 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %92, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %127

94:                                               ; preds = %82
  %95 = load i64, ptr %5, align 8, !tbaa !5
  %96 = icmp eq i64 %95, 2
  br i1 %96, label %97, label %111

97:                                               ; preds = %94
  %98 = load i64, ptr %1, align 8, !tbaa !5
  %99 = load i64, ptr %2, align 8, !tbaa !5
  %100 = load i64, ptr %5, align 8, !tbaa !5
  %101 = sub nsw i64 %99, %100
  %102 = add nsw i64 %101, 1
  %103 = add nsw i64 %98, %102
  %104 = load i64, ptr %2, align 8, !tbaa !5
  %105 = load i64, ptr %5, align 8, !tbaa !5
  %106 = sub nsw i64 %104, %105
  %107 = add nsw i64 %106, 2
  %108 = sub nsw i64 %103, %107
  %109 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %108)
  %110 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %109, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %127

111:                                              ; preds = %94
  %112 = load i64, ptr %1, align 8, !tbaa !5
  %113 = load i64, ptr %2, align 8, !tbaa !5
  %114 = load i64, ptr %5, align 8, !tbaa !5
  %115 = sub nsw i64 %113, %114
  %116 = add nsw i64 %115, 1
  %117 = add nsw i64 %112, %116
  %118 = load i64, ptr %2, align 8, !tbaa !5
  %119 = load i64, ptr %5, align 8, !tbaa !5
  %120 = sub nsw i64 %118, %119
  %121 = add nsw i64 %120, 2
  %122 = sub nsw i64 %117, %121
  %123 = load i64, ptr %2, align 8, !tbaa !5
  %124 = sub nsw i64 %122, %123
  %125 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %124)
  %126 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %125, i8 noundef signext 10)
  store i32 1, ptr %3, align 4
  br label %127

127:                                              ; preds = %111, %97, %85, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %128

128:                                              ; preds = %127, %72, %10
  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 @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0 align 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 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 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"

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  %7 = load i64, ptr %1, align 8, !tbaa !5
  br i1 %6, label %28, label %8

8:                                                ; preds = %0
  %9 = and i64 %7, 1
  %10 = icmp eq i64 %9, 0
  %11 = srem i64 %5, 4
  br i1 %10, label %12, label %20

12:                                               ; preds = %8
  switch i64 %11, label %17 [
    i64 0, label %28
    i64 1, label %13
    i64 2, label %15
  ]

13:                                               ; preds = %12
  %14 = sub nsw i64 %7, %5
  br label %28

15:                                               ; preds = %12
  %16 = or disjoint i64 %7, 1
  br label %28

17:                                               ; preds = %12
  %18 = add i64 %5, 1
  %19 = add i64 %18, %7
  br label %28

20:                                               ; preds = %8
  switch i64 %11, label %25 [
    i64 0, label %28
    i64 1, label %21
    i64 2, label %23
  ]

21:                                               ; preds = %20
  %22 = add nsw i64 %7, %5
  br label %28

23:                                               ; preds = %20
  %24 = add nsw i64 %7, -1
  br label %28

25:                                               ; preds = %20
  %26 = xor i64 %5, -1
  %27 = add i64 %7, %26
  br label %28

28:                                               ; preds = %20, %12, %0, %21, %23, %25, %13, %15, %17
  %.sink22 = phi i64 [ %22, %21 ], [ %24, %23 ], [ %27, %25 ], [ %14, %13 ], [ %16, %15 ], [ %19, %17 ], [ %7, %0 ], [ %7, %12 ], [ %7, %20 ]
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.sink22)
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %29, i8 noundef signext 10)
  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 @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) 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

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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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