; LLVM IR from tangjz/acm-icpc :: codeforces/sgu/537.ll (Z3dfsiPSt4pairIxiERiPxx)

; 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, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %3, i64 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %23, label %15

15:                                               ; preds = %5
  %16 = load i64, ptr %10, align 8, !tbaa !11
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i64, ptr %17, i64 %21
  store i64 %16, ptr %22, align 8, !tbaa !11
  br label %55

23:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %6, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %"struct.std::pair", ptr %24, i64 %27
  store ptr %28, ptr %11, align 8, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !11
  call void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %29, ptr noundef %30, ptr noundef nonnull align 4 dereferenceable(4) %31, ptr noundef %32, i64 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 1, ptr %12, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %51, %23
  %35 = load i32, ptr %12, align 4, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds %"struct.std::pair", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = icmp sle i32 %35, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %34
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %11, align 8, !tbaa !9
  %47 = getelementptr inbounds %"struct.std::pair", ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !15
  %49 = load i64, ptr %10, align 8, !tbaa !11
  %50 = mul nsw i64 %49, %48
  store i64 %50, ptr %10, align 8, !tbaa !11
  call void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %42, ptr noundef %43, ptr noundef nonnull align 4 dereferenceable(4) %44, ptr noundef %45, i64 noundef %50)
  br label %51

51:                                               ; preds = %41
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %12, align 4, !tbaa !5
  br label %34, !llvm.loop !16

54:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %55

55:                                               ; preds = %54, %15
  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: 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 = !{!"int", !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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTSSt4pairIxiE", !12, i64 0, !6, i64 8}
!15 = !{!14, !12, i64 0}
!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, i32, [4 x i8] }>

; Function Attrs: mustprogress nofree nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %6, label %11

6:                                                ; preds = %5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds i64, ptr %3, i64 %9
  store i64 %4, ptr %10, align 8, !tbaa !9
  br label %.loopexit

11:                                               ; preds = %5
  %12 = add nsw i32 %0, -1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds %"struct.std::pair", ptr %1, i64 %13
  tail call void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %12, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %3, i64 noundef %4)
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %.not2122 = icmp slt i32 %16, 1
  br i1 %.not2122, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.024 = phi i32 [ %19, %.lr.ph ], [ 1, %11 ]
  %.01923 = phi i64 [ %18, %.lr.ph ], [ %4, %11 ]
  %17 = load i64, ptr %14, align 8, !tbaa !13
  %18 = mul nsw i64 %17, %.01923
  tail call void @_Z3dfsiPSt4pairIxiERiPxx(i32 noundef %12, ptr noundef nonnull %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %3, i64 noundef %18)
  %19 = add nuw nsw i32 %.024, 1
  %20 = load i32, ptr %15, align 8, !tbaa !11
  %.not21.not = icmp slt i32 %.024, %20
  br i1 %.not21.not, label %.lr.ph, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph, %11, %6
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(argmem: readwrite) 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 = !{!"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, !6, i64 8}
!12 = !{!"_ZTSSt4pairIxiE", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass