; LLVM IR from stillwater-sc/universal :: c_api/pure_c/test/posit (playground)

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

%union.posit8_u = type { [1 x i8] }

@.str = external hidden unnamed_addr constant [69 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ValidateAddition(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %union.posit8_u, align 1
  %6 = alloca %union.posit8_u, align 1
  %7 = alloca %union.posit8_u, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %union.posit8_u, align 1
  %11 = alloca i32, align 4
  %12 = alloca %union.posit8_u, align 1
  %13 = alloca %union.posit8_u, align 1
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca %union.posit8_u, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 256, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %85, %1
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 256
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %88

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = trunc i32 %23 to i8
  %25 = call i8 @posit8_reinterpret(i8 noundef zeroext %24)
  %26 = getelementptr inbounds %union.posit8_u, ptr %10, i32 0, i32 0
  store i8 %25, ptr %26, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 %10, i64 1, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %81, %22
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 256
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %84

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = trunc i32 %32 to i8
  %34 = call i8 @posit8_reinterpret(i8 noundef zeroext %33)
  %35 = getelementptr inbounds %union.posit8_u, ptr %12, i32 0, i32 0
  store i8 %34, ptr %35, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %6, ptr align 1 %12, i64 1, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %36 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  %37 = load i8, ptr %36, align 1
  %38 = getelementptr inbounds %union.posit8_u, ptr %6, i32 0, i32 0
  %39 = load i8, ptr %38, align 1
  %40 = call i8 @posit8_addp8(i8 %37, i8 %39)
  %41 = getelementptr inbounds %union.posit8_u, ptr %13, i32 0, i32 0
  store i8 %40, ptr %41, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 %13, i64 1, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %42 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  %43 = load i8, ptr %42, align 1
  %44 = call float @posit8_tof(i8 %43)
  store float %44, ptr %14, align 4, !tbaa !13
  %45 = getelementptr inbounds %union.posit8_u, ptr %6, i32 0, i32 0
  %46 = load i8, ptr %45, align 1
  %47 = call float @posit8_tof(i8 %46)
  store float %47, ptr %15, align 4, !tbaa !13
  %48 = load float, ptr %14, align 4, !tbaa !13
  %49 = load float, ptr %15, align 4, !tbaa !13
  %50 = fadd float %48, %49
  store float %50, ptr %16, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #5
  %51 = load float, ptr %16, align 4, !tbaa !13
  %52 = call i8 @posit8_fromf(float noundef %51)
  %53 = getelementptr inbounds %union.posit8_u, ptr %17, i32 0, i32 0
  store i8 %52, ptr %53, align 1
  %54 = getelementptr inbounds %union.posit8_u, ptr %17, i32 0, i32 0
  %55 = load i8, ptr %54, align 1
  %56 = getelementptr inbounds %union.posit8_u, ptr %7, i32 0, i32 0
  %57 = load i8, ptr %56, align 1
  %58 = call i32 @posit8_cmp(i8 %55, i8 %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %80

60:                                               ; preds = %31
  %61 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  %62 = load i8, ptr %61, align 1
  %63 = call zeroext i8 @posit8_bits(i8 %62)
  %64 = zext i8 %63 to i32
  %65 = getelementptr inbounds %union.posit8_u, ptr %6, i32 0, i32 0
  %66 = load i8, ptr %65, align 1
  %67 = call zeroext i8 @posit8_bits(i8 %66)
  %68 = zext i8 %67 to i32
  %69 = getelementptr inbounds %union.posit8_u, ptr %7, i32 0, i32 0
  %70 = load i8, ptr %69, align 1
  %71 = call zeroext i8 @posit8_bits(i8 %70)
  %72 = zext i8 %71 to i32
  %73 = getelementptr inbounds %union.posit8_u, ptr %17, i32 0, i32 0
  %74 = load i8, ptr %73, align 1
  %75 = call zeroext i8 @posit8_bits(i8 %74)
  %76 = zext i8 %75 to i32
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %64, i32 noundef %68, i32 noundef %72, i32 noundef %76)
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %60, %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %11, align 4, !tbaa !9
  br label %27, !llvm.loop !15

84:                                               ; preds = %30
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !9
  br label %18, !llvm.loop !17

88:                                               ; preds = %21
  %89 = load i32, ptr %4, align 4, !tbaa !9
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %93

91:                                               ; preds = %88
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %95

93:                                               ; preds = %88
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %95

95:                                               ; preds = %93, %91
  %96 = load i32, ptr %4, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %96
}

; 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 uwtable
declare hidden i8 @posit8_reinterpret(i8 noundef zeroext) #2

; 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) #3

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

declare i8 @posit8_addp8(i8, i8) #4

declare float @posit8_tof(i8) #4

declare i8 @posit8_fromf(float noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @posit8_cmp(i8, i8) #2

declare i32 @printf(ptr noundef, ...) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @posit8_bits(i8) #2

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 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 nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 1, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@.str = external hidden unnamed_addr constant [69 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ValidateAddition(ptr nocapture noundef readnone %0) local_unnamed_addr #0 {
  br label %4

2:                                                ; preds = %7
  %.not = icmp eq i32 %.2, 0
  %.str.2..str.1 = select i1 %.not, ptr @.str.2, ptr @.str.1
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.1)
  ret i32 %.2

4:                                                ; preds = %1, %7
  %.029 = phi i32 [ 0, %1 ], [ %.2, %7 ]
  %.02328 = phi i32 [ 0, %1 ], [ %8, %7 ]
  %5 = trunc nuw i32 %.02328 to i8
  %6 = tail call i8 @posit8_reinterpret(i8 noundef zeroext %5)
  br label %9

7:                                                ; preds = %29
  %8 = add nuw nsw i32 %.02328, 1
  %exitcond30.not = icmp eq i32 %8, 256
  br i1 %exitcond30.not, label %2, label %4, !llvm.loop !5

9:                                                ; preds = %4, %29
  %.127 = phi i32 [ %.029, %4 ], [ %.2, %29 ]
  %.02426 = phi i32 [ 0, %4 ], [ %30, %29 ]
  %10 = trunc nuw i32 %.02426 to i8
  %11 = tail call i8 @posit8_reinterpret(i8 noundef zeroext %10)
  %12 = tail call i8 @posit8_addp8(i8 %6, i8 %11) #4
  %13 = tail call float @posit8_tof(i8 %6) #4
  %14 = tail call float @posit8_tof(i8 %11) #4
  %15 = fadd float %13, %14
  %16 = tail call i8 @posit8_fromf(float noundef %15) #4
  %17 = tail call i32 @posit8_cmp(i8 %16, i8 %12)
  %.not25 = icmp eq i32 %17, 0
  br i1 %.not25, label %29, label %18

18:                                               ; preds = %9
  %19 = tail call zeroext i8 @posit8_bits(i8 %6)
  %20 = zext i8 %19 to i32
  %21 = tail call zeroext i8 @posit8_bits(i8 %11)
  %22 = zext i8 %21 to i32
  %23 = tail call zeroext i8 @posit8_bits(i8 %12)
  %24 = zext i8 %23 to i32
  %25 = tail call zeroext i8 @posit8_bits(i8 %16)
  %26 = zext i8 %25 to i32
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %20, i32 noundef %22, i32 noundef %24, i32 noundef %26)
  %28 = add nsw i32 %.127, 1
  br label %29

29:                                               ; preds = %18, %9
  %.2 = phi i32 [ %28, %18 ], [ %.127, %9 ]
  %30 = add nuw nsw i32 %.02426, 1
  %exitcond.not = icmp eq i32 %30, 256
  br i1 %exitcond.not, label %7, label %9, !llvm.loop !7
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i8 @posit8_reinterpret(i8 noundef zeroext) local_unnamed_addr #1

declare i8 @posit8_addp8(i8, i8) local_unnamed_addr #2

declare float @posit8_tof(i8) local_unnamed_addr #2

declare i8 @posit8_fromf(float noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @posit8_cmp(i8, i8) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @posit8_bits(i8) local_unnamed_addr #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 = { 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 #2 = { "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 = { nofree 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass