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

; 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] }

@__const.posit8_mulp8.p = external hidden unnamed_addr constant %union.posit8_u, align 1

; 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: 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: inlinehint nounwind uwtable
declare signext i8 @posit8_decode_regime(i8 noundef zeroext, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i1 @posit8_isnar(i8) #2

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i1 @posit8_iszero(i8) #2

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i8 @posit8_round(i8 noundef signext, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local i8 @posit8_mulp8(i8 %0, i8 %1) #3 {
  %3 = alloca %union.posit8_u, align 1
  %4 = alloca %union.posit8_u, align 1
  %5 = alloca %union.posit8_u, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = getelementptr inbounds %union.posit8_u, ptr %4, i32 0, i32 0
  store i8 %0, ptr %16, align 1
  %17 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  store i8 %1, ptr %17, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 @__const.posit8_mulp8.p, i64 1, i1 false)
  %18 = getelementptr inbounds %union.posit8_u, ptr %4, i32 0, i32 0
  %19 = load i8, ptr %18, align 1
  %20 = call zeroext i1 @posit8_isnar(i8 %19)
  br i1 %20, label %25, label %21

21:                                               ; preds = %2
  %22 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  %23 = load i8, ptr %22, align 1
  %24 = call zeroext i1 @posit8_isnar(i8 %23)
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %2
  br label %131

26:                                               ; preds = %21
  %27 = getelementptr inbounds %union.posit8_u, ptr %4, i32 0, i32 0
  %28 = load i8, ptr %27, align 1
  %29 = call zeroext i1 @posit8_iszero(i8 %28)
  br i1 %29, label %34, label %30

30:                                               ; preds = %26
  %31 = getelementptr inbounds %union.posit8_u, ptr %5, i32 0, i32 0
  %32 = load i8, ptr %31, align 1
  %33 = call zeroext i1 @posit8_iszero(i8 %32)
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %26
  store i8 0, ptr %3, align 1, !tbaa !5
  br label %131

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  %36 = load i8, ptr %4, align 1, !tbaa !5
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 128
  %39 = icmp ne i32 %38, 0
  %40 = zext i1 %39 to i32
  %41 = load i8, ptr %5, align 1, !tbaa !5
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 128
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i32
  %46 = xor i32 %40, %45
  %47 = icmp ne i32 %46, 0
  %48 = zext i1 %47 to i8
  store i8 %48, ptr %6, align 1, !tbaa !8
  %49 = load i8, ptr %4, align 1, !tbaa !5
  %50 = zext i8 %49 to i32
  %51 = and i32 %50, 128
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %57

53:                                               ; preds = %35
  %54 = load i8, ptr %4, align 1, !tbaa !5
  %55 = zext i8 %54 to i32
  %56 = sub nsw i32 0, %55
  br label %60

57:                                               ; preds = %35
  %58 = load i8, ptr %4, align 1, !tbaa !5
  %59 = zext i8 %58 to i32
  br label %60

60:                                               ; preds = %57, %53
  %61 = phi i32 [ %56, %53 ], [ %59, %57 ]
  %62 = trunc i32 %61 to i8
  store i8 %62, ptr %4, align 1, !tbaa !5
  %63 = load i8, ptr %5, align 1, !tbaa !5
  %64 = zext i8 %63 to i32
  %65 = and i32 %64, 128
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %71

67:                                               ; preds = %60
  %68 = load i8, ptr %5, align 1, !tbaa !5
  %69 = zext i8 %68 to i32
  %70 = sub nsw i32 0, %69
  br label %74

71:                                               ; preds = %60
  %72 = load i8, ptr %5, align 1, !tbaa !5
  %73 = zext i8 %72 to i32
  br label %74

74:                                               ; preds = %71, %67
  %75 = phi i32 [ %70, %67 ], [ %73, %71 ]
  %76 = trunc i32 %75 to i8
  store i8 %76, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  store i8 0, ptr %7, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %77 = load i8, ptr %4, align 1, !tbaa !5
  %78 = call signext i8 @posit8_decode_regime(i8 noundef zeroext %77, ptr noundef %7)
  store i8 %78, ptr %8, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #4
  %79 = load i8, ptr %7, align 1, !tbaa !5
  %80 = zext i8 %79 to i32
  %81 = or i32 128, %80
  %82 = trunc i32 %81 to i16
  store i16 %82, ptr %9, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %83 = load i8, ptr %5, align 1, !tbaa !5
  %84 = call signext i8 @posit8_decode_regime(i8 noundef zeroext %83, ptr noundef %7)
  store i8 %84, ptr %10, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  %85 = load i8, ptr %7, align 1, !tbaa !5
  %86 = zext i8 %85 to i32
  %87 = or i32 128, %86
  %88 = trunc i32 %87 to i16
  store i16 %88, ptr %11, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  %89 = load i16, ptr %9, align 2, !tbaa !10
  %90 = zext i16 %89 to i32
  %91 = load i16, ptr %11, align 2, !tbaa !10
  %92 = zext i16 %91 to i32
  %93 = mul nsw i32 %90, %92
  %94 = trunc i32 %93 to i16
  store i16 %94, ptr %12, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  %95 = load i8, ptr %8, align 1, !tbaa !5
  %96 = sext i8 %95 to i32
  %97 = load i8, ptr %10, align 1, !tbaa !5
  %98 = sext i8 %97 to i32
  %99 = add nsw i32 %96, %98
  %100 = trunc i32 %99 to i8
  store i8 %100, ptr %13, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #4
  %101 = load i16, ptr %12, align 2, !tbaa !10
  %102 = zext i16 %101 to i32
  %103 = and i32 %102, 32768
  %104 = icmp ne i32 %103, 0
  %105 = zext i1 %104 to i8
  store i8 %105, ptr %14, align 1, !tbaa !8
  %106 = load i8, ptr %14, align 1, !tbaa !8, !range !12, !noundef !13
  %107 = trunc i8 %106 to i1
  br i1 %107, label %108, label %115

108:                                              ; preds = %74
  %109 = load i8, ptr %13, align 1, !tbaa !5
  %110 = add i8 %109, 1
  store i8 %110, ptr %13, align 1, !tbaa !5
  %111 = load i16, ptr %12, align 2, !tbaa !10
  %112 = zext i16 %111 to i32
  %113 = ashr i32 %112, 1
  %114 = trunc i32 %113 to i16
  store i16 %114, ptr %12, align 2, !tbaa !10
  br label %115

115:                                              ; preds = %108, %74
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  %116 = load i8, ptr %13, align 1, !tbaa !5
  %117 = load i16, ptr %12, align 2, !tbaa !10
  %118 = call zeroext i8 @posit8_round(i8 noundef signext %116, i16 noundef zeroext %117)
  store i8 %118, ptr %15, align 1, !tbaa !5
  %119 = load i8, ptr %6, align 1, !tbaa !8, !range !12, !noundef !13
  %120 = trunc i8 %119 to i1
  br i1 %120, label %121, label %125

121:                                              ; preds = %115
  %122 = load i8, ptr %15, align 1, !tbaa !5
  %123 = zext i8 %122 to i32
  %124 = sub nsw i32 0, %123
  br label %128

125:                                              ; preds = %115
  %126 = load i8, ptr %15, align 1, !tbaa !5
  %127 = zext i8 %126 to i32
  br label %128

128:                                              ; preds = %125, %121
  %129 = phi i32 [ %124, %121 ], [ %127, %125 ]
  %130 = trunc i32 %129 to i8
  store i8 %130, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  br label %131

131:                                              ; preds = %128, %34, %25
  %132 = getelementptr inbounds %union.posit8_u, ptr %3, i32 0, i32 0
  %133 = load i8, ptr %132, align 1
  ret i8 %133
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"_Bool", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}


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

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

@__const.posit8_mulp8.p = external hidden unnamed_addr constant %union.posit8_u, align 1

; 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: inlinehint nounwind uwtable
declare signext i8 @posit8_decode_regime(i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i1 @posit8_isnar(i8) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i1 @posit8_iszero(i8) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare zeroext i8 @posit8_round(i8 noundef signext, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i8 @posit8_mulp8(i8 %0, i8 %1) local_unnamed_addr #2 {
  %3 = alloca i8, align 1
  %.sroa.026.0.copyload = load i8, ptr @__const.posit8_mulp8.p, align 1
  %4 = tail call zeroext i1 @posit8_isnar(i8 %0)
  br i1 %4, label %28, label %5

5:                                                ; preds = %2
  %6 = tail call zeroext i1 @posit8_isnar(i8 %1)
  br i1 %6, label %28, label %7

7:                                                ; preds = %5
  %8 = tail call zeroext i1 @posit8_iszero(i8 %0)
  br i1 %8, label %28, label %9

9:                                                ; preds = %7
  %10 = tail call zeroext i1 @posit8_iszero(i8 %1)
  br i1 %10, label %28, label %11

11:                                               ; preds = %9
  %.lobit29 = xor i8 %1, %0
  %12 = tail call i8 @llvm.abs.i8(i8 %0, i1 false)
  %13 = tail call i8 @llvm.abs.i8(i8 %1, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  store i8 0, ptr %3, align 1, !tbaa !5
  %14 = call signext i8 @posit8_decode_regime(i8 noundef zeroext %12, ptr noundef nonnull %3)
  %15 = load i8, ptr %3, align 1, !tbaa !5
  %16 = or i8 %15, -128
  %17 = call signext i8 @posit8_decode_regime(i8 noundef zeroext %13, ptr noundef nonnull %3)
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = or i8 %18, -128
  %20 = zext i8 %16 to i16
  %21 = zext i8 %19 to i16
  %22 = mul nuw i16 %21, %20
  %23 = add i8 %17, %14
  %.lobit = lshr i16 %22, 15
  %.027 = lshr i16 %22, %.lobit
  %24 = trunc nuw nsw i16 %.lobit to i8
  %.0 = add i8 %23, %24
  %25 = call zeroext i8 @posit8_round(i8 noundef signext %.0, i16 noundef zeroext %.027)
  %26 = sub i8 0, %25
  %.not31 = icmp slt i8 %.lobit29, 0
  %27 = select i1 %.not31, i8 %26, i8 %25
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  br label %28

28:                                               ; preds = %7, %9, %2, %5, %11
  %.sroa.026.0 = phi i8 [ %.sroa.026.0.copyload, %2 ], [ %.sroa.026.0.copyload, %5 ], [ %27, %11 ], [ 0, %9 ], [ 0, %7 ]
  ret i8 %.sroa.026.0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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