; 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: nounwind uwtable
declare dso_local zeroext i1 @ra_has_run_container(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ra_portable_header_size(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = call zeroext i1 @ra_has_run_container(ptr noundef %4)
  br i1 %5, label %6, label %35

6:                                                ; preds = %1
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.roaring_array_s, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp slt i32 %9, 4
  br i1 %10, label %11, label %23

11:                                               ; preds = %6
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.roaring_array_s, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = add nsw i32 %14, 7
  %16 = sdiv i32 %15, 8
  %17 = add nsw i32 4, %16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.roaring_array_s, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = mul nsw i32 4, %20
  %22 = add nsw i32 %17, %21
  store i32 %22, ptr %2, align 4
  br label %41

23:                                               ; preds = %6
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.roaring_array_s, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = add nsw i32 %26, 7
  %28 = sdiv i32 %27, 8
  %29 = add nsw i32 4, %28
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.roaring_array_s, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = mul nsw i32 8, %32
  %34 = add nsw i32 %29, %33
  store i32 %34, ptr %2, align 4
  br label %41

35:                                               ; preds = %1
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.roaring_array_s, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = mul nsw i32 8, %38
  %40 = add nsw i32 8, %39
  store i32 %40, ptr %2, align 4
  br label %41

41:                                               ; preds = %35, %23, %11
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

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

!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, !11, i64 0}
!10 = !{!"roaring_array_s", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32}
!11 = !{!"int", !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"

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @ra_has_run_container(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ra_portable_header_size(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i1 @ra_has_run_container(ptr noundef %0)
  %3 = load i32, ptr %0, align 8, !tbaa !5
  br i1 %2, label %4, label %17

4:                                                ; preds = %1
  %5 = icmp slt i32 %3, 4
  %6 = add nsw i32 %3, 7
  br i1 %5, label %7, label %12

7:                                                ; preds = %4
  %8 = sdiv i32 %6, 8
  %9 = shl nsw i32 %3, 2
  %10 = add i32 %9, 4
  %11 = add i32 %10, %8
  br label %20

12:                                               ; preds = %4
  %13 = lshr i32 %6, 3
  %14 = shl nsw i32 %3, 3
  %15 = or disjoint i32 %14, 4
  %16 = add nuw nsw i32 %15, %13
  br label %20

17:                                               ; preds = %1
  %18 = shl nsw i32 %3, 3
  %19 = add nsw i32 %18, 8
  br label %20

20:                                               ; preds = %17, %12, %7
  %.0 = phi i32 [ %11, %7 ], [ %16, %12 ], [ %19, %17 ]
  ret i32 %.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" }

!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}


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