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

; 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.XWindowChanges = type { i32, i32, i32, i32, i32, 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.Ewmh = type { i64, i64, i64 }

@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @configwin(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3) #0 {
  %5 = alloca %struct.Rectangle, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.XWindowChanges, align 8
  %9 = alloca i32, align 4
  %10 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %10, align 4
  %11 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  store i64 %2, ptr %11, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Window, ptr %12, i32 0, i32 7
  %14 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %15 = load i64, ptr %14, align 4
  %16 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %17 = load i64, ptr %16, align 4
  %18 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %19 = load i64, ptr %18, align 8
  %20 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %21 = load i64, ptr %20, align 8
  %22 = call i32 @eqrect(i64 %15, i64 %17, i64 %19, i64 %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %31

24:                                               ; preds = %4
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Window, ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = icmp eq i32 %25, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i32 1, ptr %9, align 4
  br label %72

31:                                               ; preds = %24, %4
  %32 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 0
  %33 = getelementptr inbounds %struct.Point, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !18
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sub nsw i32 %34, %35
  %37 = getelementptr inbounds %struct.XWindowChanges, ptr %8, i32 0, i32 0
  store i32 %36, ptr %37, align 8, !tbaa !19
  %38 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 0
  %39 = getelementptr inbounds %struct.Point, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !21
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sub nsw i32 %40, %41
  %43 = getelementptr inbounds %struct.XWindowChanges, ptr %8, i32 0, i32 1
  store i32 %42, ptr %43, align 4, !tbaa !22
  %44 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 1
  %45 = getelementptr inbounds %struct.Point, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !23
  %47 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 0
  %48 = getelementptr inbounds %struct.Point, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !18
  %50 = sub nsw i32 %46, %49
  %51 = getelementptr inbounds %struct.XWindowChanges, ptr %8, i32 0, i32 2
  store i32 %50, ptr %51, align 8, !tbaa !24
  %52 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 1
  %53 = getelementptr inbounds %struct.Point, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !25
  %55 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 0
  %56 = getelementptr inbounds %struct.Point, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !21
  %58 = sub nsw i32 %54, %57
  %59 = getelementptr inbounds %struct.XWindowChanges, ptr %8, i32 0, i32 3
  store i32 %58, ptr %59, align 4, !tbaa !26
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = getelementptr inbounds %struct.XWindowChanges, ptr %8, i32 0, i32 4
  store i32 %60, ptr %61, align 8, !tbaa !27
  %62 = load ptr, ptr @display, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Window, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !28
  %66 = call i32 @XConfigureWindow(ptr noundef %62, i64 noundef %65, i32 noundef 31, ptr noundef %8)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Window, ptr %67, i32 0, i32 7
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 4 %5, i64 16, i1 false), !tbaa.struct !29
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Window, ptr %70, i32 0, i32 8
  store i32 %69, ptr %71, align 8, !tbaa !11
  store i32 0, ptr %9, align 4
  br label %72

72:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #4
  %73 = load i32, ptr %9, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

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

declare i32 @eqrect(i64, i64, i64, i64) #2

declare i32 @XConfigureWindow(ptr noundef, i64 noundef, i32 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

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


; 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.XWindowChanges = type { i32, i32, i32, i32, i32, i64, i32 }

@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @configwin(ptr nocapture noundef %0, i64 %1, i64 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.XWindowChanges, align 8
  %.sroa.0.sroa.0.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.0.sroa.5.0.extract.shift = lshr i64 %1, 32
  %.sroa.0.sroa.5.0.extract.trunc = trunc nuw i64 %.sroa.0.sroa.5.0.extract.shift to i32
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %7 = load i64, ptr %6, align 8
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = load i64, ptr %8, align 8
  %10 = tail call i32 @eqrect(i64 %1, i64 %2, i64 %7, i64 %9) #3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %15, label %11

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i32 %13, %3
  br i1 %14, label %29, label %15

15:                                               ; preds = %11, %4
  %16 = sub nsw i32 %.sroa.0.sroa.0.0.extract.trunc, %3
  store i32 %16, ptr %5, align 8, !tbaa !16
  %17 = sub nsw i32 %.sroa.0.sroa.5.0.extract.trunc, %3
  %18 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %17, ptr %18, align 4, !tbaa !18
  %.sroa.7.8.extract.trunc = trunc i64 %2 to i32
  %19 = sub nsw i32 %.sroa.7.8.extract.trunc, %.sroa.0.sroa.0.0.extract.trunc
  %20 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %19, ptr %20, align 8, !tbaa !19
  %.sroa.7.12.extract.shift = lshr i64 %2, 32
  %.sroa.7.12.extract.trunc = trunc nuw i64 %.sroa.7.12.extract.shift to i32
  %21 = sub nsw i32 %.sroa.7.12.extract.trunc, %.sroa.0.sroa.5.0.extract.trunc
  %22 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %21, ptr %22, align 4, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %3, ptr %23, align 8, !tbaa !21
  %24 = load ptr, ptr @display, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !23
  %27 = call i32 @XConfigureWindow(ptr noundef %24, i64 noundef %26, i32 noundef 31, ptr noundef nonnull %5) #3
  store i64 %1, ptr %6, align 8
  store i64 %2, ptr %8, align 8
  %28 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %3, ptr %28, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %11, %15
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #3
  ret void
}

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

declare i32 @eqrect(i64, i64, i64, i64) local_unnamed_addr #2

declare i32 @XConfigureWindow(ptr noundef, i64 noundef, i32 noundef, ptr noundef) 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

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, !7, i64 72}
!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 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !7, i64 32}
!18 = !{!17, !7, i64 4}
!19 = !{!17, !7, i64 8}
!20 = !{!17, !7, i64 12}
!21 = !{!17, !7, i64 16}
!22 = !{!11, !11, i64 0}
!23 = !{!6, !10, i64 8}


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