; LLVM IR from kaynewbie/algorithm :: algorithm/LeetCode/Easy (longest-common-prefix)

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

@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [101 x i8], align 1

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

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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @testLongestCommonPrefix5(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 20, ptr %3, align 4, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = call ptr @llvm.stacksave.p0()
  store ptr %11, ptr %4, align 8
  %12 = alloca ptr, i64 %10, align 16
  store i64 %10, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %23, %1
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %26

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr @.str.10, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %12, i64 %21
  store ptr %19, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !11

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = call ptr %27(ptr noundef %12, i32 noundef %28)
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %30)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %32 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %32)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [101 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @testLongestCommonPrefix5(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca [20 x ptr], align 16
  store ptr @.str.10, ptr %2, align 16, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr @.str.10, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr @.str.10, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr @.str.10, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr @.str.10, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr @.str.10, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 48
  store ptr @.str.10, ptr %8, align 16, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 56
  store ptr @.str.10, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %2, i64 64
  store ptr @.str.10, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 72
  store ptr @.str.10, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %2, i64 80
  store ptr @.str.10, ptr %12, align 16, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %2, i64 88
  store ptr @.str.10, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %2, i64 96
  store ptr @.str.10, ptr %14, align 16, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %2, i64 104
  store ptr @.str.10, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 112
  store ptr @.str.10, ptr %16, align 16, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %2, i64 120
  store ptr @.str.10, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %2, i64 128
  store ptr @.str.10, ptr %18, align 16, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 136
  store ptr @.str.10, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 144
  store ptr @.str.10, ptr %20, align 16, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %2, i64 152
  store ptr @.str.10, ptr %21, align 8, !tbaa !5
  %22 = call ptr %0(ptr noundef nonnull %2, i32 noundef 20) #2
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %22)
  ret void
}

attributes #0 = { 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 #1 = { 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 #2 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass