; LLVM IR from 0intro/wmii :: lib/libstuff/x11/text (freefont)

; 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.Font = type { i32, %union.anon, %struct.Rectangle, i32, i32, i32, ptr }
%union.anon = type { ptr }
%struct.Rectangle = type { %struct.Point, %struct.Point }
%struct.Point = type { i32, i32 }
%struct.Xft = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@display = external global ptr, align 8
@xft = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @freefont(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.Font, ptr %3, i32 0, i32 0
  %5 = load i32, ptr %4, align 8, !tbaa !9
  switch i32 %5, label %26 [
    i32 2, label %6
    i32 3, label %11
    i32 1, label %20
  ]

6:                                                ; preds = %1
  %7 = load ptr, ptr @display, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Font, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  call void @XFreeFontSet(ptr noundef %7, ptr noundef %10)
  br label %27

11:                                               ; preds = %1
  %12 = load ptr, ptr @xft, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Xft, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr @display, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Font, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = call ptr %14(ptr noundef %15, ptr noundef %18)
  br label %27

20:                                               ; preds = %1
  %21 = load ptr, ptr @display, align 8, !tbaa !5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Font, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = call i32 @XFreeFont(ptr noundef %21, ptr noundef %24)
  br label %27

26:                                               ; preds = %1
  br label %27

27:                                               ; preds = %26, %20, %11, %6
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Font, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  call void @free(ptr noundef %30) #3
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %31) #3
  ret void
}

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

declare i32 @XFreeFont(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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 = { "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 "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 }

!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 = !{!"Font", !11, i64 0, !7, i64 8, !12, i64 16, !11, i64 32, !11, i64 36, !11, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"Rectangle", !13, i64 0, !13, i64 8}
!13 = !{!"Point", !11, i64 0, !11, i64 4}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 32}
!16 = !{!"Xft", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!10, !6, i64 48}


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

@display = external local_unnamed_addr global ptr, align 8
@xft = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @freefont(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %2, label %20 [
    i32 2, label %3
    i32 3, label %7
    i32 1, label %15
  ]

3:                                                ; preds = %1
  %4 = load ptr, ptr @display, align 8, !tbaa !13
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  tail call void @XFreeFontSet(ptr noundef %4, ptr noundef %6) #3
  br label %20

7:                                                ; preds = %1
  %8 = load ptr, ptr @xft, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = load ptr, ptr @display, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = tail call ptr %10(ptr noundef %11, ptr noundef %13) #3
  br label %20

15:                                               ; preds = %1
  %16 = load ptr, ptr @display, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = tail call i32 @XFreeFont(ptr noundef %16, ptr noundef %18) #3
  br label %20

20:                                               ; preds = %1, %15, %7, %3
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  tail call void @free(ptr noundef %22) #3
  tail call void @free(ptr noundef nonnull %0) #3
  ret void
}

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

declare i32 @XFreeFont(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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 = { "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 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 #3 = { 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 = !{!"Font", !7, i64 0, !8, i64 8, !10, i64 16, !7, i64 32, !7, i64 36, !7, i64 40, !12, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Rectangle", !11, i64 0, !11, i64 8}
!11 = !{!"Point", !7, i64 0, !7, i64 4}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !12, i64 32}
!16 = !{!"Xft", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!17 = !{!6, !12, i64 48}


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