; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (2325)

; 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 ptr @decodeMessage(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [26 x i32], align 16
  %6 = alloca [26 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 104, ptr %5) #3
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 104, i1 false)
  call void @llvm.lifetime.start.p0(i64 104, ptr %6) #3
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 104, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -65, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %40, %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %41

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i32 1
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load i8, ptr %17, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = sub nsw i32 %20, 97
  store i32 %21, ptr %9, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %40

25:                                               ; preds = %16
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [26 x i32], ptr %5, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %40

31:                                               ; preds = %25
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [26 x i32], ptr %6, i64 0, i64 %35
  store i32 %32, ptr %36, align 4, !tbaa !9
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [26 x i32], ptr %5, i64 0, i64 %38
  store i32 1, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %31, %25, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %12, !llvm.loop !12

41:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %42, ptr %10, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %62, %41
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %65

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  store i32 %50, ptr %11, align 4, !tbaa !9
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 32
  br i1 %52, label %53, label %62

53:                                               ; preds = %47
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 97
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [26 x i32], ptr %6, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = add nsw i32 %58, 97
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %60, ptr %61, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %53, %47
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %43, !llvm.loop !14

65:                                               ; preds = %43
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr %5) #3
  ret ptr %66
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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 norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @decodeMessage(ptr nocapture noundef readonly %0, ptr noundef returned %1) local_unnamed_addr #0 {
  %3 = alloca [26 x i32], align 16
  %4 = alloca [26 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) %3, i8 0, i64 104, i1 false)
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) %4, i8 0, i64 104, i1 false)
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %.not24 = icmp eq i8 %5, 0
  br i1 %.not24, label %.preheader.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %2, %18
  %6 = phi i8 [ %19, %18 ], [ %5, %2 ]
  %.026 = phi ptr [ %7, %18 ], [ %0, %2 ]
  %.01625 = phi i32 [ %.1, %18 ], [ 0, %2 ]
  %7 = getelementptr inbounds i8, ptr %.026, i64 1
  %8 = sext i8 %6 to i32
  %9 = add nsw i32 %8, -97
  %.not23 = icmp eq i32 %9, -65
  br i1 %.not23, label %18, label %10

10:                                               ; preds = %.lr.ph
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [26 x i32], ptr %3, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !8
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = add nsw i32 %.01625, 1
  %17 = getelementptr inbounds [26 x i32], ptr %4, i64 0, i64 %11
  store i32 %.01625, ptr %17, align 4, !tbaa !8
  store i32 1, ptr %12, align 4, !tbaa !8
  br label %18

18:                                               ; preds = %15, %10, %.lr.ph
  %.1 = phi i32 [ %16, %15 ], [ %.01625, %10 ], [ %.01625, %.lr.ph ]
  %19 = load i8, ptr %7, align 1, !tbaa !5
  %.not = icmp eq i8 %19, 0
  br i1 %.not, label %.preheader.preheader, label %.lr.ph, !llvm.loop !10

.preheader.preheader:                             ; preds = %18, %2
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %28
  %.015 = phi ptr [ %29, %28 ], [ %1, %.preheader.preheader ]
  %20 = load i8, ptr %.015, align 1, !tbaa !5
  switch i8 %20, label %21 [
    i8 0, label %30
    i8 32, label %28
  ]

21:                                               ; preds = %.preheader
  %22 = sext i8 %20 to i64
  %23 = add nsw i64 %22, -97
  %24 = getelementptr inbounds [26 x i32], ptr %4, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !8
  %26 = trunc i32 %25 to i8
  %27 = add i8 %26, 97
  store i8 %27, ptr %.015, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %.preheader, %21
  %29 = getelementptr inbounds i8, ptr %.015, i64 1
  br label %.preheader, !llvm.loop !12

30:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %3) #3
  ret ptr %1
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass