; LLVM IR from aagdev/mlimgsynth :: src/ccommon (stream)

; 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.Stream = type { ptr, ptr, ptr, ptr, ptr, %struct.StreamInt, i64, i32 }
%struct.StreamInt = type { [3 x ptr] }

@g_allocator = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @stream_ibuffer_set(ptr noalias noundef %0, i64 noundef %1, ptr noalias noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %7, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %33

11:                                               ; preds = %3
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp ult i64 %12, 32
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 -257, ptr %4, align 4
  br label %126

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Stream, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 -257, ptr %4, align 4
  br label %126

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Stream, ptr %22, i32 0, i32 7
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %25 = and i32 %24, -9
  store i32 %25, ptr %23, align 8, !tbaa !15
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Stream, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Stream, ptr %29, i32 0, i32 0
  store ptr %26, ptr %30, align 8, !tbaa !16
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Stream, ptr %31, i32 0, i32 1
  store ptr %26, ptr %32, align 8, !tbaa !17
  br label %106

33:                                               ; preds = %3
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp ult i64 %34, 32
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i64 32, ptr %6, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %36, %33
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Stream, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %62

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Stream, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Stream, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = icmp ule ptr %47, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  store i32 0, ptr %4, align 4
  br label %126

53:                                               ; preds = %42
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Stream, ptr %54, i32 0, i32 7
  %56 = load i32, ptr %55, align 8, !tbaa !15
  %57 = xor i32 %56, -1
  %58 = and i32 %57, 8
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %53
  store i32 -257, ptr %4, align 4
  br label %126

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61, %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %63 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Stream, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = call noalias ptr @alloc_realloc(ptr noundef %63, ptr noundef %66, i64 noundef %67) #5
  store ptr %68, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !9
  %72 = call i64 @alloc_size_opt(ptr noundef %69, ptr noundef %70, i64 noundef %71)
  store i64 %72, ptr %6, align 8, !tbaa !9
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Stream, ptr %73, i32 0, i32 7
  %75 = load i32, ptr %74, align 8, !tbaa !15
  %76 = or i32 %75, 8
  store i32 %76, ptr %74, align 8, !tbaa !15
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Stream, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Stream, ptr %80, i32 0, i32 2
  %82 = load ptr, ptr %81, align 8, !tbaa !11
  %83 = ptrtoint ptr %79 to i64
  %84 = ptrtoint ptr %82 to i64
  %85 = sub i64 %83, %84
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds i8, ptr %86, i64 %85
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Stream, ptr %88, i32 0, i32 0
  store ptr %87, ptr %89, align 8, !tbaa !16
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.Stream, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !17
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.Stream, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !11
  %96 = ptrtoint ptr %92 to i64
  %97 = ptrtoint ptr %95 to i64
  %98 = sub i64 %96, %97
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i64 %98
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Stream, ptr %101, i32 0, i32 1
  store ptr %100, ptr %102, align 8, !tbaa !17
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.Stream, ptr %104, i32 0, i32 2
  store ptr %103, ptr %105, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %106

106:                                              ; preds = %62, %21
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.Stream, ptr %107, i32 0, i32 2
  %109 = load ptr, ptr %108, align 8, !tbaa !11
  %110 = load i64, ptr %6, align 8, !tbaa !9
  %111 = getelementptr inbounds i8, ptr %109, i64 %110
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.Stream, ptr %112, i32 0, i32 3
  store ptr %111, ptr %113, align 8, !tbaa !18
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.Stream, ptr %114, i32 0, i32 7
  %116 = load i32, ptr %115, align 8, !tbaa !15
  %117 = and i32 %116, 1
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %125

119:                                              ; preds = %106
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.Stream, ptr %120, i32 0, i32 3
  %122 = load ptr, ptr %121, align 8, !tbaa !18
  %123 = load ptr, ptr %5, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.Stream, ptr %123, i32 0, i32 1
  store ptr %122, ptr %124, align 8, !tbaa !17
  br label %125

125:                                              ; preds = %119, %106
  store i32 0, ptr %4, align 4
  br label %126

126:                                              ; preds = %125, %60, %52, %20, %14
  %127 = load i32, ptr %4, align 4
  ret i32 %127
}

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

; Function Attrs: inlinehint nounwind allocsize(2) uwtable
declare hidden noalias ptr @alloc_realloc(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @alloc_size_opt(ptr noundef, ptr noundef, i64 noundef) #3

; 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 = { inlinehint nounwind allocsize(2) 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 #3 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { allocsize(2) }

!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, !6, i64 16}
!12 = !{!"Stream", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !10, i64 64, !14, i64 72}
!13 = !{!"StreamInt", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 72}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !6, i64 24}


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

@g_allocator = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -257, 1) i32 @stream_ibuffer_set(ptr noalias nocapture noundef %0, i64 noundef %1, ptr noalias noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %14, label %4

4:                                                ; preds = %3
  %5 = icmp ult i64 %1, 32
  br i1 %5, label %51, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not42 = icmp eq ptr %8, null
  br i1 %.not42, label %9, label %51

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = and i32 %11, -9
  store i32 %12, ptr %10, align 8, !tbaa !13
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %0, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %2, ptr %13, align 8, !tbaa !15
  br label %43

14:                                               ; preds = %3
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %1, i64 32)
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not39 = icmp eq ptr %16, null
  br i1 %.not39, label %25, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %16, i64 %spec.store.select
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %.not40 = icmp ugt ptr %18, %20
  br i1 %.not40, label %21, label %51

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 72
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = and i32 %23, 8
  %.not41.not = icmp eq i32 %24, 0
  br i1 %.not41.not, label %51, label %25

25:                                               ; preds = %21, %14
  %26 = load ptr, ptr @g_allocator, align 8, !tbaa !17
  %27 = tail call noalias ptr @alloc_realloc(ptr noundef %26, ptr noundef %16, i64 noundef %spec.store.select) #4
  %28 = load ptr, ptr @g_allocator, align 8, !tbaa !17
  %29 = tail call i64 @alloc_size_opt(ptr noundef %28, ptr noundef %27, i64 noundef %spec.store.select)
  %30 = getelementptr inbounds i8, ptr %0, i64 72
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = or i32 %31, 8
  store i32 %32, ptr %30, align 8, !tbaa !13
  %33 = load ptr, ptr %0, align 8, !tbaa !14
  %34 = ptrtoint ptr %33 to i64
  %35 = ptrtoint ptr %16 to i64
  %36 = sub i64 %34, %35
  %37 = getelementptr inbounds i8, ptr %27, i64 %36
  store ptr %37, ptr %0, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %0, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = ptrtoint ptr %39 to i64
  %41 = sub i64 %40, %35
  %42 = getelementptr inbounds i8, ptr %27, i64 %41
  store ptr %42, ptr %38, align 8, !tbaa !15
  store ptr %27, ptr %15, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %25, %9
  %44 = phi i32 [ %12, %9 ], [ %32, %25 ]
  %45 = phi ptr [ %2, %9 ], [ %27, %25 ]
  %.035 = phi i64 [ %1, %9 ], [ %29, %25 ]
  %46 = getelementptr inbounds i8, ptr %45, i64 %.035
  %47 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %46, ptr %47, align 8, !tbaa !16
  %48 = and i32 %44, 1
  %.not43 = icmp eq i32 %48, 0
  br i1 %.not43, label %51, label %49

49:                                               ; preds = %43
  %50 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %46, ptr %50, align 8, !tbaa !15
  br label %51

51:                                               ; preds = %43, %49, %21, %17, %6, %4
  %.0 = phi i32 [ -257, %4 ], [ -257, %6 ], [ 0, %17 ], [ -257, %21 ], [ 0, %49 ], [ 0, %43 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind allocsize(2) uwtable
declare hidden noalias ptr @alloc_realloc(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @alloc_size_opt(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

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 = { inlinehint nounwind allocsize(2) 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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { allocsize(2) }

!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 16}
!6 = !{!"Stream", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !11, i64 64, !12, i64 72}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"StreamInt", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !12, i64 72}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 24}
!17 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass