; LLVM IR from freddiev4/dailyprogrammerchallenges :: Easy Challenges/Challenge 0275 Easy - Splurthian Chemistry 101/solutions (solution)

; 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: nounwind uwtable
define dso_local zeroext i8 @validSymbol(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [50 x i8], align 16
  %7 = alloca [3 x i8], align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #4
  %15 = icmp ne i64 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i8 0, ptr %3, align 1
  br label %81

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 50, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 3, ptr %7) #5
  %18 = getelementptr inbounds [50 x i8], ptr %6, i64 0, i64 0
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call ptr @strcpy(ptr noundef %18, ptr noundef %19) #5
  %21 = getelementptr inbounds [3 x i8], ptr %7, i64 0, i64 0
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call ptr @strcpy(ptr noundef %21, ptr noundef %22) #5
  %24 = getelementptr inbounds [50 x i8], ptr %6, i64 0, i64 0
  %25 = load i8, ptr %24, align 16, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = add nsw i32 %26, 32
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %24, align 16, !tbaa !9
  %29 = getelementptr inbounds [3 x i8], ptr %7, i64 0, i64 0
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = add nsw i32 %31, 32
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %29, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  br label %34

34:                                               ; preds = %74, %17
  %35 = load i32, ptr %8, align 4, !tbaa !10
  %36 = icmp slt i32 %35, 2
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %11, align 4
  br label %77

38:                                               ; preds = %34
  store i32 0, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %39 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %39, ptr %12, align 4, !tbaa !10
  br label %40

40:                                               ; preds = %65, %38
  %41 = load i32, ptr %12, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [50 x i8], ptr %6, i64 0, i64 0
  %44 = call i64 @strlen(ptr noundef %43) #4
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  store i32 5, ptr %11, align 4
  br label %68

47:                                               ; preds = %40
  %48 = load i32, ptr %8, align 4, !tbaa !10
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [3 x i8], ptr %7, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = load i32, ptr %12, align 4, !tbaa !10
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [50 x i8], ptr %6, i64 0, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = icmp eq i32 %52, %57
  br i1 %58, label %59, label %64

59:                                               ; preds = %47
  %60 = load i32, ptr %12, align 4, !tbaa !10
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %9, align 4, !tbaa !10
  %62 = load i32, ptr %10, align 4, !tbaa !10
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !10
  store i32 5, ptr %11, align 4
  br label %68

64:                                               ; preds = %47
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %12, align 4, !tbaa !10
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %12, align 4, !tbaa !10
  br label %40, !llvm.loop !12

68:                                               ; preds = %59, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %10, align 4, !tbaa !10
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  store i8 0, ptr %3, align 1
  store i32 1, ptr %11, align 4
  br label %77

73:                                               ; preds = %69
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %8, align 4, !tbaa !10
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !10
  br label %34, !llvm.loop !14

77:                                               ; preds = %72, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %78 = load i32, ptr %11, align 4
  switch i32 %78, label %80 [
    i32 2, label %79
  ]

79:                                               ; preds = %77
  store i8 1, ptr %3, align 1
  store i32 1, ptr %11, align 4
  br label %80

80:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 3, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 50, ptr %6) #5
  br label %81

81:                                               ; preds = %80, %16
  %82 = load i8, ptr %3, align 1
  ret i8 %82
}

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

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

attributes #0 = { 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: nofree nounwind memory(argmem: readwrite) uwtable
define dso_local zeroext range(i8 0, 2) i8 @validSymbol(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [50 x i8], align 16
  %4 = alloca [3 x i8], align 1
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %.not = icmp eq i64 %5, 2
  br i1 %.not, label %.preheader, label %26

.preheader:                                       ; preds = %2
  call void @llvm.lifetime.start.p0(i64 50, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %4) #5
  %6 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %0) #5
  %7 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) %1) #5
  %8 = load i8, ptr %3, align 16, !tbaa !5
  %9 = add i8 %8, 32
  store i8 %9, ptr %3, align 16, !tbaa !5
  %10 = load i8, ptr %4, align 1, !tbaa !5
  %11 = add i8 %10, 32
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #4
  %.not2228.not = icmp eq i64 %12, 0
  br i1 %.not2228.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 0, %.preheader ]
  %13 = getelementptr inbounds [50 x i8], ptr %3, i64 0, i64 %indvars.iv
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = icmp eq i8 %11, %14
  br i1 %15, label %.preheader.1, label %16

16:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %12
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

.preheader.1:                                     ; preds = %.lr.ph
  %17 = shl i64 %indvars.iv, 32
  %sext = add i64 %17, 4294967296
  %18 = ashr exact i64 %sext, 32
  %.not2228.1 = icmp ugt i64 %12, %18
  br i1 %.not2228.1, label %.lr.ph.1, label %.loopexit

.lr.ph.1:                                         ; preds = %.preheader.1
  %19 = getelementptr inbounds i8, ptr %4, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !5
  br label %21

21:                                               ; preds = %25, %.lr.ph.1
  %indvars.iv.1 = phi i64 [ %18, %.lr.ph.1 ], [ %indvars.iv.next.1, %25 ]
  %22 = getelementptr inbounds [50 x i8], ptr %3, i64 0, i64 %indvars.iv.1
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp eq i8 %20, %23
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %21
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %.not22.1 = icmp ugt i64 %12, %indvars.iv.next.1
  br i1 %.not22.1, label %21, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %16, %21, %25, %.preheader, %.preheader.1
  %spec.select = phi i8 [ 0, %.preheader ], [ 0, %.preheader.1 ], [ 1, %21 ], [ 0, %25 ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 50, ptr nonnull %3) #5
  br label %26

26:                                               ; preds = %2, %.loopexit
  %.2 = phi i8 [ %spec.select, %.loopexit ], [ 0, %2 ]
  ret i8 %.2
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

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

attributes #0 = { nofree nounwind memory(argmem: readwrite) 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 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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