; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 28. Codechef Problems (shuffling_parites)

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

@t = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 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 ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @t)
  br label %12

12:                                               ; preds = %82, %0
  %13 = load i64, ptr @t, align 8, !tbaa !5
  %14 = add nsw i64 %13, -1
  store i64 %14, ptr @t, align 8, !tbaa !5
  %15 = icmp ne i64 %13, 0
  br i1 %15, label %16, label %87

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %17 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = call ptr @llvm.stacksave.p0()
  store ptr %19, ptr %3, align 8
  %20 = alloca i64, i64 %18, align 16
  store i64 %18, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %42, %16
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %45

26:                                               ; preds = %21
  %27 = load i64, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds i64, ptr %20, i64 %27
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %28)
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %20, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = srem i64 %32, 2
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %26
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %6, align 8, !tbaa !5
  br label %41

38:                                               ; preds = %26
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %38, %35
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %7, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !5
  br label %21, !llvm.loop !9

45:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = srem i64 %46, 2
  %48 = icmp eq i64 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %45
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = sdiv i64 %50, 2
  store i64 %51, ptr %9, align 8, !tbaa !5
  store i64 %51, ptr %8, align 8, !tbaa !5
  br label %58

52:                                               ; preds = %45
  %53 = load i64, ptr %2, align 8, !tbaa !5
  %54 = sdiv i64 %53, 2
  store i64 %54, ptr %8, align 8, !tbaa !5
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = sdiv i64 %55, 2
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %9, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %52, %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = icmp sgt i64 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %58
  %63 = load i64, ptr %9, align 8, !tbaa !5
  %64 = load i64, ptr %10, align 8, !tbaa !5
  %65 = add nsw i64 %64, %63
  store i64 %65, ptr %10, align 8, !tbaa !5
  br label %70

66:                                               ; preds = %58
  %67 = load i64, ptr %6, align 8, !tbaa !5
  %68 = load i64, ptr %10, align 8, !tbaa !5
  %69 = add nsw i64 %68, %67
  store i64 %69, ptr %10, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %66, %62
  %71 = load i64, ptr %5, align 8, !tbaa !5
  %72 = load i64, ptr %8, align 8, !tbaa !5
  %73 = icmp sgt i64 %71, %72
  br i1 %73, label %74, label %78

74:                                               ; preds = %70
  %75 = load i64, ptr %8, align 8, !tbaa !5
  %76 = load i64, ptr %10, align 8, !tbaa !5
  %77 = add nsw i64 %76, %75
  store i64 %77, ptr %10, align 8, !tbaa !5
  br label %82

78:                                               ; preds = %70
  %79 = load i64, ptr %5, align 8, !tbaa !5
  %80 = load i64, ptr %10, align 8, !tbaa !5
  %81 = add nsw i64 %80, %79
  store i64 %81, ptr %10, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %78, %74
  %83 = load i64, ptr %10, align 8, !tbaa !5
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %83)
  %85 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %84, ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %86 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %86)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  br label %12, !llvm.loop !11

87:                                               ; preds = %12
  ret i32 0
}

; 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)) #1 align 2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

; 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) #4

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

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

@t = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @t)
  %3 = load i64, ptr @t, align 8, !tbaa !5
  %4 = add nsw i64 %3, -1
  store i64 %4, ptr @t, align 8, !tbaa !5
  %.not32 = icmp eq i64 %3, 0
  br i1 %.not32, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %0, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  %5 = 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)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = call ptr @llvm.stacksave.p0()
  %8 = alloca i64, i64 %6, align 16
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph34
  %.024.lcssa = phi i64 [ 0, %.lr.ph34 ], [ %.125, %.lr.ph ]
  %.022.lcssa = phi i64 [ 0, %.lr.ph34 ], [ %.123, %.lr.ph ]
  %.lcssa = phi i64 [ %9, %.lr.ph34 ], [ %19, %.lr.ph ]
  %11 = and i64 %.lcssa, 1
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %21, label %23

.lr.ph:                                           ; preds = %.lr.ph34, %.lr.ph
  %.02129 = phi i64 [ %18, %.lr.ph ], [ 0, %.lr.ph34 ]
  %.02228 = phi i64 [ %.123, %.lr.ph ], [ 0, %.lr.ph34 ]
  %.02427 = phi i64 [ %.125, %.lr.ph ], [ 0, %.lr.ph34 ]
  %13 = getelementptr inbounds i64, ptr %8, i64 %.02129
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %13)
  %15 = load i64, ptr %13, align 8, !tbaa !5
  %16 = and i64 %15, 1
  %.125 = add i64 %16, %.02427
  %17 = xor i64 %16, 1
  %.123 = add i64 %17, %.02228
  %18 = add nuw nsw i64 %.02129, 1
  %19 = load i64, ptr %1, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !9

21:                                               ; preds = %._crit_edge
  %22 = ashr exact i64 %.lcssa, 1
  br label %26

23:                                               ; preds = %._crit_edge
  %24 = sdiv i64 %.lcssa, 2
  %25 = add nsw i64 %24, 1
  br label %26

26:                                               ; preds = %23, %21
  %.020 = phi i64 [ %22, %21 ], [ %24, %23 ]
  %.019 = phi i64 [ %22, %21 ], [ %25, %23 ]
  %.019..022 = call i64 @llvm.smin.i64(i64 %.022.lcssa, i64 %.019)
  %.020.pn = call i64 @llvm.smin.i64(i64 %.024.lcssa, i64 %.020)
  %.1 = add nsw i64 %.019..022, %.020.pn
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.1)
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef nonnull @.str)
  call void @llvm.stackrestore.p0(ptr %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  %29 = load i64, ptr @t, align 8, !tbaa !5
  %30 = add nsw i64 %29, -1
  store i64 %30, ptr @t, align 8, !tbaa !5
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !11

._crit_edge35:                                    ; preds = %26, %0
  ret i32 0
}

; 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 #1 align 2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

; 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 #4

; 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 #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #5

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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