; LLVM IR from caryll/otfcc :: lib/libcff (cff-charset)

; 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.cff_Charset = type { i32, i32, %union.anon }
%union.anon = type { %struct.cff_CharsetFormat0 }
%struct.cff_CharsetFormat0 = type { i8, ptr }
%struct.cff_CharsetFormat1 = type { i8, ptr }
%struct.cff_CharsetFormat2 = type { i8, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @cff_close_Charset(ptr noundef byval(%struct.cff_Charset) align 8 %0) #0 {
  %2 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 0
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %41 [
    i32 1, label %4
    i32 2, label %4
    i32 0, label %4
    i32 3, label %5
    i32 4, label %17
    i32 5, label %29
  ]

4:                                                ; preds = %1, %1, %1
  br label %41

5:                                                ; preds = %1
  %6 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %7 = getelementptr inbounds %struct.cff_CharsetFormat0, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %16

10:                                               ; preds = %5
  %11 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %12 = getelementptr inbounds %struct.cff_CharsetFormat0, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  call void @free(ptr noundef %13) #2
  %14 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %15 = getelementptr inbounds %struct.cff_CharsetFormat0, ptr %14, i32 0, i32 1
  store ptr null, ptr %15, align 8, !tbaa !10
  br label %16

16:                                               ; preds = %10, %5
  br label %41

17:                                               ; preds = %1
  %18 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %19 = getelementptr inbounds %struct.cff_CharsetFormat1, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !10
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %28

22:                                               ; preds = %17
  %23 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %24 = getelementptr inbounds %struct.cff_CharsetFormat1, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !10
  call void @free(ptr noundef %25) #2
  %26 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %27 = getelementptr inbounds %struct.cff_CharsetFormat1, ptr %26, i32 0, i32 1
  store ptr null, ptr %27, align 8, !tbaa !10
  br label %28

28:                                               ; preds = %22, %17
  br label %41

29:                                               ; preds = %1
  %30 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %31 = getelementptr inbounds %struct.cff_CharsetFormat2, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !10
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %36 = getelementptr inbounds %struct.cff_CharsetFormat2, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !10
  call void @free(ptr noundef %37) #2
  %38 = getelementptr inbounds %struct.cff_Charset, ptr %0, i32 0, i32 2
  %39 = getelementptr inbounds %struct.cff_CharsetFormat2, ptr %38, i32 0, i32 1
  store ptr null, ptr %39, align 8, !tbaa !10
  br label %40

40:                                               ; preds = %34, %29
  br label %41

41:                                               ; preds = %40, %28, %16, %4, %1
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #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 = { 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 #2 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


; 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.cff_Charset = type { i32, i32, %union.anon }
%union.anon = type { %struct.cff_CharsetFormat0 }
%struct.cff_CharsetFormat0 = type { i8, ptr }

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @cff_close_Charset(ptr nocapture noundef readonly byval(%struct.cff_Charset) align 8 %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %2, label %12 [
    i32 5, label %9
    i32 4, label %6
    i32 3, label %3
  ]

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !10
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %12, label %.sink.split

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %.not3 = icmp eq ptr %8, null
  br i1 %.not3, label %12, label %.sink.split

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  %.not4 = icmp eq ptr %11, null
  br i1 %.not4, label %12, label %.sink.split

.sink.split:                                      ; preds = %9, %6, %3
  %.sink = phi ptr [ %5, %3 ], [ %8, %6 ], [ %11, %9 ]
  tail call void @free(ptr noundef nonnull %.sink) #2
  br label %12

12:                                               ; preds = %.sink.split, %9, %6, %3, %1
  ret void
}

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

attributes #0 = { mustprogress nounwind willreturn 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 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 #2 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SimplifyCFGPass,TailCallElimPass