; LLVM IR from LeetCode-in-C/LeetCode-in-C :: src/main/c/g0301_0400/s0394_decode_string (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
declare dso_local ptr @repeatString(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local ptr @decodeHelper(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %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 8, ptr %5) #6
  %12 = call noalias ptr @malloc(i64 noundef 10000) #7
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  store i8 0, ptr %14, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !10
  br label %15

15:                                               ; preds = %103, %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !10
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %16, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %104

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #6
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %25, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !9
  store i8 %30, ptr %7, align 1, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %31, align 4, !tbaa !10
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 4, !tbaa !10
  %34 = call ptr @__ctype_b_loc() #8
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load i8, ptr %7, align 1, !tbaa !9
  %37 = sext i8 %36 to i32
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i16, ptr %35, i64 %38
  %40 = load i16, ptr %39, align 2, !tbaa !12
  %41 = zext i16 %40 to i32
  %42 = and i32 %41, 1024
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %58

44:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call i64 @strlen(ptr noundef %45) #9
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr %8, align 4, !tbaa !10
  %48 = load i8, ptr %7, align 1, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !10
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  store i8 %48, ptr %52, align 1, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !10
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %100

58:                                               ; preds = %24
  %59 = call ptr @__ctype_b_loc() #8
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = load i8, ptr %7, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i16, ptr %60, i64 %63
  %65 = load i16, ptr %64, align 2, !tbaa !12
  %66 = zext i16 %65 to i32
  %67 = and i32 %66, 2048
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %76

69:                                               ; preds = %58
  %70 = load i32, ptr %6, align 4, !tbaa !10
  %71 = mul nsw i32 %70, 10
  %72 = load i8, ptr %7, align 1, !tbaa !9
  %73 = sext i8 %72 to i32
  %74 = sub nsw i32 %73, 48
  %75 = add nsw i32 %71, %74
  store i32 %75, ptr %6, align 4, !tbaa !10
  br label %99

76:                                               ; preds = %58
  %77 = load i8, ptr %7, align 1, !tbaa !9
  %78 = sext i8 %77 to i32
  %79 = icmp eq i32 %78, 91
  br i1 %79, label %80, label %92

80:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = call ptr @decodeHelper(ptr noundef %81, ptr noundef %82)
  store ptr %83, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !10
  %86 = call ptr @repeatString(ptr noundef %84, i32 noundef %85)
  store ptr %86, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = call ptr @strcat(ptr noundef %87, ptr noundef %88) #6
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %90) #6
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %91) #6
  store i32 0, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %98

92:                                               ; preds = %76
  %93 = load i8, ptr %7, align 1, !tbaa !9
  %94 = sext i8 %93 to i32
  %95 = icmp eq i32 %94, 93
  br i1 %95, label %96, label %97

96:                                               ; preds = %92
  store i32 3, ptr %11, align 4
  br label %101

97:                                               ; preds = %92
  br label %98

98:                                               ; preds = %97, %80
  br label %99

99:                                               ; preds = %98, %69
  br label %100

100:                                              ; preds = %99, %44
  store i32 0, ptr %11, align 4
  br label %101

101:                                              ; preds = %100, %96
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #6
  %102 = load i32, ptr %11, align 4
  switch i32 %102, label %106 [
    i32 0, label %103
    i32 3, label %104
  ]

103:                                              ; preds = %101
  br label %15, !llvm.loop !14

104:                                              ; preds = %101, %15
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret ptr %105

106:                                              ; preds = %101
  unreachable
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #5

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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 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 #3 = { 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 #4 = { 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 #5 = { nounwind willreturn memory(none) "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @repeatString(ptr noundef, i32 noundef) local_unnamed_addr #0

; 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 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 @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @decodeHelper(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(10000) ptr @malloc(i64 noundef 10000) #6
  store i8 0, ptr %3, align 1, !tbaa !5
  %4 = load i32, ptr %1, align 4, !tbaa !8
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %.not35 = icmp eq i8 %7, 0
  br i1 %.not35, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %8 = tail call ptr @__ctype_b_loc() #7
  br label %9

9:                                                ; preds = %.lr.ph, %37
  %10 = phi i8 [ %7, %.lr.ph ], [ %41, %37 ]
  %11 = phi i32 [ %4, %.lr.ph ], [ %38, %37 ]
  %.02736 = phi i32 [ 0, %.lr.ph ], [ %.2, %37 ]
  %12 = sext i8 %10 to i32
  %13 = add nsw i32 %11, 1
  store i32 %13, ptr %1, align 4, !tbaa !8
  %14 = load ptr, ptr %8, align 8, !tbaa !10
  %15 = sext i8 %10 to i64
  %16 = getelementptr inbounds i16, ptr %14, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = zext i16 %17 to i32
  %19 = and i32 %18, 1024
  %.not29 = icmp eq i32 %19, 0
  br i1 %.not29, label %26, label %20

20:                                               ; preds = %9
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #8
  %sext = shl i64 %21, 32
  %22 = ashr exact i64 %sext, 32
  %23 = getelementptr inbounds i8, ptr %3, i64 %22
  store i8 %10, ptr %23, align 1, !tbaa !5
  %sext31 = add i64 %sext, 4294967296
  %24 = ashr exact i64 %sext31, 32
  %25 = getelementptr inbounds i8, ptr %3, i64 %24
  store i8 0, ptr %25, align 1, !tbaa !5
  br label %37

26:                                               ; preds = %9
  %27 = and i32 %18, 2048
  %.not30 = icmp eq i32 %27, 0
  br i1 %.not30, label %32, label %28

28:                                               ; preds = %26
  %29 = mul nsw i32 %.02736, 10
  %30 = add i32 %29, -48
  %31 = add i32 %30, %12
  br label %37

32:                                               ; preds = %26
  switch i8 %10, label %37 [
    i8 91, label %33
    i8 93, label %.thread
  ]

33:                                               ; preds = %32
  %34 = tail call ptr @decodeHelper(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %35 = tail call ptr @repeatString(ptr noundef %34, i32 noundef %.02736)
  %36 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %35) #9
  tail call void @free(ptr noundef %34) #9
  tail call void @free(ptr noundef %35) #9
  %.pre = load i32, ptr %1, align 4, !tbaa !8
  br label %37

37:                                               ; preds = %32, %20, %33, %28
  %38 = phi i32 [ %13, %20 ], [ %13, %28 ], [ %.pre, %33 ], [ %13, %32 ]
  %.2 = phi i32 [ %.02736, %20 ], [ %31, %28 ], [ 0, %33 ], [ %.02736, %32 ]
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %.not = icmp eq i8 %41, 0
  br i1 %.not, label %.thread, label %9

.thread:                                          ; preds = %37, %32, %2
  ret ptr %3
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

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 = { 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 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #5 = { mustprogress nounwind willreturn allockind("free") 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 #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !6, i64 0}


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