; LLVM IR from ADJA/algos :: DataStructures (QueueWithMinimum)

; 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 [205000 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7enqueuei(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 nounwind uwtable
declare dso_local void @_Z7dequeuev() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6getMinv() #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %16, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %19

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %14)
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

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

20:                                               ; preds = %30, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %33

25:                                               ; preds = %20
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  call void @_Z7enqueuei(i32 noundef %29)
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  %34 = call noundef i32 @_Z6getMinv()
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %34)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %50, %33
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %53

43:                                               ; preds = %38
  call void @_Z7dequeuev()
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  call void @_Z7enqueuei(i32 noundef %47)
  %48 = call noundef i32 @_Z6getMinv()
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %48)
  br label %50

50:                                               ; preds = %43
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !12

53:                                               ; preds = %42
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #4

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 = { mustprogress norecurse 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 #4 = { "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 #5 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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 global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [205000 x i32], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7dequeuev() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6getMinv() local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not13 = icmp slt i32 %2, 1
  br i1 %.not13, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %.not1115 = icmp slt i32 %3, 1
  br i1 %.not1115, label %._crit_edge, label %.lr.ph17

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %4 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %indvars.iv
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %4)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %.not.not = icmp slt i64 %indvars.iv, %7
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph17, %.preheader
  %8 = tail call noundef i32 @_Z6getMinv()
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %8)
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %.not12.not18 = icmp slt i32 %10, %11
  br i1 %.not12.not18, label %.lr.ph21.preheader, label %._crit_edge22

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %12 = sext i32 %10 to i64
  br label %.lr.ph21

.lr.ph17:                                         ; preds = %.preheader, %.lr.ph17
  %indvars.iv24 = phi i64 [ %indvars.iv.next25, %.lr.ph17 ], [ 1, %.preheader ]
  %13 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %indvars.iv24
  %14 = load i32, ptr %13, align 4, !tbaa !5
  tail call void @_Z7enqueuei(i32 noundef %14)
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %15 = load i32, ptr @m, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %.not11.not = icmp slt i64 %indvars.iv24, %16
  br i1 %.not11.not, label %.lr.ph17, label %._crit_edge, !llvm.loop !11

._crit_edge22:                                    ; preds = %.lr.ph21, %._crit_edge
  ret i32 0

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %.lr.ph21
  %indvars.iv27 = phi i64 [ %12, %.lr.ph21.preheader ], [ %indvars.iv.next28, %.lr.ph21 ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, 1
  tail call void @_Z7dequeuev()
  %17 = getelementptr inbounds [205000 x i32], ptr @a, i64 0, i64 %indvars.iv.next28
  %18 = load i32, ptr %17, align 4, !tbaa !5
  tail call void @_Z7enqueuei(i32 noundef %18)
  %19 = tail call noundef i32 @_Z6getMinv()
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %19)
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %.not12.not = icmp slt i64 %indvars.iv.next28, %22
  br i1 %.not12.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !12
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 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 #2 = { mustprogress norecurse 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 = { nofree 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" }

!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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass