; LLVM IR from abeaumont/competitive-programming :: codechef/sept18a (xorier)

; 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
@n = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@e = external dso_local global i64, align 8
@o = external dso_local global i64, align 8
@s = external dso_local global i64, align 8
@a = external dso_local global [1000010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %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) @t)
  br label %6

6:                                                ; preds = %85, %0
  %7 = load i64, ptr @t, align 8, !tbaa !5
  %8 = add nsw i64 %7, -1
  store i64 %8, ptr @t, align 8, !tbaa !5
  %9 = icmp ne i64 %7, 0
  br i1 %9, label %10, label %90

10:                                               ; preds = %6
  %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) @n)
  store i64 0, ptr @s, align 8, !tbaa !5
  store i64 0, ptr @e, align 8, !tbaa !5
  store i64 0, ptr @o, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %20, %10
  %13 = load i32, ptr %2, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 1000010
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %23

16:                                               ; preds = %12
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %18
  store i64 0, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !9
  br label %12, !llvm.loop !11

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %46, %23
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr @n, align 8, !tbaa !5
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %49

30:                                               ; preds = %24
  %31 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @x)
  %32 = load i64, ptr @x, align 8, !tbaa !5
  %33 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %33, align 8, !tbaa !5
  %36 = load i64, ptr @x, align 8, !tbaa !5
  %37 = srem i64 %36, 2
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %30
  %40 = load i64, ptr @o, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr @o, align 8, !tbaa !5
  br label %45

42:                                               ; preds = %30
  %43 = load i64, ptr @e, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr @e, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42, %39
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !9
  br label %24, !llvm.loop !13

49:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %82, %49
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = icmp slt i32 %51, 1000006
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %85

54:                                               ; preds = %50
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = srem i32 %59, 2
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %54
  %63 = load i64, ptr @o, align 8, !tbaa !5
  br label %66

64:                                               ; preds = %54
  %65 = load i64, ptr @e, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %64, %62
  %67 = phi i64 [ %63, %62 ], [ %65, %64 ]
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !5
  %72 = sub nsw i64 %67, %71
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = xor i32 %73, 2
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !5
  %78 = sub nsw i64 %72, %77
  %79 = mul nsw i64 %58, %78
  %80 = load i64, ptr @s, align 8, !tbaa !5
  %81 = add nsw i64 %80, %79
  store i64 %81, ptr @s, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %66
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, align 4, !tbaa !9
  br label %50, !llvm.loop !14

85:                                               ; preds = %53
  %86 = load i64, ptr @s, align 8, !tbaa !5
  %87 = sdiv i64 %86, 2
  %88 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %87)
  %89 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %88, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %6, !llvm.loop !15

90:                                               ; preds = %6
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; 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: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #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 = { 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 #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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
@n = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@e = external dso_local local_unnamed_addr global i64, align 8
@o = external dso_local local_unnamed_addr global i64, align 8
@s = external dso_local local_unnamed_addr global i64, align 8
@a = external dso_local local_unnamed_addr global [1000010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = 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)
  %2 = load i64, ptr @t, align 8, !tbaa !5
  %3 = add nsw i64 %2, -1
  store i64 %3, ptr @t, align 8, !tbaa !5
  %.not22 = icmp eq i64 %2, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph23

.lr.ph23:                                         ; preds = %0, %19
  %4 = 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) @n)
  store i64 0, ptr @s, align 8, !tbaa !5
  store i64 0, ptr @e, align 8, !tbaa !5
  store i64 0, ptr @o, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8000080) @a, i8 0, i64 8000080, i1 false), !tbaa !5
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %.preheader

.preheader.loopexit:                              ; preds = %.lr.ph
  %.pre = load i64, ptr @o, align 8
  %.pre29 = load i64, ptr @e, align 8
  %s.promoted.pre = load i64, ptr @s, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.lr.ph23
  %s.promoted = phi i64 [ %s.promoted.pre, %.preheader.loopexit ], [ 0, %.lr.ph23 ]
  %7 = phi i64 [ %.pre29, %.preheader.loopexit ], [ 0, %.lr.ph23 ]
  %8 = phi i64 [ %.pre, %.preheader.loopexit ], [ 0, %.lr.ph23 ]
  br label %25

.lr.ph:                                           ; preds = %.lr.ph23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph23 ]
  %9 = 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) @x)
  %10 = load i64, ptr @x, align 8, !tbaa !5
  %11 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr %11, align 8, !tbaa !5
  %14 = and i64 %10, 1
  %.not15 = icmp eq i64 %14, 0
  %e.o = select i1 %.not15, ptr @e, ptr @o
  %15 = load i64, ptr %e.o, align 8, !tbaa !5
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %e.o, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i64, ptr @n, align 8, !tbaa !5
  %18 = icmp sgt i64 %17, %indvars.iv.next
  br i1 %18, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !9

19:                                               ; preds = %25
  store i64 %35, ptr @s, align 8, !tbaa !5
  %20 = sdiv i64 %35, 2
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %20)
  %22 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %23 = load i64, ptr @t, align 8, !tbaa !5
  %24 = add nsw i64 %23, -1
  store i64 %24, ptr @t, align 8, !tbaa !5
  %.not = icmp eq i64 %23, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph23, !llvm.loop !11

25:                                               ; preds = %36, %.preheader
  %indvars.iv26 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next27.1, %36 ]
  %26 = phi i64 [ %s.promoted, %.preheader ], [ %45, %36 ]
  %27 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %indvars.iv26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = xor i64 %indvars.iv26, 2
  %30 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = add i64 %31, %28
  %33 = sub i64 %8, %32
  %34 = mul nsw i64 %33, %28
  %35 = add nsw i64 %34, %26
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next27, 1000006
  br i1 %exitcond.not, label %19, label %36, !llvm.loop !12

36:                                               ; preds = %25
  %37 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %indvars.iv.next27
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = xor i64 %indvars.iv.next27, 2
  %40 = getelementptr inbounds [1000010 x i64], ptr @a, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = add i64 %41, %38
  %43 = sub i64 %7, %42
  %44 = mul nsw i64 %43, %38
  %45 = add nsw i64 %44, %35
  %indvars.iv.next27.1 = add nuw nsw i64 %indvars.iv26, 2
  br label %25

._crit_edge:                                      ; preds = %19, %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 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 uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
!12 = distinct !{!12, !10}


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