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

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

@display = external global ptr, align 8
@ZR = external constant %struct.Rectangle, align 4
@scr = external global %struct.Screen, align 8
@ZP = external constant %struct.Point, align 4

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @getwinrect(ptr noundef %0) #0 {
  %2 = alloca %struct.Rectangle, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.XWindowAttributes, align 8
  %5 = alloca %struct.Point, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Point, align 4
  %8 = alloca %struct.Rectangle, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 136, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load ptr, ptr @display, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Window, ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = call i32 @XGetWindowAttributes(ptr noundef %9, i64 noundef %12, ptr noundef %4)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 @ZR, i64 16, i1 false), !tbaa.struct !17
  store i32 1, ptr %6, align 4
  br label %40

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr @ZP, align 4
  %19 = call i64 @translate(ptr noundef %17, ptr noundef getelementptr inbounds (%struct.Screen, ptr @scr, i32 0, i32 1), i64 %18)
  store i64 %19, ptr %7, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %20 = getelementptr inbounds %struct.Rectangle, ptr %8, i32 0, i32 0
  %21 = getelementptr inbounds %struct.Point, ptr %20, i32 0, i32 0
  store i32 0, ptr %21, align 4, !tbaa !20
  %22 = getelementptr inbounds %struct.Point, ptr %20, i32 0, i32 1
  store i32 0, ptr %22, align 4, !tbaa !21
  %23 = getelementptr inbounds %struct.Rectangle, ptr %8, i32 0, i32 1
  %24 = getelementptr inbounds %struct.Point, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.XWindowAttributes, ptr %4, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !22
  store i32 %26, ptr %24, align 4, !tbaa !20
  %27 = getelementptr inbounds %struct.Point, ptr %23, i32 0, i32 1
  %28 = getelementptr inbounds %struct.XWindowAttributes, ptr %4, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !24
  store i32 %29, ptr %27, align 4, !tbaa !21
  %30 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %31 = load i64, ptr %30, align 4
  %32 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %33 = load i64, ptr %32, align 4
  %34 = load i64, ptr %5, align 4
  %35 = call { i64, i64 } @rectaddpt(i64 %31, i64 %33, i64 %34)
  %36 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 0
  %37 = extractvalue { i64, i64 } %35, 0
  store i64 %37, ptr %36, align 4
  %38 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 1
  %39 = extractvalue { i64, i64 } %35, 1
  store i64 %39, ptr %38, align 4
  store i32 1, ptr %6, align 4
  br label %40

40:                                               ; preds = %16, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 136, ptr %4) #4
  %41 = load { i64, i64 }, ptr %2, align 4
  ret { i64, i64 } %41
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i64 @translate(ptr noundef, ptr noundef, i64) #2

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

declare { i64, i64 } @rectaddpt(i64, i64, i64) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!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 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18, i64 12, i64 4, !18}
!18 = !{!11, !11, i64 0}
!19 = !{i64 0, i64 4, !18, i64 4, i64 4, !18}
!20 = !{!14, !11, i64 0}
!21 = !{!14, !11, i64 4}
!22 = !{!23, !11, i64 8}
!23 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !12, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !12, i64 56, !12, i64 64, !11, i64 72, !12, i64 80, !11, i64 88, !11, i64 92, !12, i64 96, !12, i64 104, !12, i64 112, !11, i64 120, !6, i64 128}
!24 = !{!23, !11, i64 12}


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

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

@display = external local_unnamed_addr global ptr, align 8
@ZR = external local_unnamed_addr constant %struct.Rectangle, align 4
@scr = external global %struct.Screen, align 8
@ZP = external local_unnamed_addr constant %struct.Point, align 4

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @getwinrect(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.XWindowAttributes, align 8
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %2) #3
  %3 = load ptr, ptr @display, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = call i32 @XGetWindowAttributes(ptr noundef %3, i64 noundef %5, ptr noundef nonnull %2) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %8

7:                                                ; preds = %1
  %.sroa.04.0.copyload = load i64, ptr @ZR, align 4
  %.sroa.35.0.copyload = load i64, ptr getelementptr inbounds (i8, ptr @ZR, i64 8), align 4
  br label %16

8:                                                ; preds = %1
  %9 = load i64, ptr @ZP, align 4
  %10 = call i64 @translate(ptr noundef nonnull %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @scr, i64 8), i64 %9) #3
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load i64, ptr %11, align 8
  %13 = call { i64, i64 } @rectaddpt(i64 0, i64 %12, i64 %10) #3
  %14 = extractvalue { i64, i64 } %13, 0
  %15 = extractvalue { i64, i64 } %13, 1
  br label %16

16:                                               ; preds = %8, %7
  %.sroa.04.0 = phi i64 [ %14, %8 ], [ %.sroa.04.0.copyload, %7 ]
  %.sroa.35.0 = phi i64 [ %15, %8 ], [ %.sroa.35.0.copyload, %7 ]
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %2) #3
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.sroa.04.0, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.sroa.35.0, 1
  ret { i64, i64 } %.fca.1.insert
}

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

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

declare i64 @translate(ptr noundef, ptr noundef, i64) local_unnamed_addr #2

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

declare { i64, i64 } @rectaddpt(i64, i64, i64) 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 = { mustprogress 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, !12, i64 8}
!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}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass