; LLVM IR from eyangch/competitive-programming :: CSES/Sorting_and_Searching (factory_machines)

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

@N = external dso_local global i64, align 8
@T = external dso_local global i64, align 8
@k = external dso_local global [200000 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5worksx(i64 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  store i32 0, ptr %1, align 4
  %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) @N)
  %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) @T)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %17, %0
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr @N, align 8, !tbaa !5
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  br label %20

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds [200000 x i64], ptr @k, i64 0, i64 %14
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %15)
  br label %17

17:                                               ; preds = %13
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %2, align 8, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 9223372036854775807, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %40, %20
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %25, label %41

25:                                               ; preds = %21
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = sub nsw i64 %27, %28
  %30 = sdiv i64 %29, 2
  %31 = add nsw i64 %26, %30
  store i64 %31, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = call noundef zeroext i1 @_Z5worksx(i64 noundef %32)
  br i1 %33, label %34, label %37

34:                                               ; preds = %25
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = sub nsw i64 %35, 1
  store i64 %36, ptr %4, align 8, !tbaa !5
  br label %40

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

40:                                               ; preds = %37, %34
  br label %21, !llvm.loop !11

41:                                               ; preds = %21
  br label %42

42:                                               ; preds = %45, %41
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = call noundef zeroext i1 @_Z5worksx(i64 noundef %43)
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = add nsw i64 %46, -1
  store i64 %47, ptr %5, align 8, !tbaa !5
  br label %42, !llvm.loop !12

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %53, %48
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = call noundef zeroext i1 @_Z5worksx(i64 noundef %50)
  %52 = xor i1 %51, true
  br i1 %52, label %53, label %56

53:                                               ; preds = %49
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %5, align 8, !tbaa !5
  br label %49, !llvm.loop !13

56:                                               ; preds = %49
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %57)
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %58, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  %60 = load i32, ptr %1, align 4
  ret i32 %60
}

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

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { 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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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" }

@N = external dso_local global i64, align 8
@T = external dso_local global i64, align 8
@k = external dso_local global [200000 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5worksx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %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) @N)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @T)
  %3 = load i64, ptr @N, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader23.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.02124 = phi i64 [ %7, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds [200000 x i64], ptr @k, i64 0, i64 %.02124
  %6 = 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) %5)
  %7 = add nuw nsw i64 %.02124, 1
  %8 = load i64, ptr @N, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %.lr.ph, label %.preheader23.preheader, !llvm.loop !9

.preheader23.preheader:                           ; preds = %.lr.ph, %0
  br label %.preheader23

.preheader23:                                     ; preds = %.preheader23.preheader, %.preheader23
  %.01726 = phi i64 [ %.118, %.preheader23 ], [ 9223372036854775807, %.preheader23.preheader ]
  %.01925 = phi i64 [ %.120, %.preheader23 ], [ 0, %.preheader23.preheader ]
  %10 = sub nsw i64 %.01726, %.01925
  %11 = sdiv i64 %10, 2
  %12 = add nsw i64 %11, %.01925
  %13 = tail call noundef zeroext i1 @_Z5worksx(i64 noundef %12)
  %14 = add nsw i64 %12, -1
  %15 = add nsw i64 %12, 1
  %.120 = select i1 %13, i64 %.01925, i64 %15
  %.118 = select i1 %13, i64 %14, i64 %.01726
  %16 = icmp slt i64 %.120, %.118
  br i1 %16, label %.preheader23, label %.preheader22, !llvm.loop !11

.preheader22:                                     ; preds = %.preheader23, %.preheader22
  %.1 = phi i64 [ %18, %.preheader22 ], [ %12, %.preheader23 ]
  %17 = tail call noundef zeroext i1 @_Z5worksx(i64 noundef %.1)
  %18 = add nsw i64 %.1, -1
  br i1 %17, label %.preheader22, label %.preheader, !llvm.loop !12

.preheader:                                       ; preds = %.preheader22, %.preheader
  %.2 = phi i64 [ %20, %.preheader ], [ %.1, %.preheader22 ]
  %19 = tail call noundef zeroext i1 @_Z5worksx(i64 noundef %.2)
  %20 = add nsw i64 %.2, 1
  br i1 %19, label %21, label %.preheader, !llvm.loop !13

21:                                               ; preds = %.preheader
  %22 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.2)
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  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 #2 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 #2 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 #2 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 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 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 #2 = { 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 = { 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" }

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


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