; LLVM IR from matz/streem :: src (core)

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

; 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 dso_local void @strm_task_push(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @strm_emit(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.strm_stream, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 3
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  br label %134

16:                                               ; preds = %3
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = call i32 @strm_nil_p(i64 noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %126, label %20

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.strm_stream, ptr %21, i32 0, i32 6
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %45

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.strm_stream, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.strm_stream, ptr %29, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds %struct.strm_stream, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i64, ptr %5, align 8, !tbaa !9
  call void @strm_task_push(ptr noundef %28, ptr noundef %33, i64 noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.strm_stream, ptr %35, i32 0, i32 6
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds %struct.strm_stream, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = icmp eq i32 %39, 4
  br i1 %40, label %41, label %44

41:                                               ; preds = %25
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.strm_stream, ptr %42, i32 0, i32 6
  store ptr null, ptr %43, align 8, !tbaa !14
  br label %44

44:                                               ; preds = %41, %25
  br label %45

45:                                               ; preds = %44, %20
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.strm_stream, ptr %46, i32 0, i32 7
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %80

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !17
  br label %51

51:                                               ; preds = %76, %50
  %52 = load i32, ptr %7, align 4, !tbaa !17
  %53 = sext i32 %52 to i64
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.strm_stream, ptr %54, i32 0, i32 8
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = icmp ult i64 %53, %56
  br i1 %57, label %58, label %79

58:                                               ; preds = %51
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.strm_stream, ptr %59, i32 0, i32 7
  %61 = load ptr, ptr %60, align 8, !tbaa !16
  %62 = load i32, ptr %7, align 4, !tbaa !17
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds ptr, ptr %61, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.strm_stream, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = load i32, ptr %7, align 4, !tbaa !17
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.strm_stream, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load i64, ptr %5, align 8, !tbaa !9
  call void @strm_task_push(ptr noundef %65, ptr noundef %74, i64 noundef %75)
  br label %76

76:                                               ; preds = %58
  %77 = load i32, ptr %7, align 4, !tbaa !17
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %7, align 4, !tbaa !17
  br label %51, !llvm.loop !19

79:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %80

80:                                               ; preds = %79, %45
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.strm_stream, ptr %81, i32 0, i32 6
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = icmp eq ptr %83, null
  br i1 %84, label %85, label %125

85:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !17
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.strm_stream, ptr %86, i32 0, i32 7
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %115

90:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !17
  br label %91

91:                                               ; preds = %111, %90
  %92 = load i32, ptr %9, align 4, !tbaa !17
  %93 = sext i32 %92 to i64
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.strm_stream, ptr %94, i32 0, i32 8
  %96 = load i64, ptr %95, align 8, !tbaa !18
  %97 = icmp ult i64 %93, %96
  br i1 %97, label %98, label %114

98:                                               ; preds = %91
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.strm_stream, ptr %99, i32 0, i32 7
  %101 = load ptr, ptr %100, align 8, !tbaa !16
  %102 = load i32, ptr %9, align 4, !tbaa !17
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds ptr, ptr %101, i64 %103
  %105 = load ptr, ptr %104, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.strm_stream, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 8, !tbaa !11
  %108 = icmp ne i32 %107, 4
  br i1 %108, label %109, label %110

109:                                              ; preds = %98
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %114

110:                                              ; preds = %98
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %9, align 4, !tbaa !17
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %9, align 4, !tbaa !17
  br label %91, !llvm.loop !21

114:                                              ; preds = %109, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %115

115:                                              ; preds = %114, %85
  %116 = load i32, ptr %8, align 4, !tbaa !17
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %121

118:                                              ; preds = %115
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.strm_stream, ptr %119, i32 0, i32 2
  store i32 3, ptr %120, align 8, !tbaa !11
  store i32 1, ptr %10, align 4
  br label %122

121:                                              ; preds = %115
  store i32 0, ptr %10, align 4
  br label %122

122:                                              ; preds = %121, %118
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %123 = load i32, ptr %10, align 4
  switch i32 %123, label %135 [
    i32 0, label %124
    i32 1, label %134
  ]

124:                                              ; preds = %122
  br label %125

125:                                              ; preds = %124, %80
  br label %126

126:                                              ; preds = %125, %16
  %127 = call i32 @sched_yield() #4
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = icmp ne ptr %128, null
  br i1 %129, label %130, label %134

130:                                              ; preds = %126
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = load ptr, ptr %6, align 8, !tbaa !5
  %133 = call i64 @strm_nil_value()
  call void @strm_task_push(ptr noundef %131, ptr noundef %132, i64 noundef %133)
  br label %134

134:                                              ; preds = %130, %126, %122, %15
  ret void

135:                                              ; preds = %122
  unreachable
}

declare i32 @strm_nil_p(i64 noundef) #2

; Function Attrs: nounwind
declare i32 @sched_yield() #3

declare i64 @strm_nil_value() #2

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 = { "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 "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 #4 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"strm_stream", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 64, !6, i64 72, !13, i64 80, !6, i64 88, !13, i64 96}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 40}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !6, i64 48}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !10, i64 56}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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: nounwind uwtable
declare dso_local void @strm_task_push(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @strm_emit(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 3
  br i1 %6, label %47, label %7

7:                                                ; preds = %3
  %8 = tail call i32 @strm_nil_p(i64 noundef %1) #3
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.thread45

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not36 = icmp eq ptr %11, null
  br i1 %.not36, label %20, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %11, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  tail call void @strm_task_push(ptr noundef nonnull %11, ptr noundef %14, i64 noundef %1)
  %15 = load ptr, ptr %10, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = icmp eq i32 %17, 4
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  store ptr null, ptr %10, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %12, %19, %9
  %21 = phi ptr [ %15, %12 ], [ null, %19 ], [ null, %9 ]
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %.not37 = icmp eq ptr %23, null
  br i1 %.not37, label %.loopexit49, label %.preheader48

.preheader48:                                     ; preds = %20
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %.not53 = icmp eq i64 %25, 0
  br i1 %.not53, label %.loopexit49, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader48, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader48 ]
  %26 = load ptr, ptr %22, align 8, !tbaa !14
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  tail call void @strm_task_push(ptr noundef %28, ptr noundef %30, i64 noundef %1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i64, ptr %24, align 8, !tbaa !15
  %32 = icmp ugt i64 %31, %indvars.iv.next
  br i1 %32, label %.lr.ph, label %.loopexit49.loopexit, !llvm.loop !17

.loopexit49.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %10, align 8, !tbaa !12
  br label %.loopexit49

.loopexit49:                                      ; preds = %.loopexit49.loopexit, %.preheader48, %20
  %33 = phi ptr [ %.pre, %.loopexit49.loopexit ], [ %21, %.preheader48 ], [ %21, %20 ]
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %.thread45

35:                                               ; preds = %.loopexit49
  %36 = load ptr, ptr %22, align 8, !tbaa !14
  %.not38 = icmp eq ptr %36, null
  br i1 %.not38, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %35
  %37 = getelementptr inbounds i8, ptr %0, i64 56
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %.not54 = icmp eq i64 %38, 0
  br i1 %.not54, label %.loopexit, label %.lr.ph52

39:                                               ; preds = %.lr.ph52
  %indvars.iv.next57 = add nuw i64 %indvars.iv56, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next57, %38
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph52, !llvm.loop !19

.lr.ph52:                                         ; preds = %.preheader, %39
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %39 ], [ 0, %.preheader ]
  %40 = getelementptr inbounds ptr, ptr %36, i64 %indvars.iv56
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  %43 = load i32, ptr %42, align 8, !tbaa !5
  %.not39 = icmp eq i32 %43, 4
  br i1 %.not39, label %39, label %.thread45

.loopexit:                                        ; preds = %39, %.preheader, %35
  store i32 3, ptr %4, align 8, !tbaa !5
  br label %47

.thread45:                                        ; preds = %.lr.ph52, %.loopexit49, %7
  %44 = tail call i32 @sched_yield() #3
  %.not41 = icmp eq ptr %2, null
  br i1 %.not41, label %47, label %45

45:                                               ; preds = %.thread45
  %46 = tail call i64 @strm_nil_value() #3
  tail call void @strm_task_push(ptr noundef nonnull %0, ptr noundef nonnull %2, i64 noundef %46)
  br label %47

47:                                               ; preds = %.loopexit, %3, %45, %.thread45
  ret void
}

declare i32 @strm_nil_p(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @sched_yield() local_unnamed_addr #2

declare i64 @strm_nil_value() local_unnamed_addr #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 = { "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 "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, !7, i64 8}
!6 = !{!"strm_stream", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !11, i64 56, !11, i64 64, !10, i64 72, !7, i64 80, !10, i64 88, !7, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 40}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 48}
!15 = !{!6, !11, i64 56}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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