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

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

9:                                                ; preds = %13, %1
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i32 1
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load i8, ptr %14, align 1, !tbaa !11
  %17 = sext i8 %16 to i32
  %18 = sub nsw i32 %17, 97
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [26 x i32], ptr %4, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !9
  br label %9, !llvm.loop !12

23:                                               ; preds = %9
  br label %24

24:                                               ; preds = %40, %23
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %43

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i32 1
  store ptr %30, ptr %3, align 8, !tbaa !5
  %31 = load i8, ptr %29, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = sub nsw i32 %32, 97
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [26 x i32], ptr %4, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %40

38:                                               ; preds = %28
  %39 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %39, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %44

40:                                               ; preds = %28
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !9
  br label %24, !llvm.loop !14

43:                                               ; preds = %24
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %44

44:                                               ; preds = %43, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr %4) #3
  %45 = load i32, ptr %2, align 4
  ret i32 %45
}

; 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(read, inaccessiblemem: none) uwtable
define dso_local i32 @firstUniqChar(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [26 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %2) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) %2, i8 0, i64 104, i1 false)
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not13 = icmp eq i8 %3, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  br i1 %.not13, label %._crit_edge, label %.lr.ph18

.lr.ph:                                           ; preds = %1, %.lr.ph
  %4 = phi i8 [ %11, %.lr.ph ], [ %3, %1 ]
  %.014 = phi ptr [ %5, %.lr.ph ], [ %0, %1 ]
  %5 = getelementptr inbounds i8, ptr %.014, i64 1
  %6 = sext i8 %4 to i64
  %7 = add nsw i64 %6, -97
  %8 = getelementptr inbounds [26 x i32], ptr %2, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !8
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !8
  %11 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !10

.lr.ph18:                                         ; preds = %.preheader, %18
  %12 = phi i8 [ %21, %18 ], [ %3, %.preheader ]
  %.0717 = phi i32 [ %20, %18 ], [ 0, %.preheader ]
  %.0816 = phi ptr [ %19, %18 ], [ %0, %.preheader ]
  %13 = sext i8 %12 to i64
  %14 = add nsw i64 %13, -97
  %15 = getelementptr inbounds [26 x i32], ptr %2, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !8
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %._crit_edge, label %18

18:                                               ; preds = %.lr.ph18
  %19 = getelementptr inbounds i8, ptr %.0816, i64 1
  %20 = add nuw nsw i32 %.0717, 1
  %21 = load i8, ptr %19, align 1, !tbaa !5
  %.not12 = icmp eq i8 %21, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph18, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph18, %18, %1, %.preheader
  %.09 = phi i32 [ -1, %.preheader ], [ -1, %1 ], [ -1, %18 ], [ %.0717, %.lr.ph18 ]
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %2) #3
  ret i32 %.09
}

; 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(read, 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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass