; LLVM IR from jovanlanik/wip :: src (wip_input)

; 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.wip_key_t = type { i8, i32 }

@wip_globalKey = external global [138 x ptr], align 16

; 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 zeroext i1 @wip_writeMotion(i64 %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca %struct.wip_key_t, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 4
  %6 = getelementptr inbounds %struct.wip_key_t, ptr %3, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 255
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i1 true, ptr %2, align 1
  br label %60

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %11 = getelementptr inbounds %struct.wip_key_t, ptr %3, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [138 x ptr], ptr @wip_globalKey, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  store ptr %15, ptr %4, align 8, !tbaa !10
  %16 = load ptr, ptr %4, align 8, !tbaa !10
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %10
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %59

19:                                               ; preds = %10
  %20 = load ptr, ptr %4, align 8, !tbaa !10
  %21 = load i8, ptr %20, align 4
  %22 = lshr i8 %21, 1
  %23 = and i8 %22, 3
  %24 = zext i8 %23 to i32
  switch i32 %24, label %58 [
    i32 2, label %25
    i32 0, label %36
    i32 1, label %47
  ]

25:                                               ; preds = %19
  %26 = load i8, ptr %3, align 4
  %27 = and i8 %26, 3
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 2
  br i1 %29, label %30, label %35

30:                                               ; preds = %25
  %31 = load ptr, ptr %4, align 8, !tbaa !10
  %32 = load i8, ptr %31, align 4
  %33 = and i8 %32, -2
  %34 = or i8 %33, 0
  store i8 %34, ptr %31, align 4
  br label %35

35:                                               ; preds = %30, %25
  br label %36

36:                                               ; preds = %35, %19
  %37 = load i8, ptr %3, align 4
  %38 = and i8 %37, 3
  %39 = zext i8 %38 to i32
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %46

41:                                               ; preds = %36
  %42 = load ptr, ptr %4, align 8, !tbaa !10
  %43 = load i8, ptr %42, align 4
  %44 = and i8 %43, -2
  %45 = or i8 %44, 1
  store i8 %45, ptr %42, align 4
  br label %46

46:                                               ; preds = %41, %36
  br label %58

47:                                               ; preds = %19
  %48 = load i8, ptr %3, align 4
  %49 = and i8 %48, 3
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 2
  br i1 %51, label %52, label %57

52:                                               ; preds = %47
  %53 = load ptr, ptr %4, align 8, !tbaa !10
  %54 = load i8, ptr %53, align 4
  %55 = and i8 %54, -2
  %56 = or i8 %55, 1
  store i8 %56, ptr %53, align 4
  br label %57

57:                                               ; preds = %52, %47
  br label %58

58:                                               ; preds = %57, %46, %19
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %59

59:                                               ; preds = %58, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %60

60:                                               ; preds = %59, %9
  %61 = load i1, ptr %2, align 1
  ret i1 %61
}

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 }

!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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, 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"

@wip_globalKey = external local_unnamed_addr global [138 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @wip_writeMotion(i64 %0) local_unnamed_addr #0 {
  %.sroa.0.0.extract.trunc = trunc i64 %0 to i8
  %.sroa.47.0.extract.shift = lshr i64 %0, 32
  %2 = icmp eq i64 %.sroa.47.0.extract.shift, 255
  br i1 %2, label %23, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds [138 x ptr], ptr @wip_globalKey, i64 0, i64 %.sroa.47.0.extract.shift
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not.not = icmp eq ptr %5, null
  br i1 %.not.not, label %23, label %6

6:                                                ; preds = %3
  %7 = load i8, ptr %5, align 4
  %8 = lshr i8 %7, 1
  %9 = and i8 %8, 3
  switch i8 %9, label %default.unreachable11 [
    i8 2, label %10
    i8 0, label %._crit_edge
    i8 1, label %18
    i8 3, label %23
  ]

._crit_edge:                                      ; preds = %6
  %.pre = and i8 %.sroa.0.0.extract.trunc, 3
  br label %14

10:                                               ; preds = %6
  %11 = and i8 %.sroa.0.0.extract.trunc, 3
  %12 = icmp eq i8 %11, 2
  br i1 %12, label %.thread, label %14

.thread:                                          ; preds = %10
  %13 = and i8 %7, -2
  br label %.sink.split

14:                                               ; preds = %._crit_edge, %10
  %.pre-phi = phi i8 [ %.pre, %._crit_edge ], [ %11, %10 ]
  %15 = icmp eq i8 %.pre-phi, 1
  br i1 %15, label %16, label %23

16:                                               ; preds = %14
  %17 = or i8 %7, 1
  br label %.sink.split

18:                                               ; preds = %6
  %19 = and i8 %.sroa.0.0.extract.trunc, 3
  %20 = icmp eq i8 %19, 2
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = or i8 %7, 1
  br label %.sink.split

default.unreachable11:                            ; preds = %6
  unreachable

.sink.split:                                      ; preds = %16, %21, %.thread
  %.sink = phi i8 [ %13, %.thread ], [ %22, %21 ], [ %17, %16 ]
  store i8 %.sink, ptr %5, align 4
  br label %23

23:                                               ; preds = %.sink.split, %3, %18, %14, %6, %1
  %.1 = phi i1 [ true, %1 ], [ true, %6 ], [ true, %14 ], [ true, %18 ], [ false, %3 ], [ true, %.sink.split ]
  ret i1 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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