; LLVM IR from LeetCode-in-C/LeetCode-in-C :: src/main/c/g0001_0100/s0017_letter_combinations_of_a_phone_number (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 void @findCombinations(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !9
  %19 = load i32, ptr %12, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  %22 = call i64 @strlen(ptr noundef %21) #4
  %23 = icmp eq i64 %20, %22
  br i1 %23, label %24, label %36

24:                                               ; preds = %7
  %25 = load ptr, ptr %11, align 8, !tbaa !9
  %26 = call noalias ptr @strdup(ptr noundef %25) #5
  %27 = load ptr, ptr %13, align 8, !tbaa !9
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %14, align 8, !tbaa !9
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %28, i64 %31
  store ptr %26, ptr %32, align 8, !tbaa !9
  %33 = load ptr, ptr %14, align 8, !tbaa !9
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 4, !tbaa !5
  br label %96

36:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %37, ptr %15, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %93, %36
  %39 = load i32, ptr %15, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = call i64 @strlen(ptr noundef %41) #4
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %96

45:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = load i32, ptr %15, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = sext i8 %50 to i32
  %52 = sub nsw i32 %51, 48
  store i32 %52, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %89, %45
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = load i32, ptr %17, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = load i32, ptr %18, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %53
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  br label %92

66:                                               ; preds = %53
  %67 = load ptr, ptr %10, align 8, !tbaa !9
  %68 = load i32, ptr %17, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = load i32, ptr %18, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = load ptr, ptr %11, align 8, !tbaa !9
  %77 = load i32, ptr %12, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i8, ptr %76, i64 %78
  store i8 %75, ptr %79, align 1, !tbaa !11
  %80 = load i32, ptr %15, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = load ptr, ptr %11, align 8, !tbaa !9
  %85 = load i32, ptr %12, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = load ptr, ptr %13, align 8, !tbaa !9
  %88 = load ptr, ptr %14, align 8, !tbaa !9
  call void @findCombinations(i32 noundef %81, ptr noundef %82, ptr noundef %83, ptr noundef %84, i32 noundef %86, ptr noundef %87, ptr noundef %88)
  br label %89

89:                                               ; preds = %66
  %90 = load i32, ptr %18, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %18, align 4, !tbaa !5
  br label %53, !llvm.loop !12

92:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %15, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %15, align 4, !tbaa !5
  br label %38, !llvm.loop !14

96:                                               ; preds = %44, %24
  ret void
}

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

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 nounwind uwtable
define dso_local void @findCombinations(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3, i32 noundef %4, ptr nocapture noundef readonly %5, ptr nocapture noundef %6) local_unnamed_addr #0 {
  %8 = sext i32 %4 to i64
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %10 = icmp eq i64 %9, %8
  br i1 %10, label %15, label %.preheader

.preheader:                                       ; preds = %7
  %invariant.gep = getelementptr i8, ptr %2, i64 -384
  %11 = sext i32 %0 to i64
  %12 = icmp ugt i64 %9, %11
  br i1 %12, label %.lr.ph33, label %.loopexit

.lr.ph33:                                         ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %3, i64 %8
  %14 = add nsw i32 %4, 1
  br label %22

15:                                               ; preds = %7
  %16 = tail call noalias ptr @strdup(ptr noundef %3) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  store ptr %16, ptr %20, align 8, !tbaa !5
  %21 = add nsw i32 %18, 1
  store i32 %21, ptr %6, align 4, !tbaa !9
  br label %.loopexit

22:                                               ; preds = %.lr.ph33, %._crit_edge
  %indvars.iv34 = phi i64 [ %11, %.lr.ph33 ], [ %.pre, %._crit_edge ]
  %23 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv34
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = sext i8 %24 to i64
  %gep = getelementptr ptr, ptr %invariant.gep, i64 %25
  %26 = load ptr, ptr %gep, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %.not30 = icmp eq i8 %27, 0
  %.pre = add nuw nsw i64 %indvars.iv34, 1
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %22
  %28 = trunc nsw i64 %.pre to i32
  br label %31

._crit_edge:                                      ; preds = %31, %22
  %29 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %30 = icmp ugt i64 %29, %.pre
  br i1 %30, label %22, label %.loopexit, !llvm.loop !12

31:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %32 = phi i8 [ %27, %.lr.ph ], [ %35, %31 ]
  store i8 %32, ptr %13, align 1, !tbaa !11
  tail call void @findCombinations(i32 noundef %28, ptr noundef %1, ptr noundef nonnull %2, ptr noundef %3, i32 noundef %14, ptr noundef %5, ptr noundef %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load ptr, ptr %gep, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 %indvars.iv.next
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %.not = icmp eq i8 %35, 0
  br i1 %.not, label %._crit_edge, label %31, !llvm.loop !14

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %15
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { nofree 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 = { 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 nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind willreturn memory(read) }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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