; LLVM IR from libxsmm/libxsmm :: src (libxsmm_utils)

; 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.anon.0 = type { i32 }

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local float @libxsmm_sexp2_i8(i8 noundef signext %0) #2 {
  %2 = alloca i8, align 1
  %3 = alloca %union.anon.0, align 4
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.memset.p0.i64(ptr align 4 %3, i8 0, i64 4, i1 false)
  %8 = load i8, ptr %2, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = icmp ne i32 -128, %9
  br i1 %10, label %11, label %76

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %12 = load i8, ptr %2, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = icmp sle i32 0, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load i8, ptr %2, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  br label %22

18:                                               ; preds = %11
  %19 = load i8, ptr %2, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = sub nsw i32 0, %20
  br label %22

22:                                               ; preds = %18, %15
  %23 = phi i32 [ %17, %15 ], [ %21, %18 ]
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %4, align 1, !tbaa !5
  %25 = load i8, ptr %4, align 1, !tbaa !5
  %26 = sext i8 %25 to i32
  %27 = icmp slt i32 31, %26
  br i1 %27, label %28, label %61

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %29 = load i8, ptr %4, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = ashr i32 %30, 5
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %33 = load i8, ptr %4, align 1, !tbaa !5
  %34 = sext i8 %33 to i32
  %35 = load i8, ptr %5, align 1, !tbaa !5
  %36 = sext i8 %35 to i32
  %37 = shl i32 %36, 5
  %38 = trunc i32 %37 to i8
  %39 = sext i8 %38 to i32
  %40 = sub nsw i32 %34, %39
  %41 = trunc i32 %40 to i8
  store i8 %41, ptr %6, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store float 0x41F0000000000000, ptr %3, align 4, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !5
  br label %42

42:                                               ; preds = %51, %28
  %43 = load i8, ptr %7, align 1, !tbaa !5
  %44 = sext i8 %43 to i32
  %45 = load i8, ptr %5, align 1, !tbaa !5
  %46 = sext i8 %45 to i32
  %47 = icmp slt i32 %44, %46
  br i1 %47, label %48, label %54

48:                                               ; preds = %42
  %49 = load float, ptr %3, align 4, !tbaa !5
  %50 = fmul float %49, 0x41F0000000000000
  store float %50, ptr %3, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %48
  %52 = load i8, ptr %7, align 1, !tbaa !5
  %53 = add i8 %52, 1
  store i8 %53, ptr %7, align 1, !tbaa !5
  br label %42, !llvm.loop !8

54:                                               ; preds = %42
  %55 = load i8, ptr %6, align 1, !tbaa !5
  %56 = sext i8 %55 to i32
  %57 = shl i32 1, %56
  %58 = uitofp i32 %57 to float
  %59 = load float, ptr %3, align 4, !tbaa !5
  %60 = fmul float %59, %58
  store float %60, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %66

61:                                               ; preds = %22
  %62 = load i8, ptr %4, align 1, !tbaa !5
  %63 = sext i8 %62 to i32
  %64 = shl i32 1, %63
  %65 = uitofp i32 %64 to float
  store float %65, ptr %3, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %61, %54
  %67 = load i8, ptr %4, align 1, !tbaa !5
  %68 = sext i8 %67 to i32
  %69 = load i8, ptr %2, align 1, !tbaa !5
  %70 = sext i8 %69 to i32
  %71 = icmp ne i32 %68, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %66
  %73 = load float, ptr %3, align 4, !tbaa !5
  %74 = fdiv float 1.000000e+00, %73
  store float %74, ptr %3, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %72, %66
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %77

76:                                               ; preds = %1
  store i32 2097152, ptr %3, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %76, %75
  %78 = load float, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local float @libxsmm_sexp2_i8(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = sext i8 %0 to i32
  %.not = icmp eq i8 %0, -128
  br i1 %.not, label %24, label %3

3:                                                ; preds = %1
  %4 = tail call i32 @llvm.abs.i32(i32 %2, i1 true)
  %sext = shl nuw i32 %4, 24
  %5 = ashr exact i32 %sext, 24
  %6 = icmp sgt i32 %5, 31
  br i1 %6, label %7, label %19

7:                                                ; preds = %3
  %8 = lshr i32 %5, 5
  %9 = and i32 %4, 31
  %10 = icmp ugt i32 %5, 63
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.021 = phi i8 [ %13, %.lr.ph ], [ 1, %7 ]
  %11 = phi float [ %12, %.lr.ph ], [ 0x41F0000000000000, %7 ]
  %12 = fmul float %11, 0x41F0000000000000
  %13 = add i8 %.021, 1
  %14 = sext i8 %13 to i32
  %15 = icmp sgt i32 %8, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %7
  %.lcssa = phi float [ 0x41F0000000000000, %7 ], [ %12, %.lr.ph ]
  %16 = shl nuw i32 1, %9
  %17 = uitofp i32 %16 to float
  %18 = fmul float %.lcssa, %17
  br label %22

19:                                               ; preds = %3
  %20 = shl nuw i32 1, %5
  %21 = uitofp i32 %20 to float
  br label %22

22:                                               ; preds = %19, %._crit_edge
  %.sroa.0.1.in = phi float [ %18, %._crit_edge ], [ %21, %19 ]
  %.not20 = icmp eq i32 %5, %2
  %23 = fdiv float 1.000000e+00, %.sroa.0.1.in
  %.sroa.0.2.in = select i1 %.not20, float %.sroa.0.1.in, float %23
  br label %24

24:                                               ; preds = %1, %22
  %25 = phi float [ %.sroa.0.2.in, %22 ], [ 0x37F0000000000000, %1 ]
  ret float %25
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(none) 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 speculatable willreturn memory(none) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass