; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 186A. Comparing Strings (main)

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

@a = external dso_local global [100005 x i8], align 16
@b = external dso_local global [100005 x i8], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  br label %10

10:                                               ; preds = %95, %0
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b)
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %13, label %96

13:                                               ; preds = %10
  %14 = call i64 @strlen(ptr noundef @a) #5
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %2, align 4, !tbaa !5
  %16 = call i64 @strlen(ptr noundef @b) #5
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp ne i32 %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %13
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %95

23:                                               ; preds = %13
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %81, %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %84

28:                                               ; preds = %24
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %33, %38
  br i1 %39, label %40, label %80

40:                                               ; preds = %28
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %6, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %54

45:                                               ; preds = %40
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9
  store i8 %49, ptr %8, align 1, !tbaa !9
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !9
  store i8 %53, ptr %9, align 1, !tbaa !9
  br label %79

54:                                               ; preds = %40
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = icmp eq i32 %55, 2
  br i1 %56, label %57, label %77

57:                                               ; preds = %54
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = load i8, ptr %9, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %62, %64
  br i1 %65, label %66, label %76

66:                                               ; preds = %57
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %71 = sext i8 %70 to i32
  %72 = load i8, ptr %8, align 1, !tbaa !9
  %73 = sext i8 %72 to i32
  %74 = icmp eq i32 %71, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %66
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %75, %66, %57
  br label %78

77:                                               ; preds = %54
  br label %84

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78, %45
  br label %80

80:                                               ; preds = %79, %28
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !10

84:                                               ; preds = %77, %24
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %92

87:                                               ; preds = %84
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = icmp eq i32 %88, 2
  br i1 %89, label %90, label %92

90:                                               ; preds = %87
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %94

92:                                               ; preds = %87, %84
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %94

94:                                               ; preds = %92, %90
  br label %95

95:                                               ; preds = %94, %21
  br label %10, !llvm.loop !12

96:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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 = { 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 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 #4 = { nounwind }
attributes #5 = { 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"}
!12 = distinct !{!12, !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"

@a = external dso_local global [100005 x i8], align 16
@b = external dso_local global [100005 x i8], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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 @a, ptr noundef nonnull @b)
  %.not50 = icmp eq i32 %1, -1
  br i1 %.not50, label %._crit_edge55, label %.lr.ph54

.lr.ph54:                                         ; preds = %0, %._crit_edge.thread
  %.052 = phi i8 [ %.3, %._crit_edge.thread ], [ undef, %0 ]
  %.01951 = phi i8 [ %.322, %._crit_edge.thread ], [ undef, %0 ]
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @a) #3
  %3 = trunc i64 %2 to i32
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @b) #3
  %5 = trunc i64 %4 to i32
  %.not34 = icmp eq i32 %3, %5
  %6 = icmp sgt i32 %3, 0
  %or.cond65 = and i1 %.not34, %6
  br i1 %or.cond65, label %.lr.ph.preheader, label %._crit_edge.thread

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %15 ]
  %.141 = phi i8 [ %.052, %.lr.ph.preheader ], [ %.2, %15 ]
  %.12040 = phi i8 [ %.01951, %.lr.ph.preheader ], [ %.221, %15 ]
  %.02339 = phi i32 [ 0, %.lr.ph.preheader ], [ %.124, %15 ]
  %.02538 = phi i32 [ 0, %.lr.ph.preheader ], [ %.126, %15 ]
  %7 = getelementptr inbounds [100005 x i8], ptr @a, i64 0, i64 %indvars.iv
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = getelementptr inbounds [100005 x i8], ptr @b, i64 0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not35 = icmp eq i8 %8, %10
  br i1 %.not35, label %15, label %11

11:                                               ; preds = %.lr.ph
  switch i32 %.02538, label %._crit_edge.thread [
    i32 0, label %15
    i32 1, label %12
  ]

12:                                               ; preds = %11
  %13 = icmp eq i8 %8, %.141
  %14 = icmp eq i8 %10, %.12040
  %or.cond36 = select i1 %13, i1 %14, i1 false
  %spec.select = select i1 %or.cond36, i32 1, i32 %.02339
  br label %15

15:                                               ; preds = %11, %12, %.lr.ph
  %.126 = phi i32 [ %.02538, %.lr.ph ], [ 1, %11 ], [ 2, %12 ]
  %.124 = phi i32 [ %.02339, %.lr.ph ], [ %.02339, %11 ], [ %spec.select, %12 ]
  %.221 = phi i8 [ %.12040, %.lr.ph ], [ %8, %11 ], [ %.12040, %12 ]
  %.2 = phi i8 [ %.141, %.lr.ph ], [ %10, %11 ], [ %.141, %12 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %15
  %16 = icmp eq i32 %.124, 1
  %17 = icmp eq i32 %.126, 2
  %or.cond = select i1 %16, i1 %17, i1 false
  %spec.select66 = select i1 %or.cond, ptr @.str.2, ptr @.str.1
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %11, %._crit_edge, %.lr.ph54
  %.str.2.sink = phi ptr [ @.str.1, %.lr.ph54 ], [ %spec.select66, %._crit_edge ], [ @.str.1, %11 ]
  %.322 = phi i8 [ %.01951, %.lr.ph54 ], [ %.221, %._crit_edge ], [ %.12040, %11 ]
  %.3 = phi i8 [ %.052, %.lr.ph54 ], [ %.2, %._crit_edge ], [ %.141, %11 ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %.not = icmp eq i32 %19, -1
  br i1 %.not, label %._crit_edge55, label %.lr.ph54, !llvm.loop !10

._crit_edge55:                                    ; preds = %._crit_edge.thread, %0
  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 @printf(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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