; LLVM IR from jermp/2i_bench :: external/CRoaring/src (roaring_array)

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

; 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

declare ptr @get_copy_of_container(ptr noundef, ptr noundef, i1 noundef zeroext) #1

declare ptr @container_clone(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @extend_array(ptr noundef, i32 noundef) #2

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

31:                                               ; preds = %4
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.roaring_array_s, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = load i16, ptr %7, align 2, !tbaa !9
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.roaring_array_s, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !21
  %42 = load i16, ptr %7, align 2, !tbaa !9
  %43 = zext i16 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %8, align 1, !tbaa !11, !range !18, !noundef !19
  %46 = trunc i8 %45 to i1
  %47 = call ptr @get_copy_of_container(ptr noundef %38, ptr noundef %44, i1 noundef zeroext %46)
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.roaring_array_s, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load i16, ptr %7, align 2, !tbaa !9
  %52 = zext i16 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  store ptr %47, ptr %53, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.roaring_array_s, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = load i16, ptr %7, align 2, !tbaa !9
  %58 = zext i16 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %56, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.roaring_array_s, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load i32, ptr %9, align 4, !tbaa !16
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  store ptr %60, ptr %66, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.roaring_array_s, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  %70 = load i16, ptr %7, align 2, !tbaa !9
  %71 = zext i16 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !22
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.roaring_array_s, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !21
  %77 = load i32, ptr %9, align 4, !tbaa !16
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i8, ptr %76, i64 %78
  store i8 %73, ptr %79, align 1, !tbaa !22
  br label %115

80:                                               ; preds = %4
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.roaring_array_s, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !20
  %84 = load i16, ptr %7, align 2, !tbaa !9
  %85 = zext i16 %84 to i64
  %86 = getelementptr inbounds ptr, ptr %83, i64 %85
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.roaring_array_s, ptr %88, i32 0, i32 4
  %90 = load ptr, ptr %89, align 8, !tbaa !21
  %91 = load i16, ptr %7, align 2, !tbaa !9
  %92 = zext i16 %91 to i64
  %93 = getelementptr inbounds i8, ptr %90, i64 %92
  %94 = load i8, ptr %93, align 1, !tbaa !22
  %95 = call ptr @container_clone(ptr noundef %87, i8 noundef zeroext %94)
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.roaring_array_s, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !20
  %99 = load i32, ptr %9, align 4, !tbaa !16
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds ptr, ptr %98, i64 %100
  store ptr %95, ptr %101, align 8, !tbaa !5
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.roaring_array_s, ptr %102, i32 0, i32 4
  %104 = load ptr, ptr %103, align 8, !tbaa !21
  %105 = load i16, ptr %7, align 2, !tbaa !9
  %106 = zext i16 %105 to i64
  %107 = getelementptr inbounds i8, ptr %104, i64 %106
  %108 = load i8, ptr %107, align 1, !tbaa !22
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.roaring_array_s, ptr %109, i32 0, i32 4
  %111 = load ptr, ptr %110, align 8, !tbaa !21
  %112 = load i32, ptr %9, align 4, !tbaa !16
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds i8, ptr %111, i64 %113
  store i8 %108, ptr %114, align 1, !tbaa !22
  br label %115

115:                                              ; preds = %80, %31
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.roaring_array_s, ptr %116, i32 0, i32 0
  %118 = load i32, ptr %117, align 8, !tbaa !13
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %117, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"roaring_array_s", !15, i64 0, !15, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!14, !6, i64 16}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!14, !6, i64 8}
!21 = !{!14, !6, i64 24}
!22 = !{!7, !7, 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"

declare ptr @get_copy_of_container(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare ptr @container_clone(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @extend_array(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ra_append_copy(ptr noundef %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2, i1 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i1 @extend_array(ptr noundef %0, i32 noundef 1)
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = zext i16 %2 to i64
  %10 = getelementptr inbounds i16, ptr %8, i64 %9
  %11 = load i16, ptr %10, align 2, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = sext i32 %6 to i64
  %15 = getelementptr inbounds i16, ptr %13, i64 %14
  store i16 %11, ptr %15, align 2, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds ptr, ptr %17, i64 %9
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %21, i64 %9
  br i1 %3, label %23, label %30

23:                                               ; preds = %4
  %24 = tail call ptr @get_copy_of_container(ptr noundef %19, ptr noundef %22, i1 noundef zeroext true) #2
  %25 = load ptr, ptr %16, align 8, !tbaa !14
  %26 = getelementptr inbounds ptr, ptr %25, i64 %9
  store ptr %24, ptr %26, align 8, !tbaa !15
  %27 = load ptr, ptr %16, align 8, !tbaa !14
  %28 = getelementptr inbounds ptr, ptr %27, i64 %9
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  br label %33

30:                                               ; preds = %4
  %31 = load i8, ptr %22, align 1, !tbaa !17
  %32 = tail call ptr @container_clone(ptr noundef %19, i8 noundef zeroext %31) #2
  br label %33

33:                                               ; preds = %30, %23
  %.sink = phi ptr [ %32, %30 ], [ %29, %23 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds ptr, ptr %35, i64 %14
  store ptr %.sink, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %20, align 8, !tbaa !16
  %38 = getelementptr inbounds i8, ptr %37, i64 %9
  %39 = load i8, ptr %38, align 1, !tbaa !17
  %40 = getelementptr inbounds i8, ptr %0, i64 24
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = getelementptr inbounds i8, ptr %41, i64 %14
  store i8 %39, ptr %42, align 1, !tbaa !17
  %43 = load i32, ptr %0, align 8, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %0, align 8, !tbaa !5
  ret void
}

attributes #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 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 0}
!6 = !{!"roaring_array_s", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !8, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !10, i64 24}
!17 = !{!8, !8, i64 0}


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