; LLVM IR from andreimaximov/algorithms :: codeforces/running-with-obstacles/main.ll (Z3dfsi)

; 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
@S = external dso_local global i32, align 4
@D = external dso_local global i32, align 4
@X = external dso_local global [200010 x i32], align 16
@DP = external dso_local global [200001 x i32], align 16
@.str.3 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._Z3dfsi = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3runi(i32 noundef) #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
declare dso_local void @_Z4jumpi(i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sge i32 %7, 0
  br i1 %8, label %9, label %13

9:                                                ; preds = %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @N, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br label %13

13:                                               ; preds = %9, %1
  %14 = phi i1 [ false, %1 ], [ %12, %9 ]
  br i1 %14, label %15, label %16

15:                                               ; preds = %13
  br label %18

16:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.3, i32 noundef 37, ptr noundef @__PRETTY_FUNCTION__._Z3dfsi) #3
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %34

24:                                               ; preds = %18
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 2
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  br label %33

31:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.3, i32 noundef 42, ptr noundef @__PRETTY_FUNCTION__._Z3dfsi) #3
  unreachable

32:                                               ; No predecessors!
  br label %33

33:                                               ; preds = %32, %30
  store i1 false, ptr %2, align 1
  br label %150

34:                                               ; preds = %18
  %35 = load i32, ptr @M, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp slt i32 %35, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %34
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %43
  store i32 2, ptr %44, align 4, !tbaa !5
  store i1 false, ptr %2, align 1
  br label %150

45:                                               ; preds = %34
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr @N, align 4, !tbaa !5
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %57, label %49

49:                                               ; preds = %45
  %50 = load i32, ptr @M, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp slt i32 %50, %55
  br i1 %56, label %57, label %68

57:                                               ; preds = %49, %45
  %58 = load i32, ptr @M, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sub nsw i32 %58, %62
  %64 = sub nsw i32 %63, 1
  call void @_Z3runi(i32 noundef %64)
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %66
  store i32 1, ptr %67, align 4, !tbaa !5
  br label %144

68:                                               ; preds = %49
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %70
  store i32 2, ptr %71, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sub nsw i32 %76, %80
  %82 = sub nsw i32 %81, 2
  store i32 %82, ptr %4, align 4, !tbaa !5
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = load i32, ptr @S, align 4, !tbaa !5
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %86, label %87

86:                                               ; preds = %68
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %141

87:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %137, %87
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = icmp ne i32 %94, 1
  br i1 %95, label %96, label %115

96:                                               ; preds = %90
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = load i32, ptr @N, align 4, !tbaa !5
  %99 = icmp sle i32 %97, %98
  br i1 %99, label %100, label %115

100:                                              ; preds = %96
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  %106 = load i32, ptr %3, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = sub nsw i32 %110, 1
  %112 = load i32, ptr @D, align 4, !tbaa !5
  %113 = add nsw i32 %111, %112
  %114 = icmp sle i32 %105, %113
  br label %115

115:                                              ; preds = %100, %96, %90
  %116 = phi i1 [ false, %96 ], [ false, %90 ], [ %114, %100 ]
  br i1 %116, label %117, label %140

117:                                              ; preds = %115
  %118 = load i32, ptr %6, align 4, !tbaa !5
  %119 = call noundef zeroext i1 @_Z3dfsi(i32 noundef %118)
  br i1 %119, label %120, label %137

120:                                              ; preds = %117
  %121 = load i32, ptr %3, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %122
  store i32 1, ptr %123, align 4, !tbaa !5
  %124 = load i32, ptr %6, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %125
  %127 = load i32, ptr %126, align 4, !tbaa !5
  %128 = add nsw i32 %127, 1
  %129 = load i32, ptr %3, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %131
  %133 = load i32, ptr %132, align 4, !tbaa !5
  %134 = sub nsw i32 %128, %133
  %135 = add nsw i32 %134, 1
  call void @_Z4jumpi(i32 noundef %135)
  %136 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3runi(i32 noundef %136)
  br label %137

137:                                              ; preds = %120, %117
  %138 = load i32, ptr %6, align 4, !tbaa !5
  %139 = add nsw i32 %138, 1
  store i32 %139, ptr %6, align 4, !tbaa !5
  br label %90, !llvm.loop !9

140:                                              ; preds = %115
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  store i32 0, ptr %5, align 4
  br label %141

141:                                              ; preds = %140, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %142 = load i32, ptr %5, align 4
  switch i32 %142, label %152 [
    i32 0, label %143
    i32 1, label %150
  ]

143:                                              ; preds = %141
  br label %144

144:                                              ; preds = %143, %57
  %145 = load i32, ptr %3, align 4, !tbaa !5
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %146
  %148 = load i32, ptr %147, align 4, !tbaa !5
  %149 = icmp eq i32 %148, 1
  store i1 %149, ptr %2, align 1
  br label %150

150:                                              ; preds = %144, %141, %41, %33
  %151 = load i1, ptr %2, align 1
  ret i1 %151

152:                                              ; preds = %141
  unreachable
}

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 = { noreturn nounwind "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 = { noreturn nounwind }
attributes #4 = { 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 = distinct !{!9, !10}
!10 = !{!"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"

@N = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local local_unnamed_addr global i32, align 4
@D = external dso_local local_unnamed_addr global i32, align 4
@X = external dso_local local_unnamed_addr global [200010 x i32], align 16
@DP = external dso_local local_unnamed_addr global [200001 x i32], align 16
@.str.3 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._Z3dfsi = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3runi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4jumpi(i32 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, -1
  %3 = load i32, ptr @N, align 4
  %4 = icmp sge i32 %3, %0
  %5 = select i1 %2, i1 %4, i1 false
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.3, i32 noundef 37, ptr noundef nonnull @__PRETTY_FUNCTION__._Z3dfsi) #2
  unreachable

7:                                                ; preds = %1
  %8 = zext nneg i32 %0 to i64
  %9 = getelementptr inbounds [200001 x i32], ptr @DP, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  switch i32 %10, label %11 [
    i32 0, label %12
    i32 2, label %.critedge.thread
  ]

11:                                               ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.3, i32 noundef 42, ptr noundef nonnull @__PRETTY_FUNCTION__._Z3dfsi) #2
  unreachable

12:                                               ; preds = %7
  %13 = load i32, ptr @M, align 4, !tbaa !5
  %14 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %8
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  store i32 2, ptr %9, align 4, !tbaa !5
  br label %.critedge.thread

18:                                               ; preds = %12
  %19 = icmp eq i32 %3, %0
  br i1 %19, label %26, label %20

20:                                               ; preds = %18
  %21 = add nuw nsw i32 %0, 1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp slt i32 %13, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %20, %18
  %27 = xor i32 %15, -1
  %28 = add i32 %13, %27
  tail call void @_Z3runi(i32 noundef %28)
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %.critedge.thread

29:                                               ; preds = %20
  store i32 2, ptr %9, align 4, !tbaa !5
  %30 = sub nsw i32 %24, %15
  %31 = add nsw i32 %30, -2
  %32 = load i32, ptr @S, align 4, !tbaa !5
  %.not = icmp sge i32 %31, %32
  %.not3539.not = icmp sgt i32 %3, %0
  %or.cond44 = select i1 %.not, i1 %.not3539.not, i1 false
  br i1 %or.cond44, label %.lr.ph.preheader, label %.critedge.thread

.lr.ph.preheader:                                 ; preds = %29
  %indvars.iv45 = add nuw nsw i64 %8, 1
  %33 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %indvars.iv45
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %23, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  %37 = load i32, ptr @D, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %.not36.not46 = icmp slt i32 %34, %38
  br i1 %.not36.not46, label %.lr.ph48, label %.critedge.thread

.lr.ph:                                           ; preds = %53
  %indvars.iv = add nuw nsw i64 %indvars.iv47, 1
  %39 = getelementptr inbounds [200010 x i32], ptr @X, i64 0, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %23, align 4, !tbaa !5
  %42 = add nsw i32 %41, -1
  %43 = load i32, ptr @D, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %.not36.not = icmp slt i32 %40, %44
  br i1 %.not36.not, label %.lr.ph48, label %.critedge.loopexit.loopexit, !llvm.loop !9

.lr.ph48:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %45 = phi ptr [ %39, %.lr.ph ], [ %33, %.lr.ph.preheader ]
  %indvars.iv47 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv45, %.lr.ph.preheader ]
  %46 = trunc nuw i64 %indvars.iv47 to i32
  %47 = tail call noundef zeroext i1 @_Z3dfsi(i32 noundef %46)
  br i1 %47, label %48, label %53

48:                                               ; preds = %.lr.ph48
  store i32 1, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %45, align 4, !tbaa !5
  %50 = load i32, ptr %23, align 4, !tbaa !5
  %51 = add i32 %49, 2
  %52 = sub i32 %51, %50
  tail call void @_Z4jumpi(i32 noundef %52)
  tail call void @_Z3runi(i32 noundef %31)
  br label %53

53:                                               ; preds = %48, %.lr.ph48
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %.not34 = icmp eq i32 %54, 1
  %55 = load i32, ptr @N, align 4
  %.not35 = icmp sle i32 %55, %46
  %or.cond = select i1 %.not34, i1 true, i1 %.not35
  br i1 %or.cond, label %.critedge.loopexit.loopexit, label %.lr.ph, !llvm.loop !9

.critedge.loopexit.loopexit:                      ; preds = %53, %.lr.ph
  %56 = icmp eq i32 %54, 1
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.lr.ph.preheader, %.critedge.loopexit.loopexit, %26, %29, %7, %17
  %.1 = phi i1 [ false, %17 ], [ false, %7 ], [ false, %29 ], [ true, %26 ], [ false, %.lr.ph.preheader ], [ %56, %.critedge.loopexit.loopexit ]
  ret i1 %.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 = { noreturn nounwind "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 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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