; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/313 Division 1/Problem B (B)

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

@s1 = external dso_local global [200200 x i8], align 16
@s2 = external dso_local global [200200 x i8], align 16
@.str = external hidden unnamed_addr constant [6 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 uwtable
declare dso_local noundef zeroext i1 @_Z4goodiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; 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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s1, ptr noundef @s2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %6 = call i64 @strlen(ptr noundef @s1) #6
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = srem i32 %8, 2
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %39

11:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %32, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %4, align 4
  br label %35

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200200 x i8], ptr @s1, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200200 x i8], ptr @s2, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %22, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %17
  %30 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %35

31:                                               ; preds = %17
  br label %32

32:                                               ; preds = %31
  %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 %12, !llvm.loop !10

35:                                               ; preds = %29, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  %36 = load i32, ptr %4, align 4
  switch i32 %36, label %48 [
    i32 2, label %37
  ]

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

39:                                               ; preds = %0
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = call noundef zeroext i1 @_Z4goodiiii(i32 noundef 0, i32 noundef %40, i32 noundef 0, i32 noundef %41)
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = call i32 @puts(ptr noundef @.str.2)
  br label %47

45:                                               ; preds = %39
  %46 = call i32 @puts(ptr noundef @.str.1)
  br label %47

47:                                               ; preds = %45, %43
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %48

48:                                               ; preds = %47, %37, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %49 = load i32, ptr %1, align 4
  ret i32 %49
}

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

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

declare i32 @puts(ptr noundef) #3

attributes #0 = { mustprogress 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 = { 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 #3 = { "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 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 #5 = { nounwind }
attributes #6 = { 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"}


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

@s1 = external dso_local global [200200 x i8], align 16
@s2 = external dso_local global [200200 x i8], align 16
@.str = external hidden unnamed_addr constant [6 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 uwtable
declare dso_local noundef zeroext i1 @_Z4goodiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s1, ptr noundef nonnull @s2)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s1) #4
  %3 = trunc i64 %2 to i32
  %4 = and i32 %3, -2147483647
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %.lr.ph.preheader, label %11

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

6:                                                ; preds = %.lr.ph
  %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 %.critedge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds [200200 x i8], ptr @s1, i64 0, i64 %indvars.iv
  %8 = load i8, ptr %7, align 1, !tbaa !7
  %9 = getelementptr inbounds [200200 x i8], ptr @s2, i64 0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !7
  %.not = icmp eq i8 %8, %10
  br i1 %.not, label %6, label %.critedge

11:                                               ; preds = %0
  %12 = tail call noundef zeroext i1 @_Z4goodiiii(i32 noundef 0, i32 noundef %3, i32 noundef 0, i32 noundef %3)
  %.str.2..str.1 = select i1 %12, ptr @.str.2, ptr @.str.1
  br label %.critedge

.critedge:                                        ; preds = %6, %.lr.ph, %11
  %.str.1.sink = phi ptr [ %.str.2..str.1, %11 ], [ @.str.1, %.lr.ph ], [ @.str.2, %6 ]
  %13 = 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 #2

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

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

attributes #0 = { mustprogress 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 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 #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 = { 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 #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass