; LLVM IR from tangjz/acm-icpc :: lydsy/1406.ll (Z3dfsiSt4pairIiiE)

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

%"struct.std::pair" = type { i32, i32 }

@cnt = external dso_local global i32, align 4
@pp = external dso_local global [9 x i32], align 16
@sum = external dso_local global i32, align 4
@ans = external dso_local global [1024 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z5mergeSt4pairIiiES0_(i64, i64) #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 uwtable
define dso_local void @_Z3dfsiSt4pairIiiE(i32 noundef %0, i64 %1) #0 {
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca i32, align 4
  %5 = alloca %"struct.std::pair", align 4
  %6 = alloca %"struct.std::pair", align 4
  %7 = alloca %"struct.std::pair", align 4
  %8 = alloca i32, align 4
  %9 = alloca %"struct.std::pair", align 4
  %10 = alloca %"struct.std::pair", align 4
  %11 = alloca %"struct.std::pair", align 4
  %12 = alloca i32, align 4
  %13 = alloca %"struct.std::pair", align 4
  %14 = alloca %"struct.std::pair", align 4
  %15 = alloca %"struct.std::pair", align 4
  %16 = alloca i32, align 4
  %17 = alloca %"struct.std::pair", align 4
  %18 = alloca %"struct.std::pair", align 4
  %19 = alloca %"struct.std::pair", align 4
  %20 = alloca i32, align 4
  store i64 %1, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr @cnt, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %2
  %25 = getelementptr inbounds %"struct.std::pair", ptr %3, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load i32, ptr @sum, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @sum, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [1024 x i32], ptr @ans, i64 0, i64 %29
  store i32 %26, ptr %30, align 4, !tbaa !5
  br label %109

31:                                               ; preds = %2
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %3, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %35
  %37 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %36)
  store i64 %37, ptr %7, align 4
  %38 = load i64, ptr %6, align 4
  %39 = load i64, ptr %7, align 4
  %40 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %38, i64 %39)
  store i64 %40, ptr %5, align 4
  %41 = load i64, ptr %5, align 4
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %33, i64 %41)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 2
  br i1 %46, label %47, label %63

47:                                               ; preds = %31
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %3, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  store i32 %54, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %56
  %58 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %57)
  store i64 %58, ptr %11, align 4
  %59 = load i64, ptr %10, align 4
  %60 = load i64, ptr %11, align 4
  %61 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %59, i64 %60)
  store i64 %61, ptr %9, align 4
  %62 = load i64, ptr %9, align 4
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %49, i64 %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %63

63:                                               ; preds = %47, %31
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = and i32 %67, 1
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %109, label %70

70:                                               ; preds = %63
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = icmp sgt i32 %74, 4
  br i1 %75, label %76, label %109

76:                                               ; preds = %70
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %3, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = ashr i32 %82, 1
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %16, align 4, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %86
  %88 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %16, ptr noundef nonnull align 4 dereferenceable(4) %87)
  store i64 %88, ptr %15, align 4
  %89 = load i64, ptr %14, align 4
  %90 = load i64, ptr %15, align 4
  %91 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %89, i64 %90)
  store i64 %91, ptr %13, align 4
  %92 = load i64, ptr %13, align 4
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %78, i64 %92)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %3, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = ashr i32 %98, 1
  %100 = sub nsw i32 %99, 1
  store i32 %100, ptr %20, align 4, !tbaa !5
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %102
  %104 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %103)
  store i64 %104, ptr %19, align 4
  %105 = load i64, ptr %18, align 4
  %106 = load i64, ptr %19, align 4
  %107 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %105, i64 %106)
  store i64 %107, ptr %17, align 4
  %108 = load i64, ptr %17, align 4
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %94, i64 %108)
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  br label %109

109:                                              ; preds = %76, %70, %63, %24
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}


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

@cnt = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local global [9 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global [1024 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z5mergeSt4pairIiiES0_(i64, i64) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiSt4pairIiiE(i32 noundef %0, i64 %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = load i32, ptr @cnt, align 4, !tbaa !5
  %8 = icmp eq i32 %7, %0
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  %.sroa.026.0.extract.trunc = trunc i64 %1 to i32
  %10 = load i32, ptr @sum, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @sum, align 4, !tbaa !5
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [1024 x i32], ptr @ans, i64 0, i64 %12
  store i32 %.sroa.026.0.extract.trunc, ptr %13, align 4, !tbaa !5
  br label %.thread

14:                                               ; preds = %2
  %15 = add nsw i32 %0, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %0 to i64
  %17 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %16
  %18 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %19 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %1, i64 %18)
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %15, i64 %19)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %20 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 2
  br i1 %.not, label %.thread, label %21

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  %22 = add nsw i32 %20, -1
  store i32 %22, ptr %4, align 4, !tbaa !5
  %23 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %24 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %1, i64 %23)
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %15, i64 %24)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  %.pre = load i32, ptr %17, align 4, !tbaa !5
  %25 = and i32 %.pre, 1
  %.not48 = icmp eq i32 %25, 0
  %26 = icmp sgt i32 %.pre, 4
  %or.cond = and i1 %26, %.not48
  br i1 %or.cond, label %27, label %.thread

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %28 = lshr exact i32 %.pre, 1
  %29 = add nuw nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !5
  %30 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %31 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %1, i64 %30)
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %15, i64 %31)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %32 = load i32, ptr %17, align 4, !tbaa !5
  %33 = ashr i32 %32, 1
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %6, align 4, !tbaa !5
  %35 = call i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %36 = call i64 @_Z5mergeSt4pairIiiES0_(i64 %1, i64 %35)
  call void @_Z3dfsiSt4pairIiiE(i32 noundef %15, i64 %36)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  br label %.thread

.thread:                                          ; preds = %14, %27, %21, %9
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

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


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