; LLVM IR from tangjz/acm-icpc :: hackerrank/stone-division.ll (Z3dfsx)

; 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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, bool>, std::_Select1st<std::pair<const long long, bool>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, bool>, std::_Select1st<std::pair<const long long, bool>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@m = external dso_local global i32, align 4
@a = external dso_local global [11 x i64], align 16
@Hash = external dso_local global %"class.std::map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsx(i64 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %6 = call noundef i64 @_ZNKSt3mapIxbSt4lessIxESaISt4pairIKxbEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = icmp ne i64 %6, 0
  br i1 %7, label %8, label %12

8:                                                ; preds = %1
  %9 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc i8 %10 to i1
  store i1 %11, ptr %2, align 1
  br label %51

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %13

13:                                               ; preds = %44, %12
  %14 = load i32, ptr %4, align 4, !tbaa !13
  %15 = load i32, ptr @m, align 4, !tbaa !13
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %5, align 4
  br label %47

18:                                               ; preds = %13
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [11 x i64], ptr @a, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = srem i64 %19, %23
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %43

26:                                               ; preds = %18
  %27 = load i32, ptr %4, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [11 x i64], ptr @a, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = and i64 %30, 1
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %26
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [11 x i64], ptr @a, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = sdiv i64 %34, %38
  %40 = call noundef zeroext i1 @_Z3dfsx(i64 noundef %39)
  br i1 %40, label %43, label %41

41:                                               ; preds = %33, %26
  %42 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i8 1, ptr %42, align 1, !tbaa !9
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %47

43:                                               ; preds = %33, %18
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %4, align 4, !tbaa !13
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %4, align 4, !tbaa !13
  br label %13, !llvm.loop !15

47:                                               ; preds = %41, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %48 = load i32, ptr %5, align 4
  switch i32 %48, label %53 [
    i32 2, label %49
    i32 1, label %51
  ]

49:                                               ; preds = %47
  %50 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i8 0, ptr %50, align 1, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %51

51:                                               ; preds = %49, %47, %8
  %52 = load i1, ptr %2, align 1
  ret i1 %52

53:                                               ; preds = %47
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIxbSt4lessIxESaISt4pairIKxbEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; 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

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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, bool>, std::_Select1st<std::pair<const long long, bool>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, bool>, std::_Select1st<std::pair<const long long, bool>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@m = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [11 x i64], align 16
@Hash = external dso_local global %"class.std::map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = call noundef i64 @_ZNKSt3mapIxbSt4lessIxESaISt4pairIKxbEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.preheader, label %6

.preheader:                                       ; preds = %1
  %4 = load i32, ptr @m, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

6:                                                ; preds = %1
  %7 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %8 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %9 = trunc nuw i8 %8 to i1
  br label %28

.lr.ph:                                           ; preds = %.preheader, %21
  %10 = phi i32 [ %22, %21 ], [ %4, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %21 ], [ 0, %.preheader ]
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds [11 x i64], ptr @a, i64 0, i64 %indvars.iv
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = srem i64 %11, %13
  %15 = sdiv i64 %11, %13
  %16 = icmp eq i64 %14, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %.lr.ph
  %18 = and i64 %13, 1
  %.not8 = icmp eq i64 %18, 0
  br i1 %.not8, label %25, label %19

19:                                               ; preds = %17
  %20 = call noundef zeroext i1 @_Z3dfsx(i64 noundef %15)
  br i1 %20, label %._crit_edge14, label %25

._crit_edge14:                                    ; preds = %19
  %.pre = load i32, ptr @m, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %._crit_edge14, %.lr.ph
  %22 = phi i32 [ %.pre, %._crit_edge14 ], [ %10, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !15

25:                                               ; preds = %17, %19
  %26 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i8 1, ptr %26, align 1, !tbaa !11
  br label %28

._crit_edge:                                      ; preds = %21, %.preheader
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i8 0, ptr %27, align 1, !tbaa !11
  br label %28

28:                                               ; preds = %25, %._crit_edge, %6
  %.1 = phi i1 [ %9, %6 ], [ true, %25 ], [ false, %._crit_edge ]
  ret i1 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIxbSt4lessIxESaISt4pairIKxbEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt3mapIxbSt4lessIxESaISt4pairIKxbEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 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" }

!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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass