; LLVM IR from tezc/sc :: map (sc_map)

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

@sc_map_empty_32 = external hidden constant %struct.sc_map_32, align 8

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 zeroext i1 @sc_map_init_32(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %16

14:                                               ; preds = %3
  %15 = load i32, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %14, %13
  %17 = phi i32 [ 75, %13 ], [ %15, %14 ]
  store i32 %17, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp ugt i32 %18, 95
  br i1 %19, label %23, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp ult i32 %21, 25
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %16
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %64

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %28, ptr align 8 @sc_map_empty_32, i64 32, i1 false), !tbaa.struct !11
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.sc_map_32, ptr %30, i32 0, i32 3
  store i32 %29, ptr %31, align 8, !tbaa !14
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %64

32:                                               ; preds = %24
  %33 = call ptr @sc_map_alloc_32(ptr noundef %6, i32 noundef 1)
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %64

37:                                               ; preds = %32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.sc_map_32, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !16
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.sc_map_32, ptr %41, i32 0, i32 2
  store i32 0, ptr %42, align 4, !tbaa !17
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sc_map_32, ptr %43, i32 0, i32 5
  store i8 0, ptr %44, align 8, !tbaa !18
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.sc_map_32, ptr %46, i32 0, i32 1
  store i32 %45, ptr %47, align 8, !tbaa !19
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.sc_map_32, ptr %49, i32 0, i32 3
  store i32 %48, ptr %50, align 8, !tbaa !14
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.sc_map_32, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !19
  %54 = uitofp i32 %53 to double
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.sc_map_32, ptr %55, i32 0, i32 3
  %57 = load i32, ptr %56, align 8, !tbaa !14
  %58 = uitofp i32 %57 to double
  %59 = fdiv double %58, 1.000000e+02
  %60 = fmul double %54, %59
  %61 = fptoui double %60 to i32
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sc_map_32, ptr %62, i32 0, i32 4
  store i32 %61, ptr %63, align 4, !tbaa !20
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %64

64:                                               ; preds = %37, %36, %27, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %65 = load i1, ptr %4, align 1
  ret i1 %65
}

; Function Attrs: nounwind uwtable
declare hidden ptr @sc_map_alloc_32(ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 8, !5, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 4, !9, i64 24, i64 1, !12, i64 25, i64 1, !12, i64 26, i64 1, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"sc_map_32", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 25, !13, i64 26}
!16 = !{!15, !6, i64 0}
!17 = !{!15, !10, i64 12}
!18 = !{!15, !13, i64 24}
!19 = !{!15, !10, i64 8}
!20 = !{!15, !10, i64 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"

%struct.sc_map_32 = type { ptr, i32, i32, i32, i32, i8, i8, i8 }

@sc_map_empty_32 = external hidden local_unnamed_addr constant %struct.sc_map_32, align 8

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @sc_map_init_32(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = icmp eq i32 %2, 0
  %6 = select i1 %5, i32 75, i32 %2
  %7 = add i32 %6, -96
  %or.cond = icmp ult i32 %7, -71
  br i1 %or.cond, label %27, label %8

8:                                                ; preds = %3
  %9 = icmp eq i32 %1, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) @sc_map_empty_32, i64 32, i1 false), !tbaa.struct !9
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %6, ptr %11, align 8, !tbaa !14
  br label %27

12:                                               ; preds = %8
  %13 = call ptr @sc_map_alloc_32(ptr noundef nonnull %4, i32 noundef 1)
  %14 = icmp eq ptr %13, null
  br i1 %14, label %27, label %15

15:                                               ; preds = %12
  store ptr %13, ptr %0, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %16, align 4, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 0, ptr %17, align 8, !tbaa !18
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %18, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %6, ptr %20, align 8, !tbaa !14
  %21 = uitofp i32 %18 to double
  %22 = uitofp nneg i32 %6 to double
  %23 = fdiv double %22, 1.000000e+02
  %24 = fmul double %23, %21
  %25 = fptoui double %24 to i32
  %26 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %25, ptr %26, align 4, !tbaa !20
  br label %27

27:                                               ; preds = %12, %3, %15, %10
  %.0 = phi i1 [ true, %10 ], [ true, %15 ], [ false, %3 ], [ false, %12 ]
  ret i1 %.0
}

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

attributes #0 = { mustprogress nocallback nofree 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" }

!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 = !{i64 0, i64 8, !10, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 1, !12, i64 25, i64 1, !12, i64 26, i64 1, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"sc_map_32", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !13, i64 24, !13, i64 25, !13, i64 26}
!16 = !{!15, !11, i64 0}
!17 = !{!15, !6, i64 12}
!18 = !{!15, !13, i64 24}
!19 = !{!15, !6, i64 8}
!20 = !{!15, !6, i64 20}


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