; LLVM IR from awawa-dev/HyperHDR :: sources/grabber/linux/X11 (smartX11)

; 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.anon = type { ptr, ptr, i32, i32, i32, i32, ptr, i64, i64, i64, i32, ptr, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, i32, i64, i64, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, i32, i32, ptr, i64, i64, i32, i32, ptr, ptr, i32, ptr }
%struct.x11Displays = type { i32, ptr }
%struct.Screen = type { ptr, ptr, i64, i32, i32, i32, i32, i32, ptr, i32, ptr, ptr, i64, i64, i64, i32, i32, i32, i32, i64 }
%struct.x11Display = type { i32, i32, i32, [50 x i8] }

@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local ptr @enumerateX11Displays() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %8 = call ptr @XOpenDisplay(ptr noundef null)
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %90

12:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 34
  %15 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %15, ptr %4, align 4, !tbaa !13
  %16 = load i32, ptr %4, align 4, !tbaa !13
  %17 = icmp sle i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %12
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = call i32 @XCloseDisplay(ptr noundef %19)
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %89

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %22 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !13
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.x11Displays, ptr %24, i32 0, i32 0
  store i32 %23, ptr %25, align 8, !tbaa !14
  %26 = load i32, ptr %4, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 64
  %29 = call noalias ptr @malloc(i64 noundef %28) #6
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.x11Displays, ptr %30, i32 0, i32 1
  store ptr %29, ptr %31, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %82, %21
  %33 = load i32, ptr %6, align 4, !tbaa !13
  %34 = load i32, ptr %4, align 4, !tbaa !13
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %85

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 35
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i32, ptr %6, align 4, !tbaa !13
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.Screen, ptr %40, i64 %42
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !13
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.x11Displays, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = load i32, ptr %6, align 4, !tbaa !13
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.x11Display, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.x11Display, ptr %50, i32 0, i32 0
  store i32 %44, ptr %51, align 4, !tbaa !18
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Screen, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 8, !tbaa !20
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.x11Displays, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = load i32, ptr %6, align 4, !tbaa !13
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.x11Display, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.x11Display, ptr %60, i32 0, i32 1
  store i32 %54, ptr %61, align 4, !tbaa !22
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Screen, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %63, align 4, !tbaa !23
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.x11Displays, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = load i32, ptr %6, align 4, !tbaa !13
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.x11Display, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.x11Display, ptr %70, i32 0, i32 2
  store i32 %64, ptr %71, align 4, !tbaa !24
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.x11Displays, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !16
  %75 = load i32, ptr %6, align 4, !tbaa !13
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %struct.x11Display, ptr %74, i64 %76
  %78 = getelementptr inbounds %struct.x11Display, ptr %77, i32 0, i32 3
  %79 = getelementptr inbounds [50 x i8], ptr %78, i64 0, i64 0
  %80 = load i32, ptr %6, align 4, !tbaa !13
  %81 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %79, i64 noundef 50, ptr noundef @.str, i32 noundef %80) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %82

82:                                               ; preds = %37
  %83 = load i32, ptr %6, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %6, align 4, !tbaa !13
  br label %32, !llvm.loop !25

85:                                               ; preds = %36
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = call i32 @XCloseDisplay(ptr noundef %86)
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %88, ptr %1, align 8
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %89

89:                                               ; preds = %85, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %90

90:                                               ; preds = %89, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %91 = load ptr, ptr %1, align 8
  ret ptr %91
}

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

declare ptr @XOpenDisplay(ptr noundef) #2

declare i32 @XCloseDisplay(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #4

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

attributes #0 = { mustprogress 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 allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !11, i64 228}
!10 = !{!"_ZTS3$_0", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !11, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 116, !6, i64 120, !6, i64 128, !11, i64 136, !12, i64 144, !12, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !11, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !6, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !11, i64 260, !6, i64 264, !6, i64 272, !11, i64 280, !6, i64 288}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS11x11Displays", !11, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = !{!10, !6, i64 232}
!18 = !{!19, !11, i64 0}
!19 = !{!"_ZTS10x11Display", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12}
!20 = !{!21, !11, i64 24}
!21 = !{!"_ZTS6Screen", !6, i64 0, !6, i64 8, !12, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !6, i64 48, !11, i64 56, !6, i64 64, !6, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !12, i64 120}
!22 = !{!19, !11, i64 4}
!23 = !{!21, !11, i64 28}
!24 = !{!19, !11, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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.x11Display = type { i32, i32, i32, [50 x i8] }
%struct.Screen = type { ptr, ptr, i64, i32, i32, i32, i32, i32, ptr, i32, ptr, ptr, i64, i64, i64, i32, i32, i32, i32, i64 }

@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef ptr @enumerateX11Displays() local_unnamed_addr #0 {
  %1 = tail call ptr @XOpenDisplay(ptr noundef null)
  %2 = icmp eq ptr %1, null
  br i1 %2, label %24, label %3

3:                                                ; preds = %0
  %4 = getelementptr inbounds i8, ptr %1, i64 228
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %.sink.split, label %7

7:                                                ; preds = %3
  %8 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 %5, ptr %8, align 8, !tbaa !12
  %9 = zext nneg i32 %5 to i64
  %10 = shl nuw nsw i64 %9, 6
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #4
  %12 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 232
  br label %14

14:                                               ; preds = %7, %14
  %indvars.iv = phi i64 [ 0, %7 ], [ %indvars.iv.next, %14 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !15
  %16 = getelementptr inbounds %struct.x11Display, ptr %11, i64 %indvars.iv
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %17, ptr %16, align 4, !tbaa !16
  %18 = getelementptr inbounds %struct.Screen, ptr %15, i64 %indvars.iv, i32 3
  %19 = getelementptr inbounds %struct.x11Display, ptr %11, i64 %indvars.iv, i32 1
  %20 = load <2 x i32>, ptr %18, align 8, !tbaa !18
  store <2 x i32> %20, ptr %19, align 4, !tbaa !18
  %21 = getelementptr inbounds %struct.x11Display, ptr %11, i64 %indvars.iv, i32 3
  %22 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %21, i64 noundef 50, ptr noundef nonnull @.str, i32 noundef %17) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %.sink.split, label %14, !llvm.loop !19

.sink.split:                                      ; preds = %14, %3
  %.1.ph = phi ptr [ null, %3 ], [ %8, %14 ]
  %23 = tail call i32 @XCloseDisplay(ptr noundef nonnull %1)
  br label %24

24:                                               ; preds = %.sink.split, %0
  %.1 = phi ptr [ null, %0 ], [ %.1.ph, %.sink.split ]
  ret ptr %.1
}

declare ptr @XOpenDisplay(ptr noundef) local_unnamed_addr #1

declare i32 @XCloseDisplay(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { nofree 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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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, !10, i64 228}
!6 = !{!"_ZTS3$_0", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 104, !10, i64 112, !10, i64 116, !7, i64 120, !7, i64 128, !10, i64 136, !11, i64 144, !11, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !10, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !10, i64 224, !10, i64 228, !7, i64 232, !11, i64 240, !11, i64 248, !10, i64 256, !10, i64 260, !7, i64 264, !7, i64 272, !10, i64 280, !7, i64 288}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTS11x11Displays", !10, i64 0, !7, i64 8}
!14 = !{!13, !7, i64 8}
!15 = !{!6, !7, i64 232}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS10x11Display", !10, i64 0, !10, i64 4, !10, i64 8, !8, i64 12}
!18 = !{!10, !10, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass