; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SNACKDOWN/17/Elimination/F/F.ll (Z3getx)

; 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 i64, align 8
@m = external dso_local global i64, align 8
@e = external dso_local global i64, align 8
@c = external dso_local global [300 x i64], align 16
@d = external dso_local global [300 x i64], align 16

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

9:                                                ; preds = %93, %1
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = load i64, ptr @m, align 8, !tbaa !5
  %13 = icmp sle i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  store i32 2, ptr %6, align 4
  br label %96

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 -1, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %16 = load i32, ptr %3, align 4, !tbaa !9
  store i32 %16, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %70, %15
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = load i64, ptr @n, align 8, !tbaa !5
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 5, ptr %6, align 4
  br label %73

23:                                               ; preds = %17
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [300 x i64], ptr @c, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = sub nsw i64 %27, %28
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [300 x i64], ptr @d, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = sub nsw i64 %29, %33
  %35 = call noundef i64 @_ZSt3absx(i64 noundef %34)
  %36 = load i64, ptr @e, align 8, !tbaa !5
  %37 = icmp sle i64 %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %23
  %39 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %39, ptr %7, align 4, !tbaa !9
  store i32 5, ptr %6, align 4
  br label %73

40:                                               ; preds = %23
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [300 x i64], ptr @c, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = load i64, ptr %2, align 8, !tbaa !5
  %46 = sub nsw i64 %44, %45
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [300 x i64], ptr @d, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = icmp sge i64 %46, %50
  br i1 %51, label %52, label %69

52:                                               ; preds = %40
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [300 x i64], ptr @c, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [300 x i64], ptr @d, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = sub nsw i64 %58, %62
  %64 = call noundef i64 @_ZSt3absx(i64 noundef %63)
  %65 = load i64, ptr @e, align 8, !tbaa !5
  %66 = icmp sgt i64 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %52
  %68 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %68, ptr %3, align 4, !tbaa !9
  store i32 5, ptr %6, align 4
  br label %73

69:                                               ; preds = %52, %40
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !11

73:                                               ; preds = %67, %38, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = icmp ne i32 %75, -1
  br i1 %76, label %77, label %89

77:                                               ; preds = %74
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !9
  %80 = load i32, ptr %4, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @n, ptr noundef nonnull align 8 dereferenceable(8) @m)
  %83 = load i64, ptr %82, align 8, !tbaa !5
  %84 = icmp eq i64 %81, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %77
  store i32 2, ptr %6, align 4
  br label %90

86:                                               ; preds = %77
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %3, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %86, %74
  store i32 0, ptr %6, align 4
  br label %90

90:                                               ; preds = %89, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %91 = load i32, ptr %6, align 4
  switch i32 %91, label %96 [
    i32 0, label %92
  ]

92:                                               ; preds = %90
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %5, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !13

96:                                               ; preds = %90, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %4, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %98
}

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

@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@e = external dso_local local_unnamed_addr global i64, align 8
@c = external dso_local local_unnamed_addr global [300 x i64], align 16
@d = external dso_local local_unnamed_addr global [300 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3getx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @m, align 8, !tbaa !5
  %.not57 = icmp slt i64 %2, 1
  br i1 %.not57, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %1, %.thread43
  %indvars.iv65 = phi i64 [ %indvars.iv.next66, %.thread43 ], [ 1, %1 ]
  %.02559 = phi i32 [ %.248, %.thread43 ], [ 0, %1 ]
  %.02658 = phi i32 [ %.32947, %.thread43 ], [ 1, %1 ]
  %3 = sext i32 %.02658 to i64
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %.not3453 = icmp slt i64 %4, %3
  br i1 %.not3453, label %.thread43, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds [300 x i64], ptr @d, i64 0, i64 %indvars.iv65
  br label %6

6:                                                ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ %3, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %7 = getelementptr inbounds [300 x i64], ptr @c, i64 0, i64 %indvars.iv
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = load i64, ptr %5, align 8, !tbaa !5
  %10 = add i64 %9, %0
  %11 = sub i64 %8, %10
  %12 = tail call noundef i64 @_ZSt3absx(i64 noundef %11)
  %13 = load i64, ptr @e, align 8, !tbaa !5
  %.not35 = icmp sgt i64 %12, %13
  br i1 %.not35, label %14, label %25

14:                                               ; preds = %6
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = sub nsw i64 %15, %0
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %.not36 = icmp slt i64 %16, %17
  br i1 %.not36, label %23, label %18

18:                                               ; preds = %14
  %19 = sub nsw i64 %16, %17
  %20 = tail call noundef i64 @_ZSt3absx(i64 noundef %19)
  %21 = load i64, ptr @e, align 8, !tbaa !5
  %22 = icmp sgt i64 %20, %21
  br i1 %22, label %.thread43.loopexit.split.loop.exit, label %23

23:                                               ; preds = %14, %18
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %24 = load i64, ptr @n, align 8, !tbaa !5
  %.not34.not = icmp sgt i64 %24, %indvars.iv
  br i1 %.not34.not, label %6, label %.thread43, !llvm.loop !9

25:                                               ; preds = %6
  %.not37 = icmp eq i64 %indvars.iv, -1
  br i1 %.not37, label %.thread43, label %26

26:                                               ; preds = %25
  %27 = trunc nsw i64 %indvars.iv to i32
  %28 = add nsw i32 %.02559, 1
  %29 = sext i32 %28 to i64
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @n, ptr noundef nonnull align 8 dereferenceable(8) @m)
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %.not49 = icmp eq i64 %31, %29
  %32 = add nuw nsw i32 %27, 1
  br i1 %.not49, label %._crit_edge, label %.thread43

.thread43.loopexit.split.loop.exit:               ; preds = %18
  %33 = trunc nsw i64 %indvars.iv to i32
  br label %.thread43

.thread43:                                        ; preds = %23, %.thread43.loopexit.split.loop.exit, %.preheader, %25, %26
  %.248 = phi i32 [ %28, %26 ], [ %.02559, %25 ], [ %.02559, %.preheader ], [ %.02559, %.thread43.loopexit.split.loop.exit ], [ %.02559, %23 ]
  %.32947 = phi i32 [ %32, %26 ], [ %.02658, %25 ], [ %.02658, %.preheader ], [ %33, %.thread43.loopexit.split.loop.exit ], [ %.02658, %23 ]
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %34 = load i64, ptr @m, align 8, !tbaa !5
  %.not.not = icmp sgt i64 %34, %indvars.iv65
  br i1 %.not.not, label %.preheader, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %26, %.thread43, %1
  %.3 = phi i32 [ 0, %1 ], [ %.248, %.thread43 ], [ %28, %26 ]
  ret i32 %.3
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #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 #1

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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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