; LLVM IR from eyangch/competitive-programming :: USACOcontests/silver/2018.12/convention.ll (Z5worksRiiS_RA100000_ii)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5worksRiiS_RA100000_ii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(400000) %3, i32 noundef %4) #0 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = getelementptr inbounds [100000 x i32], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %56, %5
  %20 = load i32, ptr %14, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %15, align 4
  br label %59

25:                                               ; preds = %19
  %26 = load i32, ptr %14, align 4, !tbaa !9
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = sub nsw i32 %26, %27
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp sge i32 %28, %30
  br i1 %31, label %42, label %32

32:                                               ; preds = %25
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100000 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = sub nsw i32 %37, %38
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %42, label %51

42:                                               ; preds = %32, %25
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load i32, ptr %14, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100000 x i32], ptr %43, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %48, ptr %13, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %8, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %42, %32
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = icmp sle i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  store i1 false, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %59

55:                                               ; preds = %51
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %14, align 4, !tbaa !9
  br label %19, !llvm.loop !11

59:                                               ; preds = %54, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %60 = load i32, ptr %15, align 4
  switch i32 %60, label %62 [
    i32 2, label %61
  ]

61:                                               ; preds = %59
  store i1 true, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %62

62:                                               ; preds = %61, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %63 = load i1, ptr %6, align 1
  ret i1 %63
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !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"}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_Z5worksRiiS_RA100000_ii(ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %0, i32 noundef %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull readonly align 4 dereferenceable(400000) %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %0, align 4, !tbaa !5
  %.not2526 = icmp slt i32 %6, 2
  br i1 %.not2526, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %6 to i64
  %.not35 = icmp slt i32 %8, 2
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %7
  %13 = icmp sgt i32 %12, %4
  %or.cond36 = select i1 %.not35, i1 true, i1 %13
  %14 = sext i1 %or.cond36 to i32
  %.12437 = add nsw i32 %14, %1
  %15 = icmp slt i32 %.12437, 1
  br i1 %15, label %.critedge, label %.lr.ph43

.lr.ph43:                                         ; preds = %.lr.ph, %18
  %.12442 = phi i32 [ %.124, %18 ], [ %.12437, %.lr.ph ]
  %or.cond41 = phi i1 [ %or.cond, %18 ], [ %or.cond36, %.lr.ph ]
  %16 = phi i32 [ %22, %18 ], [ %11, %.lr.ph ]
  %17 = phi i32 [ %19, %18 ], [ 1, %.lr.ph ]
  %.0192840 = phi i32 [ %.120, %18 ], [ %7, %.lr.ph ]
  %.0182939 = phi i32 [ %.1, %18 ], [ 0, %.lr.ph ]
  %indvars.iv38 = phi i64 [ %indvars.iv.next, %18 ], [ 1, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv38, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %.critedge.loopexit, label %18, !llvm.loop !9

18:                                               ; preds = %.lr.ph43
  %.120 = select i1 %or.cond41, i32 %16, i32 %.0192840
  %.1 = select i1 %or.cond41, i32 %17, i32 %.0182939
  %19 = trunc nuw nsw i64 %indvars.iv.next to i32
  %20 = sub nsw i32 %19, %.1
  %.not = icmp sge i32 %20, %8
  %21 = getelementptr inbounds [100000 x i32], ptr %3, i64 0, i64 %indvars.iv.next
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sub nsw i32 %22, %.120
  %24 = icmp sgt i32 %23, %4
  %or.cond = select i1 %.not, i1 true, i1 %24
  %25 = sext i1 %or.cond to i32
  %.124 = add nsw i32 %.12442, %25
  %26 = icmp slt i32 %.124, 1
  br i1 %26, label %.critedge.loopexit, label %.lr.ph43, !llvm.loop !9

.critedge.loopexit:                               ; preds = %18, %.lr.ph43
  %.not25.le = icmp uge i64 %indvars.iv.next, %9
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph, %5
  %.not25.lcssa = phi i1 [ true, %5 ], [ false, %.lr.ph ], [ %.not25.le, %.critedge.loopexit ]
  ret i1 %.not25.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = !{!"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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass