; 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
define dso_local void @Bikeshed_FreeTasks(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %16, i64 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = and i32 %18, 8388607
  store i32 %19, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %20 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %20, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %21, i32 0, i32 10
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sub i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %23, i64 %26
  store ptr %27, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8
  %31 = lshr i32 %30, 8
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %44

33:                                               ; preds = %3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8
  %38 = lshr i32 %37, 8
  call void @Bikeshed_FreeDependencies_private(ptr noundef %34, ptr noundef %9, ptr noundef %10, i32 noundef %38)
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8
  %42 = and i32 %41, 255
  %43 = or i32 %42, 0
  store i32 %43, ptr %40, align 8
  br label %44

44:                                               ; preds = %33, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %90, %44
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp ult i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %93

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = and i32 %55, 8388607
  store i32 %56, ptr %13, align 4, !tbaa !9
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %57, i32 0, i32 10
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = sub i32 %60, 1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %59, i64 %62
  store ptr %63, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8
  %67 = lshr i32 %66, 8
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %80

69:                                               ; preds = %50
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8
  %74 = lshr i32 %73, 8
  call void @Bikeshed_FreeDependencies_private(ptr noundef %70, ptr noundef %9, ptr noundef %10, i32 noundef %74)
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %75, i32 0, i32 2
  %77 = load i32, ptr %76, align 8
  %78 = and i32 %77, 255
  %79 = or i32 %78, 0
  store i32 %79, ptr %76, align 8
  br label %80

80:                                               ; preds = %69, %50
  %81 = load i32, ptr %13, align 4, !tbaa !9
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %82, i32 0, i32 8
  %84 = load ptr, ptr %83, align 8, !tbaa !14
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = sub i32 %85, 1
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr %84, i64 %87
  store i32 %81, ptr %88, align 4, !tbaa !9
  %89 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %89, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %90

90:                                               ; preds = %80
  %91 = load i32, ptr %12, align 4, !tbaa !9
  %92 = add i32 %91, 1
  store i32 %92, ptr %12, align 4, !tbaa !9
  br label %45, !llvm.loop !15

93:                                               ; preds = %49
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %116

96:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %97, i32 0, i32 3
  %99 = getelementptr inbounds %struct.AtomicIndex, ptr %98, i32 0, i32 0
  %100 = atomicrmw add ptr %99, i32 1 seq_cst, align 4
  %101 = add i32 %100, 1
  %102 = shl i32 %101, 23
  %103 = and i32 %102, -8388608
  store i32 %103, ptr %14, align 4, !tbaa !9
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %104, i32 0, i32 2
  %106 = getelementptr inbounds %struct.AtomicIndex, ptr %105, i32 0, i32 0
  %107 = load i32, ptr %14, align 4, !tbaa !9
  %108 = load i32, ptr %9, align 4, !tbaa !9
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %109, i32 0, i32 9
  %111 = load ptr, ptr %110, align 8, !tbaa !17
  %112 = load i32, ptr %10, align 4, !tbaa !9
  %113 = sub i32 %112, 1
  %114 = zext i32 %113 to i64
  %115 = getelementptr inbounds i32, ptr %111, i64 %114
  call void @Bikeshed_PushRange_private(ptr noundef %106, i32 noundef %107, i32 noundef %108, ptr noundef %115)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %116

116:                                              ; preds = %96, %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %117, i32 0, i32 4
  %119 = getelementptr inbounds %struct.AtomicIndex, ptr %118, i32 0, i32 0
  %120 = atomicrmw add ptr %119, i32 1 seq_cst, align 8
  %121 = add i32 %120, 1
  %122 = shl i32 %121, 23
  %123 = and i32 %122, -8388608
  store i32 %123, ptr %15, align 4, !tbaa !9
  %124 = load ptr, ptr %4, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %124, i32 0, i32 1
  %126 = getelementptr inbounds %struct.AtomicIndex, ptr %125, i32 0, i32 0
  %127 = load i32, ptr %15, align 4, !tbaa !9
  %128 = load i32, ptr %7, align 4, !tbaa !9
  %129 = load ptr, ptr %4, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.Bikeshed_Shed_private, ptr %129, i32 0, i32 8
  %131 = load ptr, ptr %130, align 8, !tbaa !14
  %132 = load i32, ptr %8, align 4, !tbaa !9
  %133 = sub i32 %132, 1
  %134 = zext i32 %133 to i64
  %135 = getelementptr inbounds i32, ptr %131, i64 %134
  call void @Bikeshed_PushRange_private(ptr noundef %126, i32 noundef %127, i32 noundef %128, ptr noundef %135)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @Bikeshed_PushRange_private(ptr noundef, i32 noundef, i32 noundef, ptr 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"Bikeshed_Shed_private", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!13 = !{!"AtomicIndex", !10, i64 0}
!14 = !{!12, !6, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 48}


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

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

; Function Attrs: mustprogress 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 void @Bikeshed_FreeTasks(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = and i32 %6, 8388607
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = add nsw i32 %7, -1
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %9, i64 %11, i32 2
  %13 = load i32, ptr %12, align 8
  %.not = icmp ult i32 %13, 256
  br i1 %.not, label %18, label %14

14:                                               ; preds = %3
  %15 = lshr i32 %13, 8
  call void @Bikeshed_FreeDependencies_private(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %5, i32 noundef %15)
  %16 = load i32, ptr %12, align 8
  %17 = and i32 %16, 255
  store i32 %17, ptr %12, align 8
  br label %18

18:                                               ; preds = %14, %3
  %19 = icmp ugt i32 %1, 1
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %wide.trip.count = zext i32 %1 to i64
  br label %22

._crit_edge:                                      ; preds = %35, %18
  %.0.lcssa = phi i32 [ %7, %18 ], [ %25, %35 ]
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %.not35 = icmp eq i32 %21, 0
  br i1 %.not35, label %53, label %40

22:                                               ; preds = %.lr.ph, %35
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %35 ]
  %.038 = phi i32 [ %7, %.lr.ph ], [ %25, %35 ]
  %23 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = and i32 %24, 8388607
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = add nsw i32 %25, -1
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %struct.Bikeshed_Task_private, ptr %26, i64 %28, i32 2
  %30 = load i32, ptr %29, align 8
  %.not36 = icmp ult i32 %30, 256
  br i1 %.not36, label %35, label %31

31:                                               ; preds = %22
  %32 = lshr i32 %30, 8
  call void @Bikeshed_FreeDependencies_private(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %5, i32 noundef %32)
  %33 = load i32, ptr %29, align 8
  %34 = and i32 %33, 255
  store i32 %34, ptr %29, align 8
  br label %35

35:                                               ; preds = %31, %22
  %36 = load ptr, ptr %20, align 8, !tbaa !13
  %37 = add nsw i32 %.038, -1
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  store i32 %25, ptr %39, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %22, !llvm.loop !14

40:                                               ; preds = %._crit_edge
  %41 = getelementptr inbounds i8, ptr %0, i64 12
  %42 = atomicrmw add ptr %41, i32 1 seq_cst, align 4
  %43 = shl i32 %42, 23
  %44 = add i32 %43, 8388608
  %45 = getelementptr inbounds i8, ptr %0, i64 8
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %0, i64 48
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add i32 %49, -1
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %48, i64 %51
  call void @Bikeshed_PushRange_private(ptr noundef nonnull %45, i32 noundef %44, i32 noundef %46, ptr noundef %52)
  br label %53

53:                                               ; preds = %40, %._crit_edge
  %54 = getelementptr inbounds i8, ptr %0, i64 16
  %55 = atomicrmw add ptr %54, i32 1 seq_cst, align 8
  %56 = shl i32 %55, 23
  %57 = add i32 %56, 8388608
  %58 = getelementptr inbounds i8, ptr %0, i64 4
  %59 = getelementptr inbounds i8, ptr %0, i64 40
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = add nsw i32 %.0.lcssa, -1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %60, i64 %62
  call void @Bikeshed_PushRange_private(ptr noundef nonnull %58, i32 noundef %57, i32 noundef %7, ptr noundef %63)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret void
}

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

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

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


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