; LLVM IR from tangjz/acm-icpc :: uvalive/7504.ll (Z3dfsixx)

; 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 { i64, i64 }
%struct.Factor = type { i32, [13 x i32], [13 x i32], i32, [6721 x %"struct.std::pair"] }

@cur = external dso_local global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsixx(i32 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %"struct.std::pair", align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load ptr, ptr @cur, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.Factor, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp eq i32 %9, %12
  br i1 %13, label %14, label %32

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %15 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %16 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %17 = extractvalue { i64, i64 } %15, 0
  store i64 %17, ptr %16, align 8
  %18 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %19 = extractvalue { i64, i64 } %15, 1
  store i64 %19, ptr %18, align 8
  %20 = load ptr, ptr @cur, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.Factor, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr @cur, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.Factor, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [6721 x %"struct.std::pair"], ptr %21, i64 0, i64 %25
  %27 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16) %26, ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  %28 = load ptr, ptr @cur, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.Factor, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !15
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !15
  br label %75

32:                                               ; preds = %3
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  call void @_Z3dfsixx(i32 noundef %34, i64 noundef %35, i64 noundef %36)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %72, %32
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load ptr, ptr @cur, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.Factor, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [13 x i32], ptr %40, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sle i32 %38, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %75

47:                                               ; preds = %37
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = load ptr, ptr @cur, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.Factor, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [13 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = mul nsw i64 %57, %56
  store i64 %58, ptr %5, align 8, !tbaa !9
  %59 = load ptr, ptr @cur, align 8, !tbaa !11
  %60 = getelementptr inbounds %struct.Factor, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [13 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = icmp eq i32 %65, 1
  %67 = zext i1 %66 to i32
  %68 = sub nsw i32 %64, %67
  %69 = sext i32 %68 to i64
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = mul nsw i64 %70, %69
  store i64 %71, ptr %6, align 8, !tbaa !9
  call void @_Z3dfsixx(i32 noundef %49, i64 noundef %58, i64 noundef %71)
  br label %72

72:                                               ; preds = %47
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %8, align 4, !tbaa !5
  br label %37, !llvm.loop !16

75:                                               ; preds = %46, %14
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; 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 = { 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 #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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS6Factor", !6, i64 0, !7, i64 4, !7, i64 56, !6, i64 108, !7, i64 112}
!15 = !{!14, !6, i64 108}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

@cur = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsixx(i32 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca %"struct.std::pair", align 8
  store i64 %1, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr @cur, align 8, !tbaa !9
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %10, label %26

10:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %11 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %12 = extractvalue { i64, i64 } %11, 0
  store i64 %12, ptr %6, align 8
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  %14 = extractvalue { i64, i64 } %11, 1
  store i64 %14, ptr %13, align 8
  %15 = load ptr, ptr @cur, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 112
  %17 = getelementptr inbounds i8, ptr %15, i64 108
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [6721 x %"struct.std::pair"], ptr %16, i64 0, i64 %19
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  %22 = load ptr, ptr @cur, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %22, i64 108
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !14
  br label %.loopexit

26:                                               ; preds = %3
  %27 = add nsw i32 %0, 1
  tail call void @_Z3dfsixx(i32 noundef %27, i64 noundef %1, i64 noundef %2)
  %28 = sext i32 %0 to i64
  %29 = load ptr, ptr @cur, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %29, i64 56
  %31 = getelementptr inbounds [13 x i32], ptr %30, i64 0, i64 %28
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %.not12 = icmp slt i32 %32, 1
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %26, %.lr.ph
  %33 = phi ptr [ %46, %.lr.ph ], [ %29, %26 ]
  %.013 = phi i32 [ %45, %.lr.ph ], [ 1, %26 ]
  %34 = phi i64 [ %40, %.lr.ph ], [ %1, %26 ]
  %35 = phi i64 [ %44, %.lr.ph ], [ %2, %26 ]
  %36 = getelementptr inbounds i8, ptr %33, i64 4
  %37 = getelementptr inbounds [13 x i32], ptr %36, i64 0, i64 %28
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %34, %39
  %41 = icmp eq i32 %.013, 1
  %.neg = sext i1 %41 to i32
  %42 = add i32 %38, %.neg
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %35, %43
  tail call void @_Z3dfsixx(i32 noundef %27, i64 noundef %40, i64 noundef %44)
  %45 = add nuw nsw i32 %.013, 1
  %46 = load ptr, ptr @cur, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i64 56
  %48 = getelementptr inbounds [13 x i32], ptr %47, i64 0, i64 %28
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %.not.not = icmp slt i32 %.013, %49
  br i1 %.not.not, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %26, %10
  ret void
}

; 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 uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSEOS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS6Factor", !13, i64 0, !7, i64 4, !7, i64 56, !13, i64 108, !7, i64 112}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 108}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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