; LLVM IR from DanEngelbrecht/longtail :: lib/bikeshed (longtail_bikeshed)

; 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.Bikeshed_Shed_private = type { %struct.AtomicIndex, %struct.AtomicIndex, %struct.AtomicIndex, %struct.AtomicIndex, %struct.AtomicIndex, %struct.AtomicIndex, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.AtomicIndex = type { i32 }
%struct.Bikeshed_Task_private = type { i32, i32, i32, ptr, ptr }

; 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
declare hidden void @Bikeshed_PushRange_private(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @Bikeshed_ExecuteOne(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %17, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !10
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds %struct.AtomicIndex, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.AtomicIndex, ptr %22, i32 0, i32 0
  store ptr %23, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %27

27:                                               ; preds = %59, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load volatile i32, ptr %28, align 4, !tbaa !15
  store i32 %29, ptr %9, align 4, !tbaa !15
  %30 = load i32, ptr %9, align 4, !tbaa !15
  %31 = and i32 %30, 8388607
  store i32 %31, ptr %8, align 4, !tbaa !15
  %32 = load i32, ptr %8, align 4, !tbaa !15
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %56

35:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !15
  %38 = sub i32 %37, 1
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %36, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !15
  store i32 %41, ptr %11, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %42 = load i32, ptr %9, align 4, !tbaa !15
  %43 = and i32 %42, -8388608
  %44 = load i32, ptr %11, align 4, !tbaa !15
  %45 = or i32 %43, %44
  store i32 %45, ptr %12, align 4, !tbaa !15
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !15
  %48 = load i32, ptr %12, align 4, !tbaa !15
  %49 = cmpxchg ptr %46, i32 %47, i32 %48 seq_cst seq_cst, align 4
  %50 = extractvalue { i32, i1 } %49, 0
  %51 = load i32, ptr %9, align 4, !tbaa !15
  %52 = icmp eq i32 %50, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %35
  store i32 2, ptr %10, align 4
  br label %55

54:                                               ; preds = %35
  call void @llvm.x86.sse2.pause()
  store i32 0, ptr %10, align 4
  br label %55

55:                                               ; preds = %54, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %56

56:                                               ; preds = %55, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %57 = load i32, ptr %10, align 4
  switch i32 %57, label %122 [
    i32 0, label %58
    i32 2, label %60
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58
  br i1 true, label %27, label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %61, i32 0, i32 10
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load i32, ptr %8, align 4, !tbaa !15
  %65 = sub i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %63, i64 %66
  store ptr %67, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !17
  store i32 %70, ptr %14, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !15
  %76 = load i8, ptr %5, align 1, !tbaa !9
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %77, i32 0, i32 4
  %79 = load ptr, ptr %78, align 8, !tbaa !20
  %80 = call i32 %73(ptr noundef %74, i32 noundef %75, i8 noundef zeroext %76, ptr noundef %79)
  store i32 %80, ptr %15, align 4, !tbaa !15
  %81 = load i32, ptr %15, align 4, !tbaa !15
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %120

83:                                               ; preds = %60
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 8
  %87 = lshr i32 %86, 8
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %100

89:                                               ; preds = %83
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %92, align 8
  %94 = lshr i32 %93, 8
  call void @Bikeshed_ResolveTask_private(ptr noundef %90, i32 noundef %94)
  %95 = load ptr, ptr %13, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %95, i32 0, i32 2
  %97 = load i32, ptr %96, align 8
  %98 = and i32 %97, 255
  %99 = or i32 %98, 0
  store i32 %99, ptr %96, align 8
  br label %100

100:                                              ; preds = %89, %83
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %101, i32 0, i32 4
  %103 = getelementptr inbounds %struct.AtomicIndex, ptr %102, i32 0, i32 0
  %104 = atomicrmw add ptr %103, i32 1 seq_cst, align 8
  %105 = add i32 %104, 1
  %106 = shl i32 %105, 23
  %107 = and i32 %106, -8388608
  store i32 %107, ptr %16, align 4, !tbaa !15
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %108, i32 0, i32 1
  %110 = getelementptr inbounds %struct.AtomicIndex, ptr %109, i32 0, i32 0
  %111 = load i32, ptr %16, align 4, !tbaa !15
  %112 = load i32, ptr %8, align 4, !tbaa !15
  %113 = load ptr, ptr %4, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %113, i32 0, i32 8
  %115 = load ptr, ptr %114, align 8, !tbaa !21
  %116 = load i32, ptr %8, align 4, !tbaa !15
  %117 = sub i32 %116, 1
  %118 = zext i32 %117 to i64
  %119 = getelementptr inbounds i32, ptr %115, i64 %118
  call void @Bikeshed_PushRange_private(ptr noundef %110, i32 noundef %111, i32 noundef %112, ptr noundef %119)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  br label %121

120:                                              ; preds = %60
  br label %121

121:                                              ; preds = %120, %100
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %122

122:                                              ; preds = %121, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %123 = load i32, ptr %3, align 4
  ret i32 %123
}

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #2

; Function Attrs: nounwind uwtable
declare hidden void @Bikeshed_ResolveTask_private(ptr noundef, i32 noundef) #1

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 24}
!11 = !{!"Bikeshed_Shed_private", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!12 = !{!"AtomicIndex", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !6, i64 32}
!15 = !{!13, !13, i64 0}
!16 = !{!11, !6, i64 56}
!17 = !{!18, !13, i64 4}
!18 = !{!"Bikeshed_Task_private", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 9, !6, i64 16, !6, i64 24}
!19 = !{!18, !6, i64 16}
!20 = !{!18, !6, i64 24}
!21 = !{!11, !6, i64 40}


; 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.AtomicIndex = type { i32 }
%struct.Bikeshed_Task_private = type { i32, i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare hidden void @Bikeshed_PushRange_private(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @Bikeshed_ExecuteOne(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = zext i8 %1 to i64
  %6 = getelementptr inbounds %struct.AtomicIndex, ptr %4, i64 %5
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %invariant.gep = getelementptr i8, ptr %8, i64 -4
  %9 = load volatile i32, ptr %6, align 4, !tbaa !13
  %10 = and i32 %9, 8388607
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2, %20
  %12 = phi i32 [ %22, %20 ], [ %10, %2 ]
  %13 = phi i32 [ %21, %20 ], [ %9, %2 ]
  %14 = zext nneg i32 %12 to i64
  %gep = getelementptr i32, ptr %invariant.gep, i64 %14
  %15 = load i32, ptr %gep, align 4, !tbaa !13
  %16 = and i32 %13, -8388608
  %17 = or i32 %15, %16
  %18 = cmpxchg ptr %6, i32 %13, i32 %17 seq_cst seq_cst, align 4
  %19 = extractvalue { i32, i1 } %18, 1
  br i1 %19, label %24, label %20

20:                                               ; preds = %.lr.ph
  tail call void @llvm.x86.sse2.pause()
  %21 = load volatile i32, ptr %6, align 4, !tbaa !13
  %22 = and i32 %21, 8388607
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %.thread, label %.lr.ph

24:                                               ; preds = %.lr.ph
  %25 = getelementptr inbounds i8, ptr %0, i64 56
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = add nsw i32 %12, -1
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %26, i64 %28
  %30 = getelementptr inbounds i8, ptr %29, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %29, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %29, i64 24
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = tail call i32 %33(ptr noundef %0, i32 noundef %31, i8 noundef zeroext %1, ptr noundef %35) #1
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %.thread

38:                                               ; preds = %24
  %39 = getelementptr inbounds i8, ptr %29, i64 8
  %40 = load i32, ptr %39, align 8
  %.not = icmp ult i32 %40, 256
  br i1 %.not, label %45, label %41

41:                                               ; preds = %38
  %42 = lshr i32 %40, 8
  tail call void @Bikeshed_ResolveTask_private(ptr noundef nonnull %0, i32 noundef %42)
  %43 = load i32, ptr %39, align 8
  %44 = and i32 %43, 255
  store i32 %44, ptr %39, align 8
  br label %45

45:                                               ; preds = %41, %38
  %46 = getelementptr inbounds i8, ptr %0, i64 16
  %47 = atomicrmw add ptr %46, i32 1 seq_cst, align 8
  %48 = shl i32 %47, 23
  %49 = add i32 %48, 8388608
  %50 = getelementptr inbounds i8, ptr %0, i64 4
  %51 = getelementptr inbounds i8, ptr %0, i64 40
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  %53 = getelementptr inbounds i32, ptr %52, i64 %28
  tail call void @Bikeshed_PushRange_private(ptr noundef nonnull %50, i32 noundef %49, i32 noundef %12, ptr noundef %53)
  br label %.thread

.thread:                                          ; preds = %20, %2, %45, %24
  %.2 = phi i32 [ 1, %24 ], [ 1, %45 ], [ 0, %2 ], [ 0, %20 ]
  ret i32 %.2
}

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #1

; Function Attrs: nounwind uwtable
declare hidden void @Bikeshed_ResolveTask_private(ptr noundef, i32 noundef) local_unnamed_addr #0

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 = { 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, !11, i64 24}
!6 = !{!"Bikeshed_Shed_private", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!7 = !{!"AtomicIndex", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !11, i64 32}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !11, i64 56}
!15 = !{!16, !8, i64 4}
!16 = !{!"Bikeshed_Task_private", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 9, !11, i64 16, !11, i64 24}
!17 = !{!16, !11, i64 16}
!18 = !{!16, !11, i64 24}
!19 = !{!6, !11, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass