; LLVM IR from tangjz/acm-icpc :: projecteuler/594.ll (Z4dfs1ii)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [11 x [11 x i64]], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4dfs2ii(i32 noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4dfs1ii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %17, label %20

17:                                               ; preds = %2
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = call noundef i64 @_Z4dfs2ii(i32 noundef %18, i32 noundef 1)
  store i64 %19, ptr %3, align 8
  br label %92

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %25, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %7, align 4, !tbaa !5
  br label %31

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %28, %24
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [11 x [11 x i64]], ptr @a, i64 0, i64 %33
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [11 x i64], ptr %34, i64 0, i64 %36
  store i64 0, ptr %37, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %62, %31
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %65

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 1, ptr %11, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %58, %43
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %61

49:                                               ; preds = %44
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [11 x [11 x i64]], ptr @a, i64 0, i64 %51
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [11 x i64], ptr %52, i64 0, i64 %54
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %55)
  %57 = load i64, ptr %56, align 8, !tbaa !9
  store i64 %57, ptr %8, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %49
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !5
  br label %44, !llvm.loop !11

61:                                               ; preds = %48
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %9, align 4, !tbaa !5
  br label %38, !llvm.loop !13

65:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %66 = load i64, ptr %8, align 8, !tbaa !9
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr %13, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %87, %65
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = load i32, ptr @m, align 4, !tbaa !5
  %71 = icmp sle i32 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %68
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %90

73:                                               ; preds = %68
  %74 = load i32, ptr %13, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [11 x [11 x i64]], ptr @a, i64 0, i64 %77
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [11 x i64], ptr %78, i64 0, i64 %80
  store i64 %75, ptr %81, align 8, !tbaa !9
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = call noundef i64 @_Z4dfs1ii(i32 noundef %82, i32 noundef %83)
  %85 = load i64, ptr %12, align 8, !tbaa !9
  %86 = add nsw i64 %85, %84
  store i64 %86, ptr %12, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %73
  %88 = load i32, ptr %13, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %13, align 4, !tbaa !5
  br label %68, !llvm.loop !14

90:                                               ; preds = %72
  %91 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %91, ptr %3, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %92

92:                                               ; preds = %90, %17
  %93 = load i64, ptr %3, align 8
  ret i64 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [11 x [11 x i64]], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4dfs2ii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4dfs1ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp slt i32 %4, %0
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call noundef i64 @_Z4dfs2ii(i32 noundef %4, i32 noundef 1)
  br label %28

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  %9 = icmp sle i32 %4, %1
  %10 = add i32 %1, 1
  %11 = zext i1 %9 to i32
  %.029 = add nsw i32 %11, %0
  %.028 = select i1 %9, i32 1, i32 %10
  %12 = sext i32 %0 to i64
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds [11 x [11 x i64]], ptr @a, i64 0, i64 %12, i64 %13
  store i64 0, ptr %14, align 8, !tbaa !9
  %.not38 = icmp slt i32 %0, 1
  %.not3536 = icmp slt i32 %1, 1
  %or.cond = or i1 %.not38, %.not3536
  br i1 %or.cond, label %._crit_edge40, label %.preheader.preheader

.preheader.preheader:                             ; preds = %8
  %15 = add nuw i32 %0, 1
  %wide.trip.count51 = zext i32 %15 to i64
  %wide.trip.count = zext i32 %10 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv48 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next49, %._crit_edge ]
  br label %20

._crit_edge40.loopexit46:                         ; preds = %._crit_edge
  %16 = trunc i64 %23 to i32
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %._crit_edge40.loopexit46, %8
  %17 = phi i32 [ %16, %._crit_edge40.loopexit46 ], [ 0, %8 ]
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %.not3441 = icmp slt i32 %18, %17
  br i1 %.not3441, label %._crit_edge45, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge40
  %19 = sext i32 %17 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %20
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count51
  br i1 %exitcond52.not, label %._crit_edge40.loopexit46, label %.preheader, !llvm.loop !11

20:                                               ; preds = %.preheader, %20
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %20 ]
  %21 = getelementptr inbounds [11 x [11 x i64]], ptr @a, i64 0, i64 %indvars.iv48, i64 %indvars.iv
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = load i64, ptr %22, align 8, !tbaa !9
  store i64 %23, ptr %3, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %20, !llvm.loop !13

._crit_edge45:                                    ; preds = %.lr.ph, %._crit_edge40
  %.025.lcssa = phi i64 [ 0, %._crit_edge40 ], [ %25, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %28

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv53 = phi i64 [ %19, %.lr.ph.preheader ], [ %indvars.iv.next54, %.lr.ph ]
  %.02542 = phi i64 [ 0, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  store i64 %indvars.iv53, ptr %14, align 8, !tbaa !9
  %24 = call noundef i64 @_Z4dfs1ii(i32 noundef %.029, i32 noundef %.028)
  %25 = add nsw i64 %24, %.02542
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, 1
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not34.not = icmp slt i64 %indvars.iv53, %27
  br i1 %.not34.not, label %.lr.ph, label %._crit_edge45, !llvm.loop !14

28:                                               ; preds = %._crit_edge45, %6
  %.030 = phi i64 [ %7, %6 ], [ %.025.lcssa, %._crit_edge45 ]
  ret i64 %.030
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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