; LLVM IR from imteekay/algorithms :: competitive-programming/uri (erasing_and_winning)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [100100 x i8], align 16
  %3 = alloca i8, align 1
  %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 i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 100100, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  br label %9

9:                                                ; preds = %67, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5, ptr noundef %6)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = add nsw i32 %13, %14
  %16 = icmp ne i32 %15, 0
  br label %17

17:                                               ; preds = %12, %9
  %18 = phi i1 [ false, %9 ], [ %16, %12 ]
  br i1 %18, label %19, label %74

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

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

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

25:                                               ; preds = %20
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  br label %27

27:                                               ; preds = %45, %25
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, -1
  br i1 %29, label %30, label %43

30:                                               ; preds = %27
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %43

34:                                               ; preds = %30
  %35 = load i8, ptr %3, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100100 x i8], ptr %2, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp sgt i32 %36, %41
  br label %43

43:                                               ; preds = %34, %30, %27
  %44 = phi i1 [ false, %30 ], [ false, %27 ], [ %42, %34 ]
  br i1 %44, label %45, label %50

45:                                               ; preds = %43
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !5
  br label %27, !llvm.loop !10

50:                                               ; preds = %43
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = icmp slt i32 %52, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %50
  %58 = load i8, ptr %3, align 1, !tbaa !9
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100100 x i8], ptr %2, i64 0, i64 %61
  store i8 %58, ptr %62, align 1, !tbaa !9
  br label %63

63:                                               ; preds = %57, %50
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %8, align 4, !tbaa !5
  br label %20, !llvm.loop !12

67:                                               ; preds = %24
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100100 x i8], ptr %2, i64 0, i64 %70
  store i8 0, ptr %71, align 1, !tbaa !9
  %72 = getelementptr inbounds [100100 x i8], ptr %2, i64 0, i64 0
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %72)
  br label %9, !llvm.loop !13

74:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 100100, ptr %2) #3
  ret i32 0
}

; 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

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

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

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


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

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [100100 x i8], align 16
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 100100, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %6 = icmp ne i32 %5, 0
  %7 = load i32, ptr %3, align 4
  %8 = load i32, ptr %4, align 4
  %9 = sub i32 0, %8
  %10 = icmp ne i32 %7, %9
  %11 = select i1 %6, i1 %10, i1 false
  br i1 %11, label %.preheader, label %._crit_edge29

.preheader:                                       ; preds = %0, %._crit_edge
  %12 = phi i32 [ %20, %._crit_edge ], [ %7, %0 ]
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph27, label %._crit_edge

._crit_edge:                                      ; preds = %48, %.preheader
  %.011.lcssa = phi i32 [ -1, %.preheader ], [ %.2, %48 ]
  %14 = add nsw i32 %.011.lcssa, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100100 x i8], ptr %1, i64 0, i64 %15
  store i8 0, ptr %16, align 1, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %1)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %19 = icmp ne i32 %18, 0
  %20 = load i32, ptr %3, align 4
  %21 = load i32, ptr %4, align 4
  %22 = sub i32 0, %21
  %23 = icmp ne i32 %20, %22
  %24 = select i1 %19, i1 %23, i1 false
  br i1 %24, label %.preheader, label %._crit_edge29, !llvm.loop !8

.lr.ph27:                                         ; preds = %.preheader, %48
  %.026 = phi i32 [ %49, %48 ], [ 0, %.preheader ]
  %.01025 = phi i32 [ %.1.lcssa, %48 ], [ 0, %.preheader ]
  %.01124 = phi i32 [ %.2, %48 ], [ -1, %.preheader ]
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %26 = load i32, ptr %4, align 4
  %27 = icmp sgt i32 %.01124, -1
  %28 = icmp slt i32 %.01025, %26
  %or.cond15 = select i1 %27, i1 %28, i1 false
  br i1 %or.cond15, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph27
  %29 = load i8, ptr %2, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %35
  %.117 = phi i32 [ %.01025, %.lr.ph ], [ %37, %35 ]
  %.11216 = phi i32 [ %.01124, %.lr.ph ], [ %36, %35 ]
  %31 = zext nneg i32 %.11216 to i64
  %32 = getelementptr inbounds [100100 x i8], ptr %1, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = icmp sgt i8 %29, %33
  br i1 %34, label %35, label %.critedge

35:                                               ; preds = %30
  %36 = add nsw i32 %.11216, -1
  %37 = add nsw i32 %.117, 1
  %38 = icmp sgt i32 %.11216, 0
  %39 = icmp slt i32 %37, %26
  %or.cond = select i1 %38, i1 %39, i1 false
  br i1 %or.cond, label %30, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %30, %35, %.lr.ph27
  %.112.lcssa = phi i32 [ %.01124, %.lr.ph27 ], [ %36, %35 ], [ %.11216, %30 ]
  %.1.lcssa = phi i32 [ %.01025, %.lr.ph27 ], [ %37, %35 ], [ %.117, %30 ]
  %40 = add nsw i32 %.112.lcssa, 1
  %41 = load i32, ptr %3, align 4, !tbaa !11
  %42 = sub nsw i32 %41, %26
  %43 = icmp slt i32 %40, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %.critedge
  %45 = load i8, ptr %2, align 1, !tbaa !5
  %46 = sext i32 %40 to i64
  %47 = getelementptr inbounds [100100 x i8], ptr %1, i64 0, i64 %46
  store i8 %45, ptr %47, align 1, !tbaa !5
  br label %48

48:                                               ; preds = %.critedge, %44
  %.2 = phi i32 [ %40, %44 ], [ %.112.lcssa, %.critedge ]
  %49 = add nuw nsw i32 %.026, 1
  %50 = icmp slt i32 %49, %41
  br i1 %50, label %.lr.ph27, label %._crit_edge, !llvm.loop !13

._crit_edge29:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 100100, ptr nonnull %1) #3
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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


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