; LLVM IR from 0intro/wmii :: lib/libstuff/x11/properties (getprop_textlist)

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

@display = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @getprop_textlist(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.XTextProperty, align 8
  %8 = alloca ptr, align 8
  %9 = 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 32, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr @display, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Window, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i64 @xatom(ptr noundef %15)
  %17 = call i32 @XGetTextProperty(ptr noundef %11, i64 noundef %14, ptr noundef %7, i64 noundef %16)
  %18 = getelementptr inbounds %struct.XTextProperty, ptr %7, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !18
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %21, label %32

21:                                               ; preds = %3
  %22 = load ptr, ptr @display, align 8, !tbaa !5
  %23 = call i32 @Xutf8TextPropertyToTextList(ptr noundef %22, ptr noundef %7, ptr noundef %8, ptr noundef %9)
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %26, ptr %27, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %21
  %29 = getelementptr inbounds %struct.XTextProperty, ptr %7, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !20
  %31 = call i32 @XFree(ptr noundef %30)
  br label %32

32:                                               ; preds = %28, %3
  %33 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #3
  ret i32 %33
}

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

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

declare i64 @xatom(ptr noundef) #2

declare i32 @Xutf8TextPropertyToTextList(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @XFree(ptr noundef) #2

; 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 = { 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 8}
!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 = !{!19, !13, i64 24}
!19 = !{!"", !6, i64 0, !13, i64 8, !10, i64 16, !13, i64 24}
!20 = !{!19, !6, 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"

%struct.XTextProperty = type { ptr, i64, i32, i64 }

@display = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @getprop_textlist(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca %struct.XTextProperty, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr @display, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = tail call i64 @xatom(ptr noundef %1) #3
  %11 = call i32 @XGetTextProperty(ptr noundef %7, i64 noundef %9, ptr noundef nonnull %4, i64 noundef %10) #3
  %12 = getelementptr inbounds i8, ptr %4, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !18
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %23, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr @display, align 8, !tbaa !5
  %16 = call i32 @Xutf8TextPropertyToTextList(ptr noundef %15, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %19, ptr %2, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %14
  %21 = load ptr, ptr %4, align 8, !tbaa !20
  %22 = call i32 @XFree(ptr noundef %21) #3
  %.pre = load i32, ptr %6, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %20, %3
  %24 = phi i32 [ %.pre, %20 ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  ret i32 %24
}

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

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

declare i64 @xatom(ptr noundef) local_unnamed_addr #2

declare i32 @Xutf8TextPropertyToTextList(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @XFree(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, !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 8}
!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 = !{!19, !13, i64 24}
!19 = !{!"", !6, i64 0, !13, i64 8, !10, i64 16, !13, i64 24}
!20 = !{!19, !6, i64 0}


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