; LLVM IR from erincatto/box2d-lite :: extern/glfw/src/xkb_unicode.ll (glfwKeySym2Unicode)

; 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.codepair = type { i16, i16 }

@keysymtab = external hidden constant [828 x %struct.codepair], align 16

; Function Attrs: nounwind uwtable
define dso_local i64 @_glfwKeySym2Unicode(i32 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 827, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp uge i32 %8, 32
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp ule i32 %11, 126
  br i1 %12, label %19, label %13

13:                                               ; preds = %10, %1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp uge i32 %14, 160
  br i1 %15, label %16, label %22

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp ule i32 %17, 255
  br i1 %18, label %19, label %22

19:                                               ; preds = %16, %10
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %73

22:                                               ; preds = %16, %13
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = and i32 %23, -16777216
  %25 = icmp eq i32 %24, 16777216
  br i1 %25, label %26, label %30

26:                                               ; preds = %22
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = and i32 %27, 16777215
  %29 = zext i32 %28 to i64
  store i64 %29, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %73

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %71, %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %72

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %39 = sdiv i32 %38, 2
  store i32 %39, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [828 x %struct.codepair], ptr @keysymtab, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.codepair, ptr %42, i32 0, i32 0
  %44 = load i16, ptr %43, align 4, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = icmp ult i32 %45, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %35
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %71

51:                                               ; preds = %35
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [828 x %struct.codepair], ptr @keysymtab, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.codepair, ptr %54, i32 0, i32 0
  %56 = load i16, ptr %55, align 4, !tbaa !9
  %57 = zext i16 %56 to i32
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = icmp ugt i32 %57, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %51
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sub nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !5
  br label %70

63:                                               ; preds = %51
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [828 x %struct.codepair], ptr @keysymtab, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.codepair, ptr %66, i32 0, i32 1
  %68 = load i16, ptr %67, align 2, !tbaa !12
  %69 = zext i16 %68 to i64
  store i64 %69, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %73

70:                                               ; preds = %60
  br label %71

71:                                               ; preds = %70, %48
  br label %31, !llvm.loop !13

72:                                               ; preds = %31
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %72, %63, %26, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %74 = load i64, ptr %2, align 8
  ret i64 %74
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"codepair", !11, i64 0, !11, i64 2}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 2}
!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.codepair = type { i16, i16 }

@keysymtab = external hidden local_unnamed_addr constant [828 x %struct.codepair], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local range(i64 -1, 4294967296) i64 @_glfwKeySym2Unicode(i32 noundef %0) local_unnamed_addr #0 {
  %2 = add i32 %0, -32
  %or.cond = icmp ult i32 %2, 95
  %3 = add i32 %0, -160
  %or.cond3 = icmp ult i32 %3, 96
  %or.cond27 = or i1 %or.cond, %or.cond3
  br i1 %or.cond27, label %4, label %6

4:                                                ; preds = %1
  %5 = zext nneg i32 %0 to i64
  br label %.loopexit

6:                                                ; preds = %1
  %7 = and i32 %0, -16777216
  %8 = icmp eq i32 %7, 16777216
  br i1 %8, label %9, label %.preheader

9:                                                ; preds = %6
  %10 = and i32 %0, 16777215
  %11 = zext nneg i32 %10 to i64
  br label %.loopexit

.preheader:                                       ; preds = %6, %29
  %.02230 = phi i32 [ %.1, %29 ], [ 827, %6 ]
  %.02329 = phi i32 [ %.124, %29 ], [ 0, %6 ]
  %12 = add nsw i32 %.02230, %.02329
  %13 = sdiv i32 %12, 2
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [828 x %struct.codepair], ptr @keysymtab, i64 0, i64 %14
  %16 = load i16, ptr %15, align 4, !tbaa !5
  %17 = zext i16 %16 to i32
  %18 = icmp ult i32 %17, %0
  br i1 %18, label %19, label %21

19:                                               ; preds = %.preheader
  %20 = add nsw i32 %13, 1
  br label %29

21:                                               ; preds = %.preheader
  %22 = icmp ugt i32 %17, %0
  br i1 %22, label %23, label %25

23:                                               ; preds = %21
  %24 = add nsw i32 %13, -1
  br label %29

25:                                               ; preds = %21
  %26 = getelementptr inbounds [828 x %struct.codepair], ptr @keysymtab, i64 0, i64 %14, i32 1
  %27 = load i16, ptr %26, align 2, !tbaa !10
  %28 = zext i16 %27 to i64
  br label %.loopexit

29:                                               ; preds = %23, %19
  %.124 = phi i32 [ %20, %19 ], [ %.02329, %23 ]
  %.1 = phi i32 [ %.02230, %19 ], [ %24, %23 ]
  %.not = icmp slt i32 %.1, %.124
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !11

.loopexit:                                        ; preds = %29, %25, %9, %4
  %.0 = phi i64 [ %5, %4 ], [ %11, %9 ], [ %28, %25 ], [ -1, %29 ]
  ret i64 %.0
}

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

!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, !7, i64 0}
!6 = !{!"codepair", !7, i64 0, !7, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 2}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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