; LLVM IR from AlgoGenesis/C :: String Algorithms/Lempel-Ziv Compression Algorithm (Program)

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

%struct.DictionaryEntry = type { ptr }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @initDictionary(ptr 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @LZWCompress(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [4096 x %struct.DictionaryEntry], align 16
  %4 = alloca i32, align 4
  %5 = alloca [256 x i8], align 16
  %6 = alloca [256 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32768, ptr %3) #6
  %12 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %3, i64 0, i64 0
  call void @initDictionary(ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 256, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 256, ptr %5) #6
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 256, ptr %6) #6
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #7
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %7, align 4, !tbaa !9
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %67, %1
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  store i8 %27, ptr %9, align 1, !tbaa !11
  %28 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %29 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %30 = load i8, ptr %9, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  %32 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %28, i64 noundef 256, ptr noundef @.str.1, ptr noundef %29, i32 noundef %31) #6
  %33 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %3, i64 0, i64 0
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %36 = call i32 @searchDictionary(ptr noundef %33, i32 noundef %34, ptr noundef %35)
  %37 = icmp ne i32 %36, -1
  br i1 %37, label %38, label %42

38:                                               ; preds = %22
  %39 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %40 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %41 = call ptr @strcpy(ptr noundef %39, ptr noundef %40) #6
  br label %66

42:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %43 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %3, i64 0, i64 0
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %46 = call i32 @searchDictionary(ptr noundef %43, i32 noundef %44, ptr noundef %45)
  store i32 %46, ptr %10, align 4, !tbaa !9
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %47)
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = icmp slt i32 %49, 4096
  br i1 %50, label %51, label %60

51:                                               ; preds = %42
  %52 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 0
  %53 = call noalias ptr @strdup(ptr noundef %52) #6
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %3, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.DictionaryEntry, ptr %56, i32 0, i32 0
  store ptr %53, ptr %57, align 8, !tbaa !12
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %51, %42
  %61 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %62 = call ptr @strcpy(ptr noundef %61, ptr noundef @.str.3) #6
  %63 = load i8, ptr %9, align 1, !tbaa !11
  %64 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  store i8 %63, ptr %64, align 16, !tbaa !11
  %65 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 1
  store i8 0, ptr %65, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %66

66:                                               ; preds = %60, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !14

70:                                               ; preds = %21
  %71 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %72 = call i64 @strlen(ptr noundef %71) #7
  %73 = icmp ugt i64 %72, 0
  br i1 %73, label %74, label %81

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %75 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %3, i64 0, i64 0
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  %78 = call i32 @searchDictionary(ptr noundef %75, i32 noundef %76, ptr noundef %77)
  store i32 %78, ptr %11, align 4, !tbaa !9
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %81

81:                                               ; preds = %74, %70
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 256, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 256, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 32768, ptr %3) #6
  ret void
}

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #5

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 "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 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, 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"

%struct.DictionaryEntry = type { ptr }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @initDictionary(ptr noundef) local_unnamed_addr #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @LZWCompress(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [4096 x %struct.DictionaryEntry], align 16
  %3 = alloca [256 x i8], align 16
  %4 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32768, ptr nonnull %2) #7
  call void @initDictionary(ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %3, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %4, i8 0, i64 256, i1 false)
  %5 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #8
  %6 = trunc i64 %5 to i32
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %8 = icmp sgt i32 %6, 0
  br i1 %8, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %3, i64 1
  %wide.trip.count = and i64 %5, 2147483647
  br label %11

._crit_edge:                                      ; preds = %30
  %char0.pre = load i8, ptr %3, align 16
  %10 = icmp eq i8 %char0.pre, 0
  br i1 %10, label %._crit_edge.thread, label %31

11:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %.018 = phi i32 [ 256, %.lr.ph ], [ %.2, %30 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = sext i8 %13 to i32
  %15 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %4, i64 noundef 256, ptr noundef nonnull @.str.1, ptr noundef nonnull %3, i32 noundef %14) #7
  %16 = call i32 @searchDictionary(ptr noundef nonnull %2, i32 noundef %.018, ptr noundef nonnull %4)
  %.not16 = icmp eq i32 %16, -1
  br i1 %.not16, label %19, label %17

17:                                               ; preds = %11
  %18 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %4) #7
  br label %30

19:                                               ; preds = %11
  %20 = call i32 @searchDictionary(ptr noundef nonnull %2, i32 noundef %.018, ptr noundef nonnull %3)
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %20)
  %22 = icmp slt i32 %.018, 4096
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = call noalias ptr @strdup(ptr noundef nonnull %4) #7
  %25 = sext i32 %.018 to i64
  %26 = getelementptr inbounds [4096 x %struct.DictionaryEntry], ptr %2, i64 0, i64 %25
  store ptr %24, ptr %26, align 8, !tbaa !8
  %27 = add nsw i32 %.018, 1
  br label %28

28:                                               ; preds = %23, %19
  %.1 = phi i32 [ %27, %23 ], [ %.018, %19 ]
  %29 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.3) #7
  store i8 %13, ptr %3, align 16, !tbaa !5
  store i8 0, ptr %9, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %28, %17
  %.2 = phi i32 [ %.018, %17 ], [ %.1, %28 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !11

31:                                               ; preds = %._crit_edge
  %32 = call i32 @searchDictionary(ptr noundef nonnull %2, i32 noundef %.2, ptr noundef nonnull %3)
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %32)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %1, %31, %._crit_edge
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 32768, ptr nonnull %2) #7
  ret void
}

; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; 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 #5

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"", !10, i64 0}
!10 = !{!"any pointer", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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