; LLVM IR from lolosssss/leetcode :: c (38_count_and_say)

; 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 @countAndSay(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca [8192 x i8], align 16
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = call noalias ptr @malloc(i64 noundef 8192) #5
  store ptr %11, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8192, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  %12 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 0
  store i8 49, ptr %12, align 16, !tbaa !11
  %13 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 1
  store i8 0, ptr %13, align 1, !tbaa !11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %22

16:                                               ; preds = %1
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  store i8 49, ptr %18, align 1, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  store i8 0, ptr %20, align 1, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %21, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %97

22:                                               ; preds = %1
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %73, %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = icmp ne i32 %26, 0
  br i1 %28, label %29, label %95

29:                                               ; preds = %25
  store i32 0, ptr %7, align 4, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !5
  %30 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 0
  %31 = load i8, ptr %30, align 16, !tbaa !11
  store i8 %31, ptr %6, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %70, %29
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %73

39:                                               ; preds = %32
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = load i8, ptr %6, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %44, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %39
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %70

51:                                               ; preds = %39
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = add nsw i32 %52, 48
  %54 = trunc i32 %53 to i8
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds i8, ptr %55, i64 %58
  store i8 %54, ptr %59, align 1, !tbaa !11
  %60 = load i8, ptr %6, align 1, !tbaa !11
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !5
  %64 = sext i32 %62 to i64
  %65 = getelementptr inbounds i8, ptr %61, i64 %64
  store i8 %60, ptr %65, align 1, !tbaa !11
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  store i8 %69, ptr %6, align 1, !tbaa !11
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %51, %48
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !5
  br label %32, !llvm.loop !12

73:                                               ; preds = %32
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 48
  %76 = trunc i32 %75 to i8
  %77 = load ptr, ptr %4, align 8, !tbaa !9
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !5
  %80 = sext i32 %78 to i64
  %81 = getelementptr inbounds i8, ptr %77, i64 %80
  store i8 %76, ptr %81, align 1, !tbaa !11
  %82 = load i8, ptr %6, align 1, !tbaa !11
  %83 = load ptr, ptr %4, align 8, !tbaa !9
  %84 = load i32, ptr %9, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %9, align 4, !tbaa !5
  %86 = sext i32 %84 to i64
  %87 = getelementptr inbounds i8, ptr %83, i64 %86
  store i8 %82, ptr %87, align 1, !tbaa !11
  %88 = load ptr, ptr %4, align 8, !tbaa !9
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %88, i64 %90
  store i8 0, ptr %91, align 1, !tbaa !11
  %92 = getelementptr inbounds [8192 x i8], ptr %5, i64 0, i64 0
  %93 = load ptr, ptr %4, align 8, !tbaa !9
  %94 = call ptr @strcpy(ptr noundef %92, ptr noundef %93) #4
  br label %25, !llvm.loop !14

95:                                               ; preds = %25
  %96 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %96, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %97

97:                                               ; preds = %95, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8192, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %98 = load ptr, ptr %2, align 8
  ret ptr %98
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #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) #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 = { nounwind allocsize(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 = { 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 }
attributes #5 = { nounwind allocsize(0) }

!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 memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @countAndSay(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca [8192 x i8], align 16
  %3 = tail call noalias dereferenceable_or_null(8192) ptr @malloc(i64 noundef 8192) #4
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %2) #5
  store i8 49, ptr %2, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 0, ptr %4, align 1, !tbaa !5
  %5 = icmp eq i32 %0, 1
  br i1 %5, label %6, label %.lr.ph48.preheader

.lr.ph48.preheader:                               ; preds = %1
  %.03445 = add nsw i32 %0, -1
  br label %.lr.ph48

6:                                                ; preds = %1
  store i8 49, ptr %3, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 0, ptr %7, align 1, !tbaa !5
  br label %.loopexit

.lr.ph48:                                         ; preds = %.lr.ph48.preheader, %._crit_edge
  %.03447 = phi i32 [ %.034, %._crit_edge ], [ %.03445, %.lr.ph48.preheader ]
  %8 = load i8, ptr %2, align 16, !tbaa !5
  %.not3738 = icmp eq i8 %8, 0
  br i1 %.not3738, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph48, %20
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 0, %.lr.ph48 ]
  %9 = phi i8 [ %22, %20 ], [ %8, %.lr.ph48 ]
  %.042 = phi i32 [ %.1, %20 ], [ 0, %.lr.ph48 ]
  %.02940 = phi i32 [ %.130, %20 ], [ 0, %.lr.ph48 ]
  %.03139 = phi i8 [ %9, %20 ], [ %8, %.lr.ph48 ]
  %10 = icmp eq i8 %9, %.03139
  br i1 %10, label %11, label %13

11:                                               ; preds = %.lr.ph
  %12 = add nsw i32 %.02940, 1
  br label %20

13:                                               ; preds = %.lr.ph
  %14 = trunc i32 %.02940 to i8
  %15 = add i8 %14, 48
  %16 = sext i32 %.042 to i64
  %17 = getelementptr inbounds i8, ptr %3, i64 %16
  store i8 %15, ptr %17, align 1, !tbaa !5
  %18 = add nsw i32 %.042, 2
  %19 = getelementptr i8, ptr %17, i64 1
  store i8 %.03139, ptr %19, align 1, !tbaa !5
  br label %20

20:                                               ; preds = %13, %11
  %.130 = phi i32 [ %12, %11 ], [ 1, %13 ]
  %.1 = phi i32 [ %.042, %11 ], [ %18, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds [8192 x i8], ptr %2, i64 0, i64 %indvars.iv.next
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %.not37 = icmp eq i8 %22, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %20, %.lr.ph48
  %.031.lcssa = phi i8 [ 0, %.lr.ph48 ], [ %9, %20 ]
  %.029.lcssa = phi i32 [ 0, %.lr.ph48 ], [ %.130, %20 ]
  %.0.lcssa = phi i32 [ 0, %.lr.ph48 ], [ %.1, %20 ]
  %23 = trunc i32 %.029.lcssa to i8
  %24 = add i8 %23, 48
  %25 = sext i32 %.0.lcssa to i64
  %26 = getelementptr inbounds i8, ptr %3, i64 %25
  store i8 %24, ptr %26, align 1, !tbaa !5
  %27 = getelementptr i8, ptr %26, i64 1
  store i8 %.031.lcssa, ptr %27, align 1, !tbaa !5
  %28 = getelementptr i8, ptr %26, i64 2
  store i8 0, ptr %28, align 1, !tbaa !5
  %29 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %3) #5
  %.034 = add nsw i32 %.03447, -1
  %.not = icmp eq i32 %.034, 0
  br i1 %.not, label %.loopexit, label %.lr.ph48, !llvm.loop !10

.loopexit:                                        ; preds = %._crit_edge, %6
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %2) #5
  ret ptr %3
}

; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #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) #1

attributes #0 = { nofree nounwind memory(readwrite, argmem: 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { 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 allocsize(0) }
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"}
!10 = distinct !{!10, !9}


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