; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl (tiny_x11_opengl_window)

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

%class.TinyX11OpenGLWindow = type <{ %class.TinyWindowInterface, ptr, i8, i8, [6 x i8] }>
%class.TinyWindowInterface = type { ptr }
%struct.InternalData2 = type { ptr, i64, ptr, i64, %struct.XSetWindowAttributes, i64, ptr, %struct.XWindowAttributes, %union._XEvent, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr }
%struct.XSetWindowAttributes = type { i64, i64, i64, i64, i32, i32, i32, i64, i64, i32, i64, i64, i32, i64, i64 }
%struct.XWindowAttributes = type { i32, i32, i32, i32, i32, i32, ptr, i64, i32, i32, i32, i32, i64, i64, i32, i64, i32, i32, i64, i64, i64, i32, ptr }
%union._XEvent = type { [24 x i64] }

; 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

declare i32 @XFree(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN19TinyX11OpenGLWindow35get_ascii_code_from_virtual_keycodeEi(ptr noundef nonnull align 8 dereferenceable(18) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = getelementptr inbounds %class.TinyX11OpenGLWindow, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.InternalData2, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = trunc i32 %18 to i8
  %20 = call ptr @XGetKeyboardMapping(ptr noundef %17, i8 noundef zeroext %19, i32 noundef 1, ptr noundef %10)
  store ptr %20, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %21, i64 0
  %23 = load i64, ptr %22, align 8, !tbaa !20
  store i64 %23, ptr %7, align 8, !tbaa !20
  %24 = load i64, ptr %7, align 8, !tbaa !20
  switch i64 %24, label %49 [
    i64 65307, label %25
    i64 65293, label %26
    i64 65507, label %27
    i64 65508, label %27
    i64 65361, label %28
    i64 65363, label %29
    i64 65362, label %30
    i64 65364, label %31
    i64 65513, label %32
    i64 65514, label %32
    i64 65505, label %33
    i64 65506, label %33
    i64 65470, label %34
    i64 65471, label %35
    i64 65472, label %36
    i64 65473, label %37
    i64 65474, label %38
    i64 65475, label %39
    i64 65476, label %40
    i64 65477, label %41
    i64 65478, label %42
    i64 65479, label %43
    i64 65480, label %44
    i64 65481, label %45
    i64 65482, label %46
    i64 65483, label %47
    i64 65484, label %48
  ]

25:                                               ; preds = %2
  store i32 27, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

26:                                               ; preds = %2
  store i32 157, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

27:                                               ; preds = %2, %2
  store i32 155, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

28:                                               ; preds = %2
  store i32 143, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

29:                                               ; preds = %2
  store i32 144, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

30:                                               ; preds = %2
  store i32 145, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

31:                                               ; preds = %2
  store i32 146, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

32:                                               ; preds = %2, %2
  store i32 156, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

33:                                               ; preds = %2, %2
  store i32 154, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

34:                                               ; preds = %2
  store i32 128, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

35:                                               ; preds = %2
  store i32 129, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

36:                                               ; preds = %2
  store i32 130, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

37:                                               ; preds = %2
  store i32 131, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

38:                                               ; preds = %2
  store i32 132, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

39:                                               ; preds = %2
  store i32 133, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

40:                                               ; preds = %2
  store i32 134, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

41:                                               ; preds = %2
  store i32 135, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

42:                                               ; preds = %2
  store i32 136, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

43:                                               ; preds = %2
  store i32 137, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

44:                                               ; preds = %2
  store i32 138, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

45:                                               ; preds = %2
  store i32 139, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

46:                                               ; preds = %2
  store i32 140, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

47:                                               ; preds = %2
  store i32 141, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

48:                                               ; preds = %2
  store i32 142, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

49:                                               ; preds = %2
  %50 = load i64, ptr %7, align 8, !tbaa !20
  call void @XConvertCase(i64 noundef %50, ptr noundef %8, ptr noundef %9)
  %51 = load i64, ptr %8, align 8, !tbaa !20
  store i64 %51, ptr %7, align 8, !tbaa !20
  %52 = load i64, ptr %7, align 8, !tbaa !20
  %53 = icmp uge i64 %52, 32
  br i1 %53, label %54, label %57

54:                                               ; preds = %49
  %55 = load i64, ptr %7, align 8, !tbaa !20
  %56 = icmp ule i64 %55, 126
  br i1 %56, label %63, label %57

57:                                               ; preds = %54, %49
  %58 = load i64, ptr %7, align 8, !tbaa !20
  %59 = icmp uge i64 %58, 160
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = load i64, ptr %7, align 8, !tbaa !20
  %62 = icmp ule i64 %61, 255
  br i1 %62, label %63, label %66

63:                                               ; preds = %60, %54
  %64 = load i64, ptr %7, align 8, !tbaa !20
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

66:                                               ; preds = %60, %57
  store i32 -1, ptr %6, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = call i32 @XFree(ptr noundef %68)
  %70 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %70, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %71

71:                                               ; preds = %67, %63, %48, %47, %46, %45, %44, %43, %42, %41, %40, %39, %38, %37, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %72 = load i32, ptr %3, align 4
  ret i32 %72
}

declare ptr @XGetKeyboardMapping(ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef) #1

declare void @XConvertCase(i64 noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS19TinyX11OpenGLWindow", !13, i64 0, !6, i64 8, !14, i64 16, !14, i64 17}
!13 = !{!"_ZTS19TinyWindowInterface"}
!14 = !{!"bool", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTS13InternalData2", !6, i64 0, !17, i64 8, !6, i64 16, !17, i64 24, !18, i64 32, !17, i64 144, !6, i64 152, !19, i64 160, !7, i64 296, !6, i64 488, !10, i64 496, !10, i64 500, !10, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTS20XSetWindowAttributes", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !17, i64 48, !17, i64 56, !10, i64 64, !17, i64 72, !17, i64 80, !10, i64 88, !17, i64 96, !17, i64 104}
!19 = !{!"_ZTS17XWindowAttributes", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !17, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !17, i64 56, !17, i64 64, !10, i64 72, !17, i64 80, !10, i64 88, !10, i64 92, !17, i64 96, !17, i64 104, !17, i64 112, !10, i64 120, !6, i64 128}
!20 = !{!17, !17, i64 0}


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

declare i32 @XFree(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN19TinyX11OpenGLWindow35get_ascii_code_from_virtual_keycodeEi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(18) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = trunc i32 %1 to i8
  %10 = call ptr @XGetKeyboardMapping(ptr noundef %8, i8 noundef zeroext %9, i32 noundef 1, ptr noundef nonnull %5)
  %11 = load i64, ptr %10, align 8, !tbaa !18
  switch i64 %11, label %35 [
    i64 65307, label %43
    i64 65293, label %12
    i64 65507, label %13
    i64 65508, label %13
    i64 65361, label %14
    i64 65363, label %15
    i64 65362, label %16
    i64 65364, label %17
    i64 65513, label %18
    i64 65514, label %18
    i64 65505, label %19
    i64 65506, label %19
    i64 65470, label %20
    i64 65471, label %21
    i64 65472, label %22
    i64 65473, label %23
    i64 65474, label %24
    i64 65475, label %25
    i64 65476, label %26
    i64 65477, label %27
    i64 65478, label %28
    i64 65479, label %29
    i64 65480, label %30
    i64 65481, label %31
    i64 65482, label %32
    i64 65483, label %33
    i64 65484, label %34
  ]

12:                                               ; preds = %2
  br label %43

13:                                               ; preds = %2, %2
  br label %43

14:                                               ; preds = %2
  br label %43

15:                                               ; preds = %2
  br label %43

16:                                               ; preds = %2
  br label %43

17:                                               ; preds = %2
  br label %43

18:                                               ; preds = %2, %2
  br label %43

19:                                               ; preds = %2, %2
  br label %43

20:                                               ; preds = %2
  br label %43

21:                                               ; preds = %2
  br label %43

22:                                               ; preds = %2
  br label %43

23:                                               ; preds = %2
  br label %43

24:                                               ; preds = %2
  br label %43

25:                                               ; preds = %2
  br label %43

26:                                               ; preds = %2
  br label %43

27:                                               ; preds = %2
  br label %43

28:                                               ; preds = %2
  br label %43

29:                                               ; preds = %2
  br label %43

30:                                               ; preds = %2
  br label %43

31:                                               ; preds = %2
  br label %43

32:                                               ; preds = %2
  br label %43

33:                                               ; preds = %2
  br label %43

34:                                               ; preds = %2
  br label %43

35:                                               ; preds = %2
  call void @XConvertCase(i64 noundef %11, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %36 = load i64, ptr %3, align 8, !tbaa !18
  %37 = add i64 %36, -32
  %or.cond = icmp ult i64 %37, 95
  %38 = add i64 %36, -160
  %or.cond3 = icmp ult i64 %38, 96
  %or.cond15 = or i1 %or.cond, %or.cond3
  br i1 %or.cond15, label %39, label %41

39:                                               ; preds = %35
  %40 = trunc nuw i64 %36 to i32
  br label %43

41:                                               ; preds = %35
  %42 = call i32 @XFree(ptr noundef nonnull %10)
  br label %43

43:                                               ; preds = %2, %41, %39, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12
  %.0 = phi i32 [ %40, %39 ], [ -1, %41 ], [ 142, %34 ], [ 141, %33 ], [ 140, %32 ], [ 139, %31 ], [ 138, %30 ], [ 137, %29 ], [ 136, %28 ], [ 135, %27 ], [ 134, %26 ], [ 133, %25 ], [ 132, %24 ], [ 131, %23 ], [ 130, %22 ], [ 129, %21 ], [ 128, %20 ], [ 154, %19 ], [ 156, %18 ], [ 146, %17 ], [ 145, %16 ], [ 144, %15 ], [ 143, %14 ], [ 155, %13 ], [ 157, %12 ], [ 27, %2 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.0
}

declare ptr @XGetKeyboardMapping(ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @XConvertCase(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress 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, !8, i64 8}
!6 = !{!"_ZTS19TinyX11OpenGLWindow", !7, i64 0, !8, i64 8, !11, i64 16, !11, i64 17}
!7 = !{!"_ZTS19TinyWindowInterface"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!13, !8, i64 0}
!13 = !{!"_ZTS13InternalData2", !8, i64 0, !14, i64 8, !8, i64 16, !14, i64 24, !15, i64 32, !14, i64 144, !8, i64 152, !17, i64 160, !9, i64 296, !8, i64 488, !16, i64 496, !16, i64 500, !16, i64 504, !8, i64 512, !8, i64 520, !8, i64 528, !8, i64 536, !8, i64 544}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ZTS20XSetWindowAttributes", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !16, i64 32, !16, i64 36, !16, i64 40, !14, i64 48, !14, i64 56, !16, i64 64, !14, i64 72, !14, i64 80, !16, i64 88, !14, i64 96, !14, i64 104}
!16 = !{!"int", !9, i64 0}
!17 = !{!"_ZTS17XWindowAttributes", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !8, i64 24, !14, i64 32, !16, i64 40, !16, i64 44, !16, i64 48, !16, i64 52, !14, i64 56, !14, i64 64, !16, i64 72, !14, i64 80, !16, i64 88, !16, i64 92, !14, i64 96, !14, i64 104, !14, i64 112, !16, i64 120, !8, i64 128}
!18 = !{!14, !14, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass