; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzmsg)

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

@MAX_MANTISSA = external hidden global i32, align 4

; 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 i64 @buzzmsg_deserialize_u32(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @buzzmsg_deserialize_float(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = add i64 %11, 8
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.buzzdarray_s, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ugt i64 %12, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i64 -1, ptr %4, align 8
  br label %58

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = call i64 @buzzmsg_deserialize_u32(ptr noundef %8, ptr noundef %19, i32 noundef %20)
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %7, align 4, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = call i64 @buzzmsg_deserialize_u32(ptr noundef %9, ptr noundef %23, i32 noundef %24)
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %18
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store float 0.000000e+00, ptr %30, align 4, !tbaa !14
  br label %55

31:                                               ; preds = %18
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = call i32 @llvm.abs.i32(i32 %32, i1 true)
  %34 = sub nsw i32 %33, 1
  %35 = sitofp i32 %34 to float
  %36 = load i32, ptr @MAX_MANTISSA, align 4, !tbaa !9
  %37 = sitofp i32 %36 to float
  %38 = fmul float 2.000000e+00, %37
  %39 = fdiv float %35, %38
  %40 = fadd float %39, 5.000000e-01
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  store float %40, ptr %41, align 4, !tbaa !14
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load float, ptr %42, align 4, !tbaa !14
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = call float @ldexpf(float noundef %43, i32 noundef %44) #4
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  store float %45, ptr %46, align 4, !tbaa !14
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %31
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load float, ptr %50, align 4, !tbaa !14
  %52 = fneg float %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  store float %52, ptr %53, align 4, !tbaa !14
  br label %54

54:                                               ; preds = %49, %31
  br label %55

55:                                               ; preds = %54, %29
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  store i64 %57, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %58

58:                                               ; preds = %55, %17
  %59 = load i64, ptr %4, align 8
  ret i64 %59
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

; Function Attrs: nounwind
declare float @ldexpf(float noundef, i32 noundef) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"buzzdarray_s", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !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"

@MAX_MANTISSA = external hidden local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress 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 i64 @buzzmsg_deserialize_u32(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -1, 4294967296) i64 @buzzmsg_deserialize_float(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = zext i32 %2 to i64
  %7 = add nuw nsw i64 %6, 8
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp ugt i64 %7, %9
  br i1 %10, label %34, label %11

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %12 = call i64 @buzzmsg_deserialize_u32(ptr noundef nonnull %4, ptr noundef nonnull %1, i32 noundef %2)
  %13 = trunc i64 %12 to i32
  %14 = call i64 @buzzmsg_deserialize_u32(ptr noundef nonnull %5, ptr noundef nonnull %1, i32 noundef %13)
  %15 = load i32, ptr %4, align 4, !tbaa !12
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.sink.split, label %17

17:                                               ; preds = %11
  %18 = call i32 @llvm.abs.i32(i32 %15, i1 true)
  %19 = add nsw i32 %18, -1
  %20 = uitofp nneg i32 %19 to float
  %21 = load i32, ptr @MAX_MANTISSA, align 4, !tbaa !12
  %22 = sitofp i32 %21 to float
  %23 = fmul float %22, 2.000000e+00
  %24 = fdiv float %20, %23
  %25 = fadd float %24, 5.000000e-01
  store float %25, ptr %0, align 4, !tbaa !13
  %26 = load i32, ptr %5, align 4, !tbaa !12
  %27 = call float @ldexpf(float noundef %25, i32 noundef %26) #4
  store float %27, ptr %0, align 4, !tbaa !13
  %28 = load i32, ptr %4, align 4, !tbaa !12
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %17
  %31 = fneg float %27
  br label %.sink.split

.sink.split:                                      ; preds = %11, %30
  %.sink = phi float [ %31, %30 ], [ 0.000000e+00, %11 ]
  store float %.sink, ptr %0, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %.sink.split, %17
  %33 = and i64 %14, 4294967295
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %34

34:                                               ; preds = %3, %32
  %.0 = phi i64 [ %33, %32 ], [ -1, %3 ]
  ret i64 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn
declare float @ldexpf(float noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree nounwind willreturn "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, !10, i64 8}
!6 = !{!"buzzdarray_s", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}


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