; LLVM IR from viveakrt/Competitive-programing :: CodeChef (MAXREM_Maximum_Remaining)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @cmpfunc(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @func() #0 {
  %1 = alloca [100001 x i64], align 16
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 800008, ptr %1) #3
  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 8, ptr %4) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %14, %0
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %10, label %17

10:                                               ; preds = %6
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %11
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %12)
  br label %14

14:                                               ; preds = %10
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %3, align 8, !tbaa !5
  br label %6, !llvm.loop !9

17:                                               ; preds = %6
  %18 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 0
  %19 = load i64, ptr %2, align 8, !tbaa !5
  call void @qsort(ptr noundef %18, i64 noundef %19, i64 noundef 8, ptr noundef @cmpfunc)
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = sub nsw i64 %20, 1
  %22 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  store i64 %23, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = sub nsw i64 %24, 2
  store i64 %25, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %48, %17
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = sub nsw i64 %28, 1
  %30 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = icmp eq i64 %27, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %26
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = icmp sge i64 %34, 0
  br label %36

36:                                               ; preds = %33, %26
  %37 = phi i1 [ false, %26 ], [ %35, %33 ]
  br i1 %37, label %38, label %51

38:                                               ; preds = %36
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = icmp ne i64 %39, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %38
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  store i64 %47, ptr %4, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %44, %38
  %49 = load i64, ptr %3, align 8, !tbaa !5
  %50 = add nsw i64 %49, -1
  store i64 %50, ptr %3, align 8, !tbaa !5
  br label %26, !llvm.loop !11

51:                                               ; preds = %36
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = load i64, ptr %2, align 8, !tbaa !5
  %54 = sub nsw i64 %53, 1
  %55 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = icmp eq i64 %52, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %51
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %58, %51
  %60 = load i64, ptr %4, align 8, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  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 800008, ptr %1) #3
  ret void
}

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

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

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @cmpfunc(ptr noundef, ptr noundef) #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @func() local_unnamed_addr #1 {
  %1 = alloca [100001 x i64], align 16
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 800008, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01116 = phi i64 [ %8, %.lr.ph ], [ 0, %0 ]
  %6 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %.01116
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %8 = add nuw nsw i64 %.01116, 1
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa15 = phi i64 [ %4, %0 ], [ %9, %.lr.ph ]
  call void @qsort(ptr noundef nonnull %1, i64 noundef %.lcssa15, i64 noundef 8, ptr noundef nonnull @cmpfunc) #5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = add nsw i64 %11, -1
  %13 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = icmp sgt i64 %11, 1
  br i1 %15, label %.lr.ph19.preheader, label %._crit_edge20

.lr.ph19.preheader:                               ; preds = %._crit_edge
  %16 = add nsw i64 %11, -2
  br label %.lr.ph19

.lr.ph19:                                         ; preds = %.lr.ph19.preheader, %.lr.ph19
  %.11217 = phi i64 [ %19, %.lr.ph19 ], [ %16, %.lr.ph19.preheader ]
  %17 = getelementptr inbounds [100001 x i64], ptr %1, i64 0, i64 %.11217
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = add nsw i64 %.11217, -1
  %20 = icmp eq i64 %18, %14
  %21 = icmp ne i64 %.11217, 0
  %22 = and i1 %20, %21
  br i1 %22, label %.lr.ph19, label %._crit_edge20.loopexit, !llvm.loop !11

._crit_edge20.loopexit:                           ; preds = %.lr.ph19
  %23 = select i1 %20, i64 0, i64 %18
  br label %._crit_edge20

._crit_edge20:                                    ; preds = %._crit_edge20.loopexit, %._crit_edge
  %.lcssa = phi i64 [ 0, %._crit_edge ], [ %23, %._crit_edge20.loopexit ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 800008, ptr nonnull %1) #5
  ret void
}

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

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

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

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

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

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


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