; LLVM IR from 0intro/wmii :: lib/libstuff/x11/images (freeimage)

; 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.Window = type { i32, i64, ptr, ptr, ptr, i64, ptr, %struct.Rectangle, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.Ewmh, i64, ptr, ptr, i8, i32, i32 }
%struct.Rectangle = type { %struct.Point, %struct.Point }
%struct.Point = type { i32, i32 }
%struct.Ewmh = type { i64, i64, i64 }
%struct.Xft = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@__PRETTY_FUNCTION__.freeimage = external hidden unnamed_addr constant [24 x i8], align 1
@xft = external global ptr, align 8
@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @freeimage(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 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  br label %37

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.Window, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  br label %13

12:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 11, ptr noundef @__PRETTY_FUNCTION__.freeimage) #4
  unreachable

13:                                               ; preds = %11
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Window, ptr %14, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %25

18:                                               ; preds = %13
  %19 = load ptr, ptr @xft, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Xft, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Window, ptr %22, i32 0, i32 6
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  call void %21(ptr noundef %24)
  br label %25

25:                                               ; preds = %18, %13
  %26 = load ptr, ptr @display, align 8, !tbaa !5
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Window, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !20
  %30 = call i32 @XFreePixmap(ptr noundef %26, i64 noundef %29)
  %31 = load ptr, ptr @display, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Window, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = call i32 @XFreeGC(ptr noundef %31, ptr noundef %34)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %36) #5
  br label %37

37:                                               ; preds = %25, %5
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

declare i32 @XFreePixmap(ptr noundef, i64 noundef) #2

declare i32 @XFreeGC(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(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 = { 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 #2 = { "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 }
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, !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 = !{!"Window", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !13, i64 56, !11, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !15, i64 128, !12, i64 152, !6, i64 160, !6, i64 168, !16, i64 176, !11, i64 180, !11, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"Rectangle", !14, i64 0, !14, i64 8}
!14 = !{!"Point", !11, i64 0, !11, i64 4}
!15 = !{!"Ewmh", !12, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!10, !6, i64 48}
!18 = !{!19, !6, i64 8}
!19 = !{!"Xft", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!10, !12, i64 8}
!21 = !{!10, !6, i64 24}


; 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 [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@__PRETTY_FUNCTION__.freeimage = external hidden unnamed_addr constant [24 x i8], align 1
@xft = external local_unnamed_addr global ptr, align 8
@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @freeimage(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %23, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 11, ptr noundef nonnull @__PRETTY_FUNCTION__.freeimage) #4
  unreachable

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

10:                                               ; preds = %7
  %11 = load ptr, ptr @xft, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  tail call void %13(ptr noundef nonnull %9) #5
  br label %14

14:                                               ; preds = %10, %7
  %15 = load ptr, ptr @display, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !20
  %18 = tail call i32 @XFreePixmap(ptr noundef %15, i64 noundef %17) #5
  %19 = load ptr, ptr @display, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !21
  %22 = tail call i32 @XFreeGC(ptr noundef %19, ptr noundef %21) #5
  tail call void @free(ptr noundef nonnull %0) #5
  br label %23

23:                                               ; preds = %1, %14
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @XFreePixmap(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @XFreeGC(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { 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 #2 = { "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 = { 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 #4 = { noreturn nounwind }
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, !7, i64 0}
!6 = !{!"Window", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !11, i64 48, !12, i64 56, !7, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !14, i64 128, !10, i64 152, !11, i64 160, !11, i64 168, !15, i64 176, !7, i64 180, !7, i64 184}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"Rectangle", !13, i64 0, !13, i64 8}
!13 = !{!"Point", !7, i64 0, !7, i64 4}
!14 = !{!"Ewmh", !10, i64 0, !10, i64 8, !10, i64 16}
!15 = !{!"_Bool", !8, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"Xft", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!20 = !{!6, !10, i64 8}
!21 = !{!6, !11, i64 24}


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