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

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

@display = external global ptr, align 8
@xinerama_screens.rects = external hidden global ptr, align 8
@scr = external global %struct.Screen, 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: 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 ptr @xinerama_screens(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = call zeroext i1 @xinerama_active()
  br i1 %8, label %11, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !9
  store ptr getelementptr inbounds (%struct.Screen, ptr @scr, i32 0, i32 7), ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %102

11:                                               ; preds = %1
  %12 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  call void @free(ptr noundef %12) #4
  %13 = load ptr, ptr @display, align 8, !tbaa !5
  %14 = call ptr @XineramaQueryScreens(ptr noundef %13, ptr noundef %6)
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 16
  %18 = trunc i64 %17 to i32
  %19 = call ptr @emalloc(i32 noundef %18)
  store ptr %19, ptr @xinerama_screens.rects, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %93, %11
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %96

24:                                               ; preds = %20
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %28, i32 0, i32 1
  %30 = load i16, ptr %29, align 4, !tbaa !11
  %31 = sext i16 %30 to i32
  %32 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.Rectangle, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.Rectangle, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.Point, ptr %36, i32 0, i32 0
  store i32 %31, ptr %37, align 4, !tbaa !14
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %41, i32 0, i32 2
  %43 = load i16, ptr %42, align 2, !tbaa !17
  %44 = sext i16 %43 to i32
  %45 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.Rectangle, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.Rectangle, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.Point, ptr %49, i32 0, i32 1
  store i32 %44, ptr %50, align 4, !tbaa !18
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %54, i32 0, i32 1
  %56 = load i16, ptr %55, align 4, !tbaa !11
  %57 = sext i16 %56 to i32
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %61, i32 0, i32 3
  %63 = load i16, ptr %62, align 4, !tbaa !19
  %64 = sext i16 %63 to i32
  %65 = add nsw i32 %57, %64
  %66 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.Rectangle, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.Rectangle, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds %struct.Point, ptr %70, i32 0, i32 0
  store i32 %65, ptr %71, align 4, !tbaa !20
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %72, i64 %74
  %76 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %75, i32 0, i32 2
  %77 = load i16, ptr %76, align 2, !tbaa !17
  %78 = sext i16 %77 to i32
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %79, i64 %81
  %83 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %82, i32 0, i32 4
  %84 = load i16, ptr %83, align 2, !tbaa !21
  %85 = sext i16 %84 to i32
  %86 = add nsw i32 %78, %85
  %87 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.Rectangle, ptr %87, i64 %89
  %91 = getelementptr inbounds %struct.Rectangle, ptr %90, i32 0, i32 1
  %92 = getelementptr inbounds %struct.Point, ptr %91, i32 0, i32 1
  store i32 %86, ptr %92, align 4, !tbaa !22
  br label %93

93:                                               ; preds = %24
  %94 = load i32, ptr %5, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !23

96:                                               ; preds = %20
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = call i32 @XFree(ptr noundef %97)
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 %99, ptr %100, align 4, !tbaa !9
  %101 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !5
  store ptr %101, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %102

102:                                              ; preds = %96, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %103 = load ptr, ptr %2, align 8
  ret ptr %103
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @xinerama_active() #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare ptr @XineramaQueryScreens(ptr noundef, ptr noundef) #3

declare ptr @emalloc(i32 noundef) #3

declare i32 @XFree(ptr noundef) #3

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 = { 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 #3 = { "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 #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, !13, i64 4}
!12 = !{!"", !10, i64 0, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"Rectangle", !16, i64 0, !16, i64 8}
!16 = !{!"Point", !10, i64 0, !10, i64 4}
!17 = !{!12, !13, i64 6}
!18 = !{!15, !10, i64 4}
!19 = !{!12, !13, i64 8}
!20 = !{!15, !10, i64 8}
!21 = !{!12, !13, i64 10}
!22 = !{!15, !10, i64 12}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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

@display = external local_unnamed_addr global ptr, align 8
@xinerama_screens.rects = external hidden local_unnamed_addr global ptr, align 8
@scr = external global %struct.Screen, align 8

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

; Function Attrs: mustprogress 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 ptr @xinerama_screens(ptr nocapture noundef writeonly %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %3 = tail call zeroext i1 @xinerama_active()
  br i1 %3, label %5, label %4

4:                                                ; preds = %1
  store i32 1, ptr %0, align 4, !tbaa !5
  br label %39

5:                                                ; preds = %1
  %6 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !9
  tail call void @free(ptr noundef %6) #4
  %7 = load ptr, ptr @display, align 8, !tbaa !9
  %8 = call ptr @XineramaQueryScreens(ptr noundef %7, ptr noundef nonnull %2) #4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = shl i32 %9, 4
  %11 = call ptr @emalloc(i32 noundef %10) #4
  store ptr %11, ptr @xinerama_screens.rects, align 8, !tbaa !9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %14 = getelementptr inbounds %struct.XineramaScreenInfo, ptr %8, i64 %indvars.iv
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load i16, ptr %15, align 4, !tbaa !11
  %17 = sext i16 %16 to i32
  %18 = getelementptr inbounds %struct.Rectangle, ptr %11, i64 %indvars.iv
  store i32 %17, ptr %18, align 4, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %14, i64 6
  %20 = load i16, ptr %19, align 2, !tbaa !17
  %21 = sext i16 %20 to i32
  %22 = getelementptr inbounds %struct.Rectangle, ptr %11, i64 %indvars.iv, i32 0, i32 1
  store i32 %21, ptr %22, align 4, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %14, i64 8
  %24 = load i16, ptr %23, align 4, !tbaa !19
  %25 = sext i16 %24 to i32
  %26 = add nsw i32 %25, %17
  %27 = getelementptr inbounds %struct.Rectangle, ptr %11, i64 %indvars.iv, i32 1
  store i32 %26, ptr %27, align 4, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %14, i64 10
  %29 = load i16, ptr %28, align 2, !tbaa !21
  %30 = sext i16 %29 to i32
  %31 = add nsw i32 %30, %21
  %32 = getelementptr inbounds %struct.Rectangle, ptr %11, i64 %indvars.iv, i32 1, i32 1
  store i32 %31, ptr %32, align 4, !tbaa !22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph, %5
  %36 = call i32 @XFree(ptr noundef %8) #4
  %37 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %37, ptr %0, align 4, !tbaa !5
  %38 = load ptr, ptr @xinerama_screens.rects, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %._crit_edge, %4
  %.021 = phi ptr [ %38, %._crit_edge ], [ getelementptr inbounds (i8, ptr @scr, i64 240), %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret ptr %.021
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @xinerama_active() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

declare ptr @XineramaQueryScreens(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @emalloc(i32 noundef) local_unnamed_addr #3

declare i32 @XFree(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"", !6, i64 0, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"Rectangle", !16, i64 0, !16, i64 8}
!16 = !{!"Point", !6, i64 0, !6, i64 4}
!17 = !{!12, !13, i64 6}
!18 = !{!15, !6, i64 4}
!19 = !{!12, !13, i64 8}
!20 = !{!15, !6, i64 8}
!21 = !{!12, !13, i64 10}
!22 = !{!15, !6, i64 12}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass