; LLVM IR from yettabaa/cub3D :: mlx-linux (mlx_destroy_image)

; 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.s_img = type { ptr, i64, ptr, i32, i32, i32, i32, i32, i32, ptr, %struct.XShmSegmentInfo }
%struct.XShmSegmentInfo = type { i64, i32, ptr, i32 }
%struct.s_xvar = type { ptr, i64, i32, i32, ptr, i64, i32, ptr, ptr, ptr, i32, i32, i32, [6 x i32], i64, i64, i32 }
%struct._XImage = type { i32, i32, i32, i32, ptr, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, ptr, %struct.funcs }
%struct.funcs = type { ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @mlx_destroy_image(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.s_img, ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 3
  br i1 %9, label %15, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s_img, ptr %11, i32 0, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %27

15:                                               ; preds = %10, %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.s_xvar, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_img, ptr %19, i32 0, i32 10
  %21 = call i32 @XShmDetach(ptr noundef %18, ptr noundef %20)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.s_img, ptr %22, i32 0, i32 10
  %24 = getelementptr inbounds %struct.XShmSegmentInfo, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = call i32 @shmdt(ptr noundef %25) #3
  br label %27

27:                                               ; preds = %15, %10
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.s_img, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = getelementptr inbounds %struct._XImage, ptr %30, i32 0, i32 16
  %32 = getelementptr inbounds %struct.funcs, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.s_img, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = call i32 %33(ptr noundef %36)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_xvar, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s_img, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !21
  %44 = call i32 @XFreePixmap(ptr noundef %40, i64 noundef %43)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s_img, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %57

49:                                               ; preds = %27
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_xvar, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s_img, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  %56 = call i32 @XFreeGC(ptr noundef %52, ptr noundef %55)
  br label %57

57:                                               ; preds = %49, %27
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %58) #3
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s_xvar, ptr %59, i32 0, i32 12
  %61 = load i32, ptr %60, align 8, !tbaa !23
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %68

63:                                               ; preds = %57
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.s_xvar, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = call i32 @XFlush(ptr noundef %66)
  br label %68

68:                                               ; preds = %63, %57
  %69 = load i32, ptr %3, align 4
  ret i32 %69
}

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

; Function Attrs: nounwind
declare i32 @shmdt(ptr noundef) #2

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

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

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

declare i32 @XFlush(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 = { "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, !12, i64 40}
!10 = !{!"s_img", !6, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !6, i64 48, !13, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !11, i64 0, !12, i64 8, !6, i64 16, !12, i64 24}
!14 = !{!15, !6, i64 0}
!15 = !{!"s_xvar", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !11, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !7, i64 84, !11, i64 112, !11, i64 120, !12, i64 128}
!16 = !{!10, !6, i64 72}
!17 = !{!10, !6, i64 0}
!18 = !{!19, !6, i64 96}
!19 = !{!"_XImage", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !6, i64 80, !20, i64 88}
!20 = !{!"funcs", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!21 = !{!10, !11, i64 8}
!22 = !{!10, !6, i64 16}
!23 = !{!15, !12, i64 80}


; 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 i32 @mlx_destroy_image(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 40
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = and i32 %4, -2
  %switch = icmp eq i32 %5, 2
  br i1 %switch, label %6, label %13

6:                                                ; preds = %2
  %7 = load ptr, ptr %0, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 56
  %9 = tail call i32 @XShmDetach(ptr noundef %7, ptr noundef nonnull %8) #4
  %10 = getelementptr inbounds i8, ptr %1, i64 72
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = tail call i32 @shmdt(ptr noundef %11) #4
  br label %13

13:                                               ; preds = %2, %6
  %14 = load ptr, ptr %1, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %14, i64 96
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = tail call i32 %16(ptr noundef %14) #4
  %18 = load ptr, ptr %0, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !20
  %21 = tail call i32 @XFreePixmap(ptr noundef %18, i64 noundef %20) #4
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %27, label %24

24:                                               ; preds = %13
  %25 = load ptr, ptr %0, align 8, !tbaa !13
  %26 = tail call i32 @XFreeGC(ptr noundef %25, ptr noundef nonnull %23) #4
  br label %27

27:                                               ; preds = %24, %13
  tail call void @free(ptr noundef nonnull %1) #4
  %28 = getelementptr inbounds i8, ptr %0, i64 80
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %.not16 = icmp eq i32 %29, 0
  br i1 %.not16, label %33, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr %0, align 8, !tbaa !13
  %32 = tail call i32 @XFlush(ptr noundef %31) #4
  br label %33

33:                                               ; preds = %30, %27
  ret i32 undef
}

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

; Function Attrs: nounwind
declare i32 @shmdt(ptr noundef) local_unnamed_addr #2

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

declare i32 @XFreeGC(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 #3

declare i32 @XFlush(ptr noundef) local_unnamed_addr #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 = { "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 = { 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 = { 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, !11, i64 40}
!6 = !{!"s_img", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !7, i64 48, !12, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !10, i64 0, !11, i64 8, !7, i64 16, !11, i64 24}
!13 = !{!14, !7, i64 0}
!14 = !{!"s_xvar", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !8, i64 84, !10, i64 112, !10, i64 120, !11, i64 128}
!15 = !{!6, !7, i64 72}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !7, i64 96}
!18 = !{!"_XImage", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !7, i64 80, !19, i64 88}
!19 = !{!"funcs", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!20 = !{!6, !10, i64 8}
!21 = !{!6, !7, i64 16}
!22 = !{!14, !11, i64 80}


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