; LLVM IR from upupming/algorithm :: kick-start/2020/RoundG/C-Combination_Lock.ll (Z5solvev)

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

@w = external dso_local global i32, align 4
@x = external dso_local global [200020 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %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 i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 1000000000000000000, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %124, %0
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr @w, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %127

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = load i32, ptr @w, align 4, !tbaa !9
  %21 = add nsw i32 %19, %20
  store i32 %21, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %22, %23
  %25 = sub nsw i32 %24, 1
  %26 = ashr i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %56

29:                                               ; preds = %18
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %30 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %30, ptr %8, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %49, %29
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %52

36:                                               ; preds = %31
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = sub nsw i64 %40, %44
  %46 = call noundef i64 @_ZSt3absx(i64 noundef %45)
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = add nsw i64 %47, %46
  store i64 %48, ptr %3, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %36
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %31, !llvm.loop !11

52:                                               ; preds = %35
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %54 = load i64, ptr %53, align 8, !tbaa !5
  store i64 %54, ptr %1, align 8, !tbaa !5
  %55 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %55, ptr %2, align 8, !tbaa !5
  br label %123

56:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !5
  %67 = sub nsw i64 %61, %66
  %68 = call noundef i64 @_ZSt3absx(i64 noundef %67)
  store i64 %68, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %69 = load i32, ptr @w, align 4, !tbaa !9
  %70 = sdiv i32 %69, 2
  %71 = sext i32 %70 to i64
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !5
  %81 = sub nsw i64 %76, %80
  %82 = call noundef i64 @_ZSt3absx(i64 noundef %81)
  %83 = mul nsw i64 %71, %82
  store i64 %83, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = sub nsw i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %90
  %92 = load i64, ptr %91, align 8, !tbaa !5
  %93 = sub nsw i64 %88, %92
  %94 = call noundef i64 @_ZSt3absx(i64 noundef %93)
  store i64 %94, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %95 = load i32, ptr @w, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  %97 = sdiv i32 %96, 2
  %98 = sext i32 %97 to i64
  %99 = load i32, ptr %7, align 4, !tbaa !9
  %100 = sub nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %101
  %103 = load i64, ptr %102, align 8, !tbaa !5
  %104 = load i32, ptr %7, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %105
  %107 = load i64, ptr %106, align 8, !tbaa !5
  %108 = sub nsw i64 %103, %107
  %109 = call noundef i64 @_ZSt3absx(i64 noundef %108)
  %110 = mul nsw i64 %98, %109
  store i64 %110, ptr %12, align 8, !tbaa !5
  %111 = load i64, ptr %2, align 8, !tbaa !5
  %112 = load i64, ptr %9, align 8, !tbaa !5
  %113 = sub nsw i64 %111, %112
  %114 = load i64, ptr %10, align 8, !tbaa !5
  %115 = sub nsw i64 %113, %114
  %116 = load i64, ptr %11, align 8, !tbaa !5
  %117 = add nsw i64 %115, %116
  %118 = load i64, ptr %12, align 8, !tbaa !5
  %119 = add nsw i64 %117, %118
  store i64 %119, ptr %3, align 8, !tbaa !5
  %120 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %121 = load i64, ptr %120, align 8, !tbaa !5
  store i64 %121, ptr %1, align 8, !tbaa !5
  %122 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %122, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %123

123:                                              ; preds = %56, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %124

124:                                              ; preds = %123
  %125 = load i32, ptr %4, align 4, !tbaa !9
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %4, align 4, !tbaa !9
  br label %13, !llvm.loop !13

127:                                              ; preds = %17
  %128 = load i64, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i64 %128
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #2

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

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

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@w = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local local_unnamed_addr global [200020 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  store i64 1000000000000000000, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = load i32, ptr @w, align 4, !tbaa !9
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph34, label %._crit_edge35

._crit_edge35:                                    ; preds = %._crit_edge, %0
  %5 = phi i64 [ 1000000000000000000, %0 ], [ %storemerge, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i64 %5

.lr.ph34:                                         ; preds = %0, %._crit_edge
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %._crit_edge ], [ 0, %0 ]
  %6 = phi i32 [ %66, %._crit_edge ], [ %3, %0 ]
  %.032 = phi i64 [ %.1, %._crit_edge ], [ undef, %0 ]
  %7 = trunc nuw nsw i64 %indvars.iv37 to i32
  %8 = add nsw i32 %6, %7
  %9 = add nsw i64 %indvars.iv37, -1
  %10 = trunc nsw i64 %9 to i32
  %11 = add i32 %8, %10
  %12 = ashr i32 %11, 1
  %13 = icmp eq i64 %indvars.iv37, 0
  br i1 %13, label %14, label %26

14:                                               ; preds = %.lr.ph34
  store i64 0, ptr %2, align 8, !tbaa !5
  %15 = icmp sgt i32 %8, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %14
  %16 = sext i32 %12 to i64
  %17 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %16
  %wide.trip.count = zext i32 %6 to i64
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %18 ]
  %19 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %indvars.iv
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = load i64, ptr %17, align 8, !tbaa !5
  %22 = sub nsw i64 %20, %21
  %23 = call noundef i64 @_ZSt3absx(i64 noundef %22)
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = add nsw i64 %24, %23
  store i64 %25, ptr %2, align 8, !tbaa !5
  %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 %18, !llvm.loop !11

26:                                               ; preds = %.lr.ph34
  %27 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %9
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i32 %12, -1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = sub nsw i64 %28, %32
  %34 = call noundef i64 @_ZSt3absx(i64 noundef %33)
  %35 = load i32, ptr @w, align 4, !tbaa !9
  %36 = sdiv i32 %35, 2
  %37 = sext i32 %36 to i64
  %38 = load i64, ptr %31, align 8, !tbaa !5
  %39 = sext i32 %12 to i64
  %40 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = sub nsw i64 %38, %41
  %43 = call noundef i64 @_ZSt3absx(i64 noundef %42)
  %44 = mul nsw i64 %43, %37
  %45 = add nsw i32 %8, -1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200020 x i64], ptr @x, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i64, ptr %40, align 8, !tbaa !5
  %50 = sub nsw i64 %48, %49
  %51 = call noundef i64 @_ZSt3absx(i64 noundef %50)
  %52 = load i32, ptr @w, align 4, !tbaa !9
  %53 = add nsw i32 %52, -1
  %54 = sdiv i32 %53, 2
  %55 = sext i32 %54 to i64
  %56 = load i64, ptr %31, align 8, !tbaa !5
  %57 = load i64, ptr %40, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = call noundef i64 @_ZSt3absx(i64 noundef %58)
  %60 = mul nsw i64 %59, %55
  %61 = add i64 %34, %44
  %62 = sub i64 %.032, %61
  %63 = add nsw i64 %62, %51
  %64 = add nsw i64 %63, %60
  store i64 %64, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %18, %14, %26
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %storemerge = load i64, ptr %65, align 8, !tbaa !5
  store i64 %storemerge, ptr %1, align 8, !tbaa !5
  %.1 = load i64, ptr %2, align 8, !tbaa !5
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %66 = load i32, ptr @w, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = icmp slt i64 %indvars.iv.next38, %67
  br i1 %68, label %.lr.ph34, label %._crit_edge35, !llvm.loop !13
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #2

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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