; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100959L)

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

@slen = external dso_local global i32, align 4
@tlen = external dso_local global i32, align 4
@s = external dso_local global [5001 x i8], align 16
@t = external dso_local global [5001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s, ptr noundef @t)
  %7 = call i64 @strlen(ptr noundef @s) #4
  %8 = trunc i64 %7 to i32
  store i32 %8, ptr @slen, align 4, !tbaa !5
  %9 = call i64 @strlen(ptr noundef @t) #4
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr @tlen, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 -1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %57, %0
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr @tlen, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  br label %60

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr @slen, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %25, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %20
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !5
  br label %41

35:                                               ; preds = %20, %16
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp eq i32 %36, -1
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %60

40:                                               ; preds = %35
  br label %41

41:                                               ; preds = %40, %32
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = icmp ne i32 %46, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %41
  %55 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %55, ptr %2, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %54, %41
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !10

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

62:                                               ; preds = %60
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = load i32, ptr @slen, align 4, !tbaa !5
  %65 = icmp eq i32 %63, %64
  %66 = zext i1 %65 to i64
  %67 = select i1 %65, ptr @.str.2, ptr @.str.1
  %68 = call i32 @puts(ptr noundef %67)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %69

69:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %70 = load i32, ptr %1, align 4
  ret i32 %70
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

declare i32 @puts(ptr noundef) #1

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

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 = { "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 = { nounwind willreturn memory(read) "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@slen = external dso_local local_unnamed_addr global i32, align 4
@tlen = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [5001 x i8], align 16
@t = external dso_local global [5001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s, ptr noundef nonnull @t)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #3
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr @slen, align 4, !tbaa !5
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @t) #3
  %5 = trunc i64 %4 to i32
  store i32 %5, ptr @tlen, align 4, !tbaa !5
  %.not21 = icmp sgt i32 %5, 0
  br i1 %.not21, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = and i64 %4, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %.01423 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %18 ]
  %.01522 = phi i32 [ -1, %.lr.ph.preheader ], [ %spec.select, %18 ]
  %6 = icmp slt i32 %.01423, %3
  br i1 %6, label %7, label %16

7:                                                ; preds = %.lr.ph
  %8 = sext i32 %.01423 to i64
  %9 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = icmp eq i8 %10, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %7
  %15 = add nsw i32 %.01423, 1
  br label %18

16:                                               ; preds = %7, %.lr.ph
  %17 = icmp eq i32 %.01522, -1
  br i1 %17, label %.loopexit, label %._crit_edge

._crit_edge:                                      ; preds = %16
  %.phi.trans.insert = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %indvars.iv
  %.pre = load i8, ptr %.phi.trans.insert, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %._crit_edge, %14
  %19 = phi i8 [ %10, %14 ], [ %.pre, %._crit_edge ]
  %.1 = phi i32 [ %15, %14 ], [ %.01423, %._crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [5001 x i8], ptr @t, i64 0, i64 %indvars.iv.next
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %.not19 = icmp eq i8 %19, %21
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select = select i1 %.not19, i32 %.01522, i32 %22
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !10

.critedge:                                        ; preds = %18, %0
  %.014.lcssa = phi i32 [ 0, %0 ], [ %.1, %18 ]
  %23 = icmp eq i32 %.014.lcssa, %3
  %24 = select i1 %23, ptr @.str.2, ptr @.str.1
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.critedge
  %.str.1.sink = phi ptr [ %24, %.critedge ], [ @.str.1, %16 ]
  %25 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

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 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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"}


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