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

; 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_FDSelect = type { i32, i32, %union.anon }
%union.anon = type { %struct.cff_FDSelectFormat3 }
%struct.cff_FDSelectFormat3 = type { i8, i16, ptr, i16 }
%struct.cff_FDSelectFormat0 = type { i8, ptr }

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

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

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

15:                                               ; preds = %9, %4
  br label %28

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

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

27:                                               ; preds = %21, %16
  br label %28

28:                                               ; preds = %27, %15, %1, %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_FDSelect = type { i32, i32, %union.anon }
%union.anon = type { %struct.cff_FDSelectFormat3 }
%struct.cff_FDSelectFormat3 = type { i8, i16, ptr, i16 }

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

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

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

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

9:                                                ; preds = %.sink.split, %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