; LLVM IR from 0intro/wmii :: lib/libstuff/x11/windows (sethandler)

; 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.HandlersLink = type { ptr, ptr, ptr }
%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 }

@free_link = external hidden global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare hidden void @updatemap(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @pushhandler(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = load ptr, ptr @free_link, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %28

11:                                               ; preds = %3
  %12 = call ptr @emalloc(i32 noundef 384)
  store ptr %12, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %24, %11
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 16
  br i1 %15, label %16, label %27

16:                                               ; preds = %13
  %17 = load ptr, ptr @free_link, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.HandlersLink, ptr %18, i64 %20
  %22 = getelementptr inbounds %struct.HandlersLink, ptr %21, i32 0, i32 0
  store ptr %17, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %23, ptr @free_link, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %16
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !13

27:                                               ; preds = %13
  br label %28

28:                                               ; preds = %27, %3
  %29 = load ptr, ptr @free_link, align 8, !tbaa !5
  store ptr %29, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HandlersLink, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  store ptr %32, ptr @free_link, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Window, ptr %33, i32 0, i32 13
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.HandlersLink, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.HandlersLink, ptr %39, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !22
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.HandlersLink, ptr %42, i32 0, i32 1
  store ptr %41, ptr %43, align 8, !tbaa !23
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Window, ptr %45, i32 0, i32 13
  store ptr %44, ptr %46, align 8, !tbaa !15
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @updatemap(ptr noundef %47)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare ptr @emalloc(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"HandlersLink", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 112}
!16 = !{!"Window", !10, i64 0, !17, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !17, i64 40, !6, i64 48, !18, i64 56, !10, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !20, i64 128, !17, i64 152, !6, i64 160, !6, i64 168, !21, i64 176, !10, i64 180, !10, i64 184}
!17 = !{!"long", !7, i64 0}
!18 = !{!"Rectangle", !19, i64 0, !19, i64 8}
!19 = !{!"Point", !10, i64 0, !10, i64 4}
!20 = !{!"Ewmh", !17, i64 0, !17, i64 8, !17, i64 16}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!12, !6, i64 16}
!23 = !{!12, !6, i64 8}


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

@free_link = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden void @updatemap(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pushhandler(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @free_link, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit.loopexit, label %.loopexit

.loopexit.loopexit:                               ; preds = %3
  %6 = tail call ptr @emalloc(i32 noundef 384) #2
  %7 = load ptr, ptr @free_link, align 8, !tbaa !5
  store ptr %7, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %6, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 48
  store ptr %6, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 72
  store ptr %6, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %6, i64 96
  store ptr %6, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %6, i64 120
  store ptr %6, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %6, i64 144
  store ptr %6, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %6, i64 168
  store ptr %6, ptr %14, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %6, i64 192
  store ptr %6, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %6, i64 216
  store ptr %6, ptr %16, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %6, i64 240
  store ptr %6, ptr %17, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %6, i64 264
  store ptr %6, ptr %18, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %6, i64 288
  store ptr %6, ptr %19, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %6, i64 312
  store ptr %6, ptr %20, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %6, i64 336
  store ptr %6, ptr %21, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %6, i64 360
  store ptr %6, ptr %22, align 8, !tbaa !9
  store ptr %6, ptr @free_link, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %3
  %23 = phi ptr [ %6, %.loopexit.loopexit ], [ %4, %3 ]
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  store ptr %24, ptr @free_link, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 112
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %23, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %23, i64 16
  store ptr %1, ptr %27, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %2, ptr %28, align 8, !tbaa !20
  store ptr %23, ptr %25, align 8, !tbaa !11
  tail call void @updatemap(ptr noundef %0)
  ret void
}

declare ptr @emalloc(i32 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"HandlersLink", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !6, i64 112}
!12 = !{!"Window", !13, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !6, i64 48, !15, i64 56, !13, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !17, i64 128, !14, i64 152, !6, i64 160, !6, i64 168, !18, i64 176, !13, i64 180, !13, i64 184}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"Rectangle", !16, i64 0, !16, i64 8}
!16 = !{!"Point", !13, i64 0, !13, i64 4}
!17 = !{!"Ewmh", !14, i64 0, !14, i64 8, !14, i64 16}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!10, !6, i64 16}
!20 = !{!10, !6, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass