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

; 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.Point = type { i32, i32 }
%struct.Rectangle = type { %struct.Point, %struct.Point }
%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 }

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.reparentwindow = external hidden unnamed_addr constant [47 x i8], align 1
@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @reparentwindow(ptr noundef %0, ptr noundef %1, i64 %2) #0 {
  %4 = alloca %struct.Point, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.Rectangle, align 4
  %8 = alloca %struct.Rectangle, align 4
  store i64 %2, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Window, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %15

14:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 8, ptr noundef @__PRETTY_FUNCTION__.reparentwindow) #5
  unreachable

15:                                               ; preds = %13
  %16 = load ptr, ptr @display, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Window, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Window, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !18
  %25 = getelementptr inbounds %struct.Point, ptr %4, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !19
  %27 = call i32 @XReparentWindow(ptr noundef %16, i64 noundef %19, i64 noundef %22, i32 noundef %24, i32 noundef %26)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Window, ptr %28, i32 0, i32 7
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #6
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Window, ptr %30, i32 0, i32 7
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Window, ptr %32, i32 0, i32 7
  %34 = getelementptr inbounds %struct.Rectangle, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds { i64, i64 }, ptr %31, i32 0, i32 0
  %36 = load i64, ptr %35, align 8
  %37 = getelementptr inbounds { i64, i64 }, ptr %31, i32 0, i32 1
  %38 = load i64, ptr %37, align 8
  %39 = load i64, ptr %34, align 8
  %40 = call { i64, i64 } @rectsubpt(i64 %36, i64 %38, i64 %39)
  %41 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %42 = extractvalue { i64, i64 } %40, 0
  store i64 %42, ptr %41, align 4
  %43 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %44 = extractvalue { i64, i64 } %40, 1
  store i64 %44, ptr %43, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 4 %7, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #6
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Window, ptr %45, i32 0, i32 7
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #6
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Window, ptr %47, i32 0, i32 7
  %49 = getelementptr inbounds { i64, i64 }, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8
  %51 = getelementptr inbounds { i64, i64 }, ptr %48, i32 0, i32 1
  %52 = load i64, ptr %51, align 8
  %53 = load i64, ptr %4, align 4
  %54 = call { i64, i64 } @rectaddpt(i64 %50, i64 %52, i64 %53)
  %55 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %56 = extractvalue { i64, i64 } %54, 0
  store i64 %56, ptr %55, align 4
  %57 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %58 = extractvalue { i64, i64 } %54, 1
  store i64 %58, ptr %57, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %46, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #6
  ret void
}

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

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

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

declare { i64, i64 } @rectsubpt(i64, i64, i64) #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) #4

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !12, i64 8}
!18 = !{!14, !11, i64 0}
!19 = !{!14, !11, i64 4}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 12, i64 4, !21}
!21 = !{!11, !11, i64 0}


; 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 [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.reparentwindow = external hidden unnamed_addr constant [47 x i8], align 1
@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @reparentwindow(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  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 8, ptr noundef nonnull @__PRETTY_FUNCTION__.reparentwindow) #3
  unreachable

7:                                                ; preds = %3
  %.sroa.3.0.extract.shift = lshr i64 %2, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %.sroa.010.0.extract.trunc = trunc i64 %2 to i32
  %8 = load ptr, ptr @display, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !17
  %13 = tail call i32 @XReparentWindow(ptr noundef %8, i64 noundef %10, i64 noundef %12, i32 noundef %.sroa.010.0.extract.trunc, i32 noundef %.sroa.3.0.extract.trunc) #4
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = load i64, ptr %14, align 8
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load i64, ptr %16, align 8
  %18 = tail call { i64, i64 } @rectsubpt(i64 %15, i64 %17, i64 %15) #4
  %19 = extractvalue { i64, i64 } %18, 0
  %20 = extractvalue { i64, i64 } %18, 1
  store i64 %19, ptr %14, align 8
  store i64 %20, ptr %16, align 8
  %21 = tail call { i64, i64 } @rectaddpt(i64 %19, i64 %20, i64 %2) #4
  %22 = extractvalue { i64, i64 } %21, 0
  %23 = extractvalue { i64, i64 } %21, 1
  store i64 %22, ptr %14, align 8
  store i64 %23, ptr %16, align 8
  ret void
}

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

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

declare { i64, i64 } @rectsubpt(i64, i64, i64) local_unnamed_addr #2

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 = { 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 = { noreturn nounwind }
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, !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 = !{!11, !11, i64 0}
!17 = !{!6, !10, i64 8}


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