; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Unit Test/Tests/DataStructuresTests/TreesTest/TrieTest (TrieTest)

; 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.ErrorTestStruct = type { i32 }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@ERROR_TEST = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [17 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 ptr @trieInitialization(...) #1

declare void @destroyTrie(ptr noundef) #1

declare void @trieAddWord(ptr noundef, ptr noundef) #1

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @testTriePrintAllWords(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [20 x i8], align 16
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %8 = call ptr (...) @trieInitialization()
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @triePrintAllWords(ptr noundef null, ptr noundef null)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ErrorTestStruct, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %9, ptr noundef @.str, i32 noundef 323, ptr noundef null, i32 noundef -83386157, i32 noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @triePrintAllWords(ptr noundef %13, ptr noundef null)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ErrorTestStruct, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !9
  call void @CuAssertIntEquals_LineMsg(ptr noundef %14, ptr noundef @.str, i32 noundef 326, ptr noundef null, i32 noundef -83384987, i32 noundef %17)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @trieAddWord(ptr noundef %18, ptr noundef @.str.2)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  call void @trieAddWord(ptr noundef %19, ptr noundef @.str.4)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @trieAddWord(ptr noundef %20, ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %21 = call noalias ptr @fopen(ptr noundef @.str.19, ptr noundef @.str.20)
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %1
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.21) #6
  call void @exit(i32 noundef -833816834) #7
  unreachable

27:                                               ; preds = %1
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  call void @triePrintAllWords(ptr noundef %28, ptr noundef %29)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i32 @fseek(ptr noundef %30, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 20, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #6
  br label %32

32:                                               ; preds = %38, %27
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call i32 @fgetc(ptr noundef %33)
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %7, align 1, !tbaa !13
  %36 = sext i8 %35 to i32
  %37 = icmp ne i32 %36, -1
  br i1 %37, label %38, label %44

38:                                               ; preds = %32
  %39 = load i8, ptr %7, align 1, !tbaa !13
  %40 = load i32, ptr %6, align 4, !tbaa !12
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !12
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 %42
  store i8 %39, ptr %43, align 1, !tbaa !13
  br label %32, !llvm.loop !14

44:                                               ; preds = %32
  %45 = load i32, ptr %6, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !13
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 0
  %50 = call i32 @strcmp(ptr noundef @.str.22, ptr noundef %49) #8
  call void @CuAssertIntEquals_LineMsg(ptr noundef %48, ptr noundef @.str, i32 noundef 350, ptr noundef null, i32 noundef 0, i32 noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call i32 @fclose(ptr noundef %51)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroyTrie(ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

declare void @triePrintAllWords(ptr noundef, ptr noundef) #1

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

declare i32 @fgetc(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #5

declare i32 @fclose(ptr noundef) #1

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 = { 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 = { noreturn 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(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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !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"

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@ERROR_TEST = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [17 x i8], align 1

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

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

declare ptr @trieInitialization(...) local_unnamed_addr #1

declare void @destroyTrie(ptr noundef) local_unnamed_addr #1

declare void @trieAddWord(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @CuAssertIntEquals_LineMsg(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @testTriePrintAllWords(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [20 x i8], align 16
  %3 = tail call ptr (...) @trieInitialization() #6
  tail call void @triePrintAllWords(ptr noundef null, ptr noundef null) #6
  %4 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 323, ptr noundef null, i32 noundef -83386157, i32 noundef %5) #6
  tail call void @triePrintAllWords(ptr noundef %3, ptr noundef null) #6
  %6 = load ptr, ptr @ERROR_TEST, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 326, ptr noundef null, i32 noundef -83384987, i32 noundef %7) #6
  tail call void @trieAddWord(ptr noundef %3, ptr noundef nonnull @.str.2) #6
  tail call void @trieAddWord(ptr noundef %3, ptr noundef nonnull @.str.4) #6
  tail call void @trieAddWord(ptr noundef %3, ptr noundef nonnull @.str.3) #6
  %8 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.20)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.21) #7
  tail call void @exit(i32 noundef -833816834) #8
  unreachable

13:                                               ; preds = %1
  tail call void @triePrintAllWords(ptr noundef %3, ptr noundef nonnull %8) #6
  %14 = tail call i32 @fseek(ptr noundef nonnull %8, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #6
  %15 = tail call i32 @fgetc(ptr noundef nonnull %8)
  %sext.mask17 = and i32 %15, 255
  %.not18 = icmp eq i32 %sext.mask17, 255
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %13 ]
  %16 = phi i32 [ %19, %.lr.ph ], [ %15, %13 ]
  %17 = trunc i32 %16 to i8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [20 x i8], ptr %2, i64 0, i64 %indvars.iv
  store i8 %17, ptr %18, align 1, !tbaa !12
  %19 = tail call i32 @fgetc(ptr noundef nonnull %8)
  %sext.mask = and i32 %19, 255
  %.not = icmp eq i32 %sext.mask, 255
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %20 = and i64 %indvars.iv.next, 4294967295
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %13
  %.0.lcssa = phi i64 [ 0, %13 ], [ %20, %._crit_edge.loopexit ]
  %21 = getelementptr inbounds [20 x i8], ptr %2, i64 0, i64 %.0.lcssa
  store i8 0, ptr %21, align 1, !tbaa !12
  %22 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef nonnull dereferenceable(1) %2) #9
  tail call void @CuAssertIntEquals_LineMsg(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 350, ptr noundef null, i32 noundef 0, i32 noundef %22) #6
  %23 = tail call i32 @fclose(ptr noundef nonnull %8)
  tail call void @destroyTrie(ptr noundef %3) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #6
  ret void
}

declare void @triePrintAllWords(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fgetc(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 #4 = { noreturn 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: 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn nounwind }
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 = !{!10, !11, i64 0}
!10 = !{!"ErrorTestStruct", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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