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

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

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

19:                                               ; preds = %4
  %20 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 1
  %21 = getelementptr inbounds %struct.Point, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %24 = getelementptr inbounds %struct.Point, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %19
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = or i32 %28, 2
  store i32 %29, ptr %7, align 4, !tbaa !5
  br label %33

30:                                               ; preds = %19, %4
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = or i32 %31, 8
  store i32 %32, ptr %7, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %30, %27
  %34 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 0
  %35 = getelementptr inbounds %struct.Point, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !13
  %37 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 0
  %38 = getelementptr inbounds %struct.Point, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = icmp ne i32 %36, %39
  br i1 %40, label %41, label %52

41:                                               ; preds = %33
  %42 = getelementptr inbounds %struct.Rectangle, ptr %5, i32 0, i32 1
  %43 = getelementptr inbounds %struct.Point, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = getelementptr inbounds %struct.Rectangle, ptr %6, i32 0, i32 1
  %46 = getelementptr inbounds %struct.Point, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = icmp eq i32 %44, %47
  br i1 %48, label %49, label %52

49:                                               ; preds = %41
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = or i32 %50, 4
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %55

52:                                               ; preds = %41, %33
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = or i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %52, %49
  %56 = load i32, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %56
}

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

; 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 = { 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, !6, i64 0}
!10 = !{!"Rectangle", !11, i64 0, !11, i64 8}
!11 = !{!"Point", !6, i64 0, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 12}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local range(i32 2, 16) i32 @get_sticky(i64 %0, i64 %1, i64 %2, i64 %3) local_unnamed_addr #0 {
  %.sroa.05.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.0.0.extract.trunc = trunc i64 %2 to i32
  %.not = icmp ne i32 %.sroa.05.0.extract.trunc, %.sroa.0.0.extract.trunc
  %.sroa.3.8.extract.trunc = trunc i64 %3 to i32
  %.sroa.37.8.extract.trunc = trunc i64 %1 to i32
  %5 = icmp eq i32 %.sroa.37.8.extract.trunc, %.sroa.3.8.extract.trunc
  %or.cond = select i1 %.not, i1 %5, i1 false
  %.0 = select i1 %or.cond, i32 2, i32 8
  %.not9.unshifted = xor i64 %2, %0
  %.not9 = icmp ugt i64 %.not9.unshifted, 4294967295
  %.unshifted = xor i64 %3, %1
  %6 = icmp ult i64 %.unshifted, 4294967296
  %or.cond10 = select i1 %.not9, i1 %6, i1 false
  %.1.v = select i1 %or.cond10, i32 4, i32 1
  %.1 = or disjoint i32 %.0, %.1.v
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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" }

!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)"}


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