; LLVM IR from kala13x/libxutils :: src/net (ws)

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

@g_wsFrameCodes = external hidden constant [16 x %struct.xws_frame_code_], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @XWS_FrameType(i8 noundef zeroext %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !8
  br label %6

6:                                                ; preds = %27, %1
  %7 = load i32, ptr %4, align 4, !tbaa !8
  %8 = zext i32 %7 to i64
  %9 = icmp ult i64 %8, 16
  br i1 %9, label %10, label %30

10:                                               ; preds = %6
  %11 = load i32, ptr %4, align 4, !tbaa !8
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [16 x %struct.xws_frame_code_], ptr @g_wsFrameCodes, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.xws_frame_code_, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 4, !tbaa !10
  %16 = zext i8 %15 to i32
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %16, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %10
  %21 = load i32, ptr %4, align 4, !tbaa !8
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [16 x %struct.xws_frame_code_], ptr @g_wsFrameCodes, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.xws_frame_code_, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !12
  store i32 %25, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %31

26:                                               ; preds = %10
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %4, align 4, !tbaa !8
  %29 = add i32 %28, 1
  store i32 %29, ptr %4, align 4, !tbaa !8
  br label %6, !llvm.loop !13

30:                                               ; preds = %6
  store i32 16, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %31

31:                                               ; preds = %30, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %32 = load i32, ptr %2, align 4
  ret i32 %32
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !6, i64 0}
!10 = !{!11, !6, i64 4}
!11 = !{!"xws_frame_code_", !9, i64 0, !6, i64 4}
!12 = !{!11, !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.xws_frame_code_ = type { i32, i8 }

@g_wsFrameCodes = external hidden local_unnamed_addr constant [16 x %struct.xws_frame_code_], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @XWS_FrameType(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 4), align 4, !tbaa !5
  %3 = icmp eq i8 %2, %0
  br i1 %3, label %49, label %4

4:                                                ; preds = %1
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 12), align 4, !tbaa !5
  %6 = icmp eq i8 %5, %0
  br i1 %6, label %49, label %7

7:                                                ; preds = %4
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 20), align 4, !tbaa !5
  %9 = icmp eq i8 %8, %0
  br i1 %9, label %49, label %10

10:                                               ; preds = %7
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 28), align 4, !tbaa !5
  %12 = icmp eq i8 %11, %0
  br i1 %12, label %49, label %13

13:                                               ; preds = %10
  %14 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 36), align 4, !tbaa !5
  %15 = icmp eq i8 %14, %0
  br i1 %15, label %49, label %16

16:                                               ; preds = %13
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 44), align 4, !tbaa !5
  %18 = icmp eq i8 %17, %0
  br i1 %18, label %49, label %19

19:                                               ; preds = %16
  %20 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 52), align 4, !tbaa !5
  %21 = icmp eq i8 %20, %0
  br i1 %21, label %49, label %22

22:                                               ; preds = %19
  %23 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 60), align 4, !tbaa !5
  %24 = icmp eq i8 %23, %0
  br i1 %24, label %49, label %25

25:                                               ; preds = %22
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 68), align 4, !tbaa !5
  %27 = icmp eq i8 %26, %0
  br i1 %27, label %49, label %28

28:                                               ; preds = %25
  %29 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 76), align 4, !tbaa !5
  %30 = icmp eq i8 %29, %0
  br i1 %30, label %49, label %31

31:                                               ; preds = %28
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 84), align 4, !tbaa !5
  %33 = icmp eq i8 %32, %0
  br i1 %33, label %49, label %34

34:                                               ; preds = %31
  %35 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 92), align 4, !tbaa !5
  %36 = icmp eq i8 %35, %0
  br i1 %36, label %49, label %37

37:                                               ; preds = %34
  %38 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 100), align 4, !tbaa !5
  %39 = icmp eq i8 %38, %0
  br i1 %39, label %49, label %40

40:                                               ; preds = %37
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 108), align 4, !tbaa !5
  %42 = icmp eq i8 %41, %0
  br i1 %42, label %49, label %43

43:                                               ; preds = %40
  %44 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 116), align 4, !tbaa !5
  %45 = icmp eq i8 %44, %0
  br i1 %45, label %49, label %46

46:                                               ; preds = %43
  %47 = load i8, ptr getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 124), align 4, !tbaa !5
  %48 = icmp eq i8 %47, %0
  br i1 %48, label %49, label %.loopexit

49:                                               ; preds = %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4, %1
  %.lcssa = phi ptr [ @g_wsFrameCodes, %1 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 8), %4 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 16), %7 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 24), %10 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 32), %13 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 40), %16 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 48), %19 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 56), %22 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 64), %25 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 72), %28 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 80), %31 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 88), %34 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 96), %37 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 104), %40 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 112), %43 ], [ getelementptr inbounds (i8, ptr @g_wsFrameCodes, i64 120), %46 ]
  %50 = load i32, ptr %.lcssa, align 8, !tbaa !10
  br label %.loopexit

.loopexit:                                        ; preds = %46, %49
  %.06 = phi i32 [ %50, %49 ], [ 16, %46 ]
  ret i32 %.06
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: 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" }

!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, !8, i64 4}
!6 = !{!"xws_frame_code_", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass