; LLVM IR from google/latency-benchmark :: src/x11 (screenscraper)

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

@display = external hidden global ptr, align 8
@send_scroll_down.x_test_extension_queried = external hidden global i8, align 1
@send_scroll_down.x_test_extension_available = external hidden global i8, align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1

declare ptr @XOpenDisplay(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @debug_log(ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @send_scroll_down(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %7 = load ptr, ptr @display, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %15, label %9

9:                                                ; preds = %2
  %10 = call ptr @XOpenDisplay(ptr noundef null)
  store ptr %10, ptr @display, align 8, !tbaa !9
  %11 = load ptr, ptr @display, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i1 false, ptr %3, align 1
  br label %44

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14, %2
  %16 = load ptr, ptr @display, align 8, !tbaa !9
  %17 = load ptr, ptr @display, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.anon, ptr %17, i32 0, i32 35
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.Screen, ptr %19, i64 0
  %21 = getelementptr inbounds %struct.Screen, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = call i32 @XWarpPointer(ptr noundef %16, i64 noundef 0, i64 noundef %22, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef %23, i32 noundef %24)
  %26 = load i8, ptr @send_scroll_down.x_test_extension_queried, align 1, !tbaa !16, !range !18, !noundef !19
  %27 = trunc i8 %26 to i1
  br i1 %27, label %33, label %28

28:                                               ; preds = %15
  store i8 1, ptr @send_scroll_down.x_test_extension_queried, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %29 = load ptr, ptr @display, align 8, !tbaa !9
  %30 = call i32 @XTestQueryExtension(ptr noundef %29, ptr noundef %6, ptr noundef %6, ptr noundef %6, ptr noundef %6)
  %31 = icmp ne i32 %30, 0
  %32 = zext i1 %31 to i8
  store i8 %32, ptr @send_scroll_down.x_test_extension_available, align 1, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %33

33:                                               ; preds = %28, %15
  %34 = load i8, ptr @send_scroll_down.x_test_extension_available, align 1, !tbaa !16, !range !18, !noundef !19
  %35 = trunc i8 %34 to i1
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void (ptr, ...) @debug_log(ptr noundef @.str.12)
  store i1 false, ptr %3, align 1
  br label %44

37:                                               ; preds = %33
  %38 = load ptr, ptr @display, align 8, !tbaa !9
  %39 = call i32 @XTestFakeButtonEvent(ptr noundef %38, i32 noundef 5, i32 noundef 1, i64 noundef 0)
  %40 = load ptr, ptr @display, align 8, !tbaa !9
  %41 = call i32 @XTestFakeButtonEvent(ptr noundef %40, i32 noundef 5, i32 noundef 0, i64 noundef 0)
  %42 = load ptr, ptr @display, align 8, !tbaa !9
  %43 = call i32 @XSync(ptr noundef %42, i32 noundef 0)
  store i1 true, ptr %3, align 1
  br label %44

44:                                               ; preds = %37, %36, %13
  %45 = load i1, ptr %3, align 1
  ret i1 %45
}

declare i32 @XWarpPointer(ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

declare i32 @XTestQueryExtension(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

declare i32 @XTestFakeButtonEvent(ptr noundef, i32 noundef, i32 noundef, i64 noundef) #0

declare i32 @XSync(ptr noundef, i32 noundef) #0

attributes #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 = { 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 #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 = !{!"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, !10, i64 232}
!12 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !10, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !6, i64 64, !10, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !6, i64 112, !6, i64 116, !10, i64 120, !10, i64 128, !6, i64 136, !13, i64 144, !13, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !6, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !6, i64 224, !6, i64 228, !10, i64 232, !13, i64 240, !13, i64 248, !6, i64 256, !6, i64 260, !10, i64 264, !10, i64 272, !6, i64 280, !10, i64 288}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 16}
!15 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !10, i64 48, !6, i64 56, !10, i64 64, !10, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !13, i64 120}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}


; 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"

@display = external hidden local_unnamed_addr global ptr, align 8
@send_scroll_down.x_test_extension_queried = external hidden local_unnamed_addr global i8, align 1
@send_scroll_down.x_test_extension_available = external hidden local_unnamed_addr global i8, align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1

declare ptr @XOpenDisplay(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @debug_log(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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @send_scroll_down(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = load ptr, ptr @display, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call ptr @XOpenDisplay(ptr noundef null) #3
  store ptr %6, ptr @display, align 8, !tbaa !5
  %.not2 = icmp eq ptr %6, null
  br i1 %.not2, label %30, label %7

7:                                                ; preds = %5, %2
  %8 = phi ptr [ %6, %5 ], [ %4, %2 ]
  %9 = getelementptr inbounds i8, ptr %8, i64 232
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = tail call i32 @XWarpPointer(ptr noundef nonnull %8, i64 noundef 0, i64 noundef %12, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef %0, i32 noundef %1) #3
  %14 = load i8, ptr @send_scroll_down.x_test_extension_queried, align 1, !tbaa !15, !range !17, !noundef !18
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %._crit_edge, label %17

._crit_edge:                                      ; preds = %7
  %.pre = load i8, ptr @send_scroll_down.x_test_extension_available, align 1, !tbaa !15, !range !17
  %16 = trunc nuw i8 %.pre to i1
  br i1 %16, label %23, label %22

17:                                               ; preds = %7
  store i8 1, ptr @send_scroll_down.x_test_extension_queried, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %18 = load ptr, ptr @display, align 8, !tbaa !5
  %19 = call i32 @XTestQueryExtension(ptr noundef %18, ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %3) #3
  %20 = icmp ne i32 %19, 0
  %21 = zext i1 %20 to i8
  store i8 %21, ptr @send_scroll_down.x_test_extension_available, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br i1 %20, label %23, label %22

22:                                               ; preds = %._crit_edge, %17
  call void (ptr, ...) @debug_log(ptr noundef nonnull @.str.12)
  br label %30

23:                                               ; preds = %._crit_edge, %17
  %24 = load ptr, ptr @display, align 8, !tbaa !5
  %25 = call i32 @XTestFakeButtonEvent(ptr noundef %24, i32 noundef 5, i32 noundef 1, i64 noundef 0) #3
  %26 = load ptr, ptr @display, align 8, !tbaa !5
  %27 = call i32 @XTestFakeButtonEvent(ptr noundef %26, i32 noundef 5, i32 noundef 0, i64 noundef 0) #3
  %28 = load ptr, ptr @display, align 8, !tbaa !5
  %29 = call i32 @XSync(ptr noundef %28, i32 noundef 0) #3
  br label %30

30:                                               ; preds = %5, %23, %22
  %.0 = phi i1 [ true, %23 ], [ false, %22 ], [ false, %5 ]
  ret i1 %.0
}

declare i32 @XWarpPointer(ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @XTestQueryExtension(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @XTestFakeButtonEvent(ptr noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

declare i32 @XSync(ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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 #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, !6, i64 232}
!10 = !{!"", !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 = !{!14, !12, i64 16}
!14 = !{!"", !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}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}


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