; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/common (shared_dictionary)

; 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.BrotliSharedDictionaryStruct = type { i32, [15 x i64], [15 x ptr], i32, [64 x i8], i8, [64 x ptr], [64 x ptr], i8, ptr, i8, ptr, ptr, ptr, ptr, ptr }

; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @BrotliSharedDictionaryCreateInstance(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %17, label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %12
  %16 = call noalias ptr @malloc(i64 noundef 1408) #6
  store ptr %16, ptr %8, align 8, !tbaa !5
  br label %28

17:                                               ; preds = %12, %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call ptr %24(ptr noundef %25, i64 noundef 1408)
  store ptr %26, ptr %8, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %23, %20, %17
  br label %28

28:                                               ; preds = %27, %15
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %72

32:                                               ; preds = %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %33, i8 0, i64 1408, i1 false)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %34, i32 0, i32 3
  store i32 0, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %36, i32 0, i32 5
  store i8 1, ptr %37, align 4, !tbaa !12
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %38, i32 0, i32 8
  store i8 0, ptr %39, align 8, !tbaa !13
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %40, i32 0, i32 10
  store i8 0, ptr %41, align 8, !tbaa !14
  %42 = call ptr @BrotliGetDictionary()
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %43, i32 0, i32 6
  %45 = getelementptr inbounds [64 x ptr], ptr %44, i64 0, i64 0
  store ptr %42, ptr %45, align 8, !tbaa !5
  %46 = call ptr @BrotliGetTransforms()
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %47, i32 0, i32 7
  %49 = getelementptr inbounds [64 x ptr], ptr %48, i64 0, i64 0
  store ptr %46, ptr %49, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %54

52:                                               ; preds = %32
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  br label %55

54:                                               ; preds = %32
  br label %55

55:                                               ; preds = %54, %52
  %56 = phi ptr [ %53, %52 ], [ @BrotliDefaultAllocFunc, %54 ]
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %57, i32 0, i32 13
  store ptr %56, ptr %58, align 8, !tbaa !15
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %63

61:                                               ; preds = %55
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  br label %64

63:                                               ; preds = %55
  br label %64

64:                                               ; preds = %63, %61
  %65 = phi ptr [ %62, %61 ], [ @BrotliDefaultFreeFunc, %63 ]
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %66, i32 0, i32 14
  store ptr %65, ptr %67, align 8, !tbaa !16
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %69, i32 0, i32 15
  store ptr %68, ptr %70, align 8, !tbaa !17
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %71, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %72

72:                                               ; preds = %64, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %73 = load ptr, ptr %4, align 8
  ret ptr %73
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare ptr @BrotliGetDictionary() #4

declare ptr @BrotliGetTransforms() #4

declare ptr @BrotliDefaultAllocFunc(ptr noundef, i64 noundef) #4

declare void @BrotliDefaultFreeFunc(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 248}
!10 = !{!"BrotliSharedDictionaryStruct", !11, i64 0, !7, i64 8, !7, i64 128, !11, i64 248, !7, i64 252, !7, i64 316, !7, i64 320, !7, i64 832, !7, i64 1344, !6, i64 1352, !7, i64 1360, !6, i64 1368, !6, i64 1376, !6, i64 1384, !6, i64 1392, !6, i64 1400}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 316}
!13 = !{!10, !7, i64 1344}
!14 = !{!10, !7, i64 1360}
!15 = !{!10, !6, i64 1384}
!16 = !{!10, !6, i64 1392}
!17 = !{!10, !6, i64 1400}


; 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
define dso_local ptr @BrotliSharedDictionaryCreateInstance(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %8, label %6

6:                                                ; preds = %3
  %7 = tail call noalias dereferenceable_or_null(1408) ptr @malloc(i64 noundef 1408) #4
  br label %11

8:                                                ; preds = %3
  %or.cond3 = and i1 %4, %5
  br i1 %or.cond3, label %9, label %.thread

9:                                                ; preds = %8
  %10 = tail call ptr %0(ptr noundef %2, i64 noundef 1408) #5
  br label %11

11:                                               ; preds = %9, %6
  %.0 = phi ptr [ %10, %9 ], [ %7, %6 ]
  %12 = icmp eq ptr %.0, null
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %.0, i64 316
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1408) %.0, i8 0, i64 1408, i1 false)
  store i8 1, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.0, i64 1360
  store i8 0, ptr %15, align 8, !tbaa !11
  %16 = tail call ptr @BrotliGetDictionary() #5
  %17 = getelementptr inbounds i8, ptr %.0, i64 320
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = tail call ptr @BrotliGetTransforms() #5
  %19 = getelementptr inbounds i8, ptr %.0, i64 832
  store ptr %18, ptr %19, align 8, !tbaa !12
  %20 = select i1 %4, ptr %0, ptr @BrotliDefaultAllocFunc
  %21 = getelementptr inbounds i8, ptr %.0, i64 1384
  store ptr %20, ptr %21, align 8, !tbaa !13
  %22 = select i1 %5, ptr %1, ptr @BrotliDefaultFreeFunc
  %23 = getelementptr inbounds i8, ptr %.0, i64 1392
  store ptr %22, ptr %23, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %.0, i64 1400
  store ptr %2, ptr %24, align 8, !tbaa !15
  br label %.thread

.thread:                                          ; preds = %8, %11, %13
  %.027 = phi ptr [ %.0, %13 ], [ null, %11 ], [ null, %8 ]
  ret ptr %.027
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare ptr @BrotliGetDictionary() local_unnamed_addr #3

declare ptr @BrotliGetTransforms() local_unnamed_addr #3

declare ptr @BrotliDefaultAllocFunc(ptr noundef, i64 noundef) #3

declare void @BrotliDefaultFreeFunc(ptr noundef, ptr noundef) #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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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, !8, i64 316}
!6 = !{!"BrotliSharedDictionaryStruct", !7, i64 0, !8, i64 8, !8, i64 128, !7, i64 248, !8, i64 252, !8, i64 316, !8, i64 320, !8, i64 832, !8, i64 1344, !10, i64 1352, !8, i64 1360, !10, i64 1368, !10, i64 1376, !10, i64 1384, !10, i64 1392, !10, i64 1400}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !8, i64 1360}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 1384}
!14 = !{!6, !10, i64 1392}
!15 = !{!6, !10, i64 1400}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass