; LLVM IR from 0intro/wmii :: lib/libstuff/event (unmapnotify)

; 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.XUnmapEvent = type { i32, i64, i32, ptr, i64, i64, i32 }
%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.Handlers = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@event_lastconfigure = external global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local void @event_unmapnotify(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.XUnmapEvent, ptr %4, i32 0, i32 2
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %12, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.XUnmapEvent, ptr %9, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !13
  store i64 %11, ptr @event_lastconfigure, align 8, !tbaa !14
  br label %12

12:                                               ; preds = %8, %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XUnmapEvent, ptr %13, i32 0, i32 5
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = call ptr @findwin(i64 noundef %15)
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %61

18:                                               ; preds = %12
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XUnmapEvent, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %26, label %23

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Window, ptr %24, i32 0, i32 19
  store i8 0, ptr %25, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %23, %18
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XUnmapEvent, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %44, label %31

31:                                               ; preds = %26
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XUnmapEvent, ptr %32, i32 0, i32 4
  %34 = load i64, ptr %33, align 8, !tbaa !22
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XUnmapEvent, ptr %35, i32 0, i32 5
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = icmp eq i64 %34, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %31
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Window, ptr %40, i32 0, i32 20
  %42 = load i32, ptr %41, align 4, !tbaa !23
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %41, align 4, !tbaa !23
  br label %44

44:                                               ; preds = %39, %31, %26
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XUnmapEvent, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %60

49:                                               ; preds = %44
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XUnmapEvent, ptr %50, i32 0, i32 4
  %52 = load i64, ptr %51, align 8, !tbaa !22
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.XUnmapEvent, ptr %53, i32 0, i32 5
  %55 = load i64, ptr %54, align 8, !tbaa !15
  %56 = icmp ne i64 %52, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %49
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_event_handle(ptr noundef %58, i64 noundef ptrtoint (ptr getelementptr inbounds (%struct.Handlers, ptr null, i32 0, i32 22) to i64), ptr noundef %59)
  br label %60

60:                                               ; preds = %57, %49, %44
  br label %61

61:                                               ; preds = %60, %12
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.XUnmapEvent, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !22
  %65 = call ptr @findwin(i64 noundef %64)
  store ptr %65, ptr %3, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %70

67:                                               ; preds = %61
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_event_handle(ptr noundef %68, i64 noundef ptrtoint (ptr getelementptr inbounds (%struct.Handlers, ptr null, i32 0, i32 22) to i64), ptr noundef %69)
  br label %70

70:                                               ; preds = %67, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @findwin(i64 noundef) #2

declare void @_event_handle(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 16}
!10 = !{!"", !11, i64 0, !12, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !11, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 40}
!16 = !{!17, !21, i64 176}
!17 = !{!"Window", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !18, i64 56, !11, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !20, i64 128, !12, i64 152, !6, i64 160, !6, i64 168, !21, i64 176, !11, i64 180, !11, i64 184}
!18 = !{!"Rectangle", !19, i64 0, !19, i64 8}
!19 = !{!"Point", !11, i64 0, !11, i64 4}
!20 = !{!"Ewmh", !12, i64 0, !12, i64 8, !12, i64 16}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!10, !12, i64 32}
!23 = !{!17, !11, i64 180}


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

@event_lastconfigure = external local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local void @event_unmapnotify(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %7

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !12
  store i64 %6, ptr @event_lastconfigure, align 8, !tbaa !13
  br label %7

7:                                                ; preds = %4, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %10 = tail call ptr @findwin(i64 noundef %9) #2
  %.not18 = icmp eq ptr %10, null
  br i1 %.not18, label %.thread24, label %11

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 8, !tbaa !5
  %.not19 = icmp eq i32 %12, 0
  br i1 %.not19, label %13, label %23

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %10, i64 176
  store i8 0, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = load i64, ptr %8, align 8, !tbaa !14
  %18 = icmp eq i64 %16, %17
  br i1 %18, label %19, label %.thread24

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %10, i64 180
  %21 = load i32, ptr %20, align 4, !tbaa !22
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %20, align 4, !tbaa !22
  br label %.thread24

23:                                               ; preds = %11
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load i64, ptr %24, align 8, !tbaa !21
  %26 = load i64, ptr %8, align 8, !tbaa !14
  %.not22 = icmp eq i64 %25, %26
  br i1 %.not22, label %.thread24, label %27

27:                                               ; preds = %23
  tail call void @_event_handle(ptr noundef nonnull %10, i64 noundef 176, ptr noundef nonnull %0) #2
  br label %.thread24

.thread24:                                        ; preds = %13, %19, %23, %27, %7
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load i64, ptr %28, align 8, !tbaa !21
  %30 = tail call ptr @findwin(i64 noundef %29) #2
  %.not23 = icmp eq ptr %30, null
  br i1 %.not23, label %32, label %31

31:                                               ; preds = %.thread24
  tail call void @_event_handle(ptr noundef nonnull %30, i64 noundef 176, ptr noundef nonnull %0) #2
  br label %32

32:                                               ; preds = %31, %.thread24
  ret void
}

declare ptr @findwin(i64 noundef) local_unnamed_addr #1

declare void @_event_handle(ptr noundef, i64 noundef, 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 }

!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 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !10, i64 32, !10, i64 40, !7, i64 48}
!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 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 40}
!15 = !{!16, !20, i64 176}
!16 = !{!"Window", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !11, i64 48, !17, i64 56, !7, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !19, i64 128, !10, i64 152, !11, i64 160, !11, i64 168, !20, i64 176, !7, i64 180, !7, i64 184}
!17 = !{!"Rectangle", !18, i64 0, !18, i64 8}
!18 = !{!"Point", !7, i64 0, !7, i64 4}
!19 = !{!"Ewmh", !10, i64 0, !10, i64 8, !10, i64 16}
!20 = !{!"_Bool", !8, i64 0}
!21 = !{!6, !10, i64 32}
!22 = !{!16, !7, i64 180}


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