; LLVM IR from niessner/Matterport :: code/gaps/pkgs/fglut (freeglut_joystick)

; 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.tagSFG_Window = type { %struct.tagSFG_Node, i32, %struct.tagSFG_Context, %struct.tagSFG_WindowState, [24 x ptr], ptr, [3 x ptr], ptr, ptr, %struct.tagSFG_List, i8 }
%struct.tagSFG_Node = type { ptr, ptr }
%struct.tagSFG_Context = type { i64, ptr, ptr, i32 }
%struct.tagSFG_WindowState = type { i32, i32, i32, i32, i8, i8, i32, i64, i64, i32, i32, i8, i8, i8, i8 }
%struct.tagSFG_List = type { ptr, ptr }
%struct.tagSFG_Joystick = type { %struct.js_event, i32, [16 x float], [128 x i8], i32, i32, i8, [128 x i8], i32, i32, [16 x float], [16 x float], [16 x float], [16 x float], [16 x float] }
%struct.js_event = type { i32, i16, i8, i8 }

@fgJoystick = external hidden global [2 x ptr], align 16

; 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: nounwind uwtable
define dso_local void @fgJoystickPollWindow(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [16 x float], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  store i32 1, ptr %6, align 4
  br label %75

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tagSFG_Window, ptr %11, i32 0, i32 4
  %13 = getelementptr inbounds [24 x ptr], ptr %12, i64 0, i64 13
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  store i32 1, ptr %6, align 4
  br label %75

17:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %71, %17
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 2
  br i1 %20, label %21, label %74

21:                                               ; preds = %18
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2 x ptr], ptr @fgJoystick, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %70

27:                                               ; preds = %21
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2 x ptr], ptr @fgJoystick, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds [16 x float], ptr %3, i64 0, i64 0
  call void @fghJoystickRead(ptr noundef %31, ptr noundef %4, ptr noundef %32)
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2 x ptr], ptr @fgJoystick, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tagSFG_Joystick, ptr %36, i32 0, i32 6
  %38 = load i8, ptr %37, align 4, !tbaa !11
  %39 = icmp ne i8 %38, 0
  br i1 %39, label %69, label %40

40:                                               ; preds = %27
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tagSFG_Window, ptr %42, i32 0, i32 4
  %44 = getelementptr inbounds [24 x ptr], ptr %43, i64 0, i64 13
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %66

47:                                               ; preds = %41
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @fgSetWindow(ptr noundef %48)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tagSFG_Window, ptr %49, i32 0, i32 4
  %51 = getelementptr inbounds [24 x ptr], ptr %50, i64 0, i64 13
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = getelementptr inbounds [16 x float], ptr %3, i64 0, i64 0
  %55 = load float, ptr %54, align 16, !tbaa !15
  %56 = fmul float %55, 1.000000e+03
  %57 = fptosi float %56 to i32
  %58 = getelementptr inbounds [16 x float], ptr %3, i64 0, i64 1
  %59 = load float, ptr %58, align 4, !tbaa !15
  %60 = fmul float %59, 1.000000e+03
  %61 = fptosi float %60 to i32
  %62 = getelementptr inbounds [16 x float], ptr %3, i64 0, i64 2
  %63 = load float, ptr %62, align 8, !tbaa !15
  %64 = fmul float %63, 1.000000e+03
  %65 = fptosi float %64 to i32
  call void %52(i32 noundef %53, i32 noundef %57, i32 noundef %61, i32 noundef %65)
  br label %66

66:                                               ; preds = %47, %41
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68, %27
  br label %70

70:                                               ; preds = %69, %21
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !9
  br label %18, !llvm.loop !17

74:                                               ; preds = %18
  store i32 0, ptr %6, align 4
  br label %75

75:                                               ; preds = %74, %16, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #3
  %76 = load i32, ptr %6, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @fghJoystickRead(ptr noundef, ptr noundef, ptr noundef) #1

declare void @fgSetWindow(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 212}
!12 = !{!"tagSFG_Joystick", !13, i64 0, !10, i64 8, !7, i64 12, !7, i64 76, !10, i64 204, !10, i64 208, !7, i64 212, !7, i64 213, !10, i64 344, !10, i64 348, !7, i64 352, !7, i64 416, !7, i64 480, !7, i64 544, !7, i64 608}
!13 = !{!"js_event", !10, i64 0, !14, i64 4, !7, i64 6, !7, i64 7}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@fgJoystick = external hidden local_unnamed_addr global [2 x ptr], align 16

; 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: nounwind uwtable
define dso_local void @fgJoystickPollWindow(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [16 x float], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 216
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not11 = icmp eq ptr %6, null
  br i1 %.not11, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load ptr, ptr @fgJoystick, align 16, !tbaa !5
  %.not12 = icmp eq ptr %9, null
  br i1 %.not12, label %28, label %10

10:                                               ; preds = %.preheader
  call void @fghJoystickRead(ptr noundef nonnull %9, ptr noundef nonnull %3, ptr noundef nonnull %2)
  %11 = load ptr, ptr @fgJoystick, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 212
  %13 = load i8, ptr %12, align 4, !tbaa !9
  %.not13 = icmp eq i8 %13, 0
  br i1 %.not13, label %14, label %28

14:                                               ; preds = %10
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %.not14 = icmp eq ptr %15, null
  br i1 %.not14, label %28, label %16

16:                                               ; preds = %14
  call void @fgSetWindow(ptr noundef nonnull %0) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !14
  %19 = load float, ptr %2, align 16, !tbaa !15
  %20 = fmul float %19, 1.000000e+03
  %21 = fptosi float %20 to i32
  %22 = load float, ptr %7, align 4, !tbaa !15
  %23 = fmul float %22, 1.000000e+03
  %24 = fptosi float %23 to i32
  %25 = load float, ptr %8, align 8, !tbaa !15
  %26 = fmul float %25, 1.000000e+03
  %27 = fptosi float %26 to i32
  call void %17(i32 noundef %18, i32 noundef %21, i32 noundef %24, i32 noundef %27) #3
  br label %28

28:                                               ; preds = %.preheader, %14, %16, %10
  %29 = load ptr, ptr getelementptr inbounds (i8, ptr @fgJoystick, i64 8), align 8, !tbaa !5
  %.not12.1 = icmp eq ptr %29, null
  br i1 %.not12.1, label %.loopexit, label %30

30:                                               ; preds = %28
  call void @fghJoystickRead(ptr noundef nonnull %29, ptr noundef nonnull %3, ptr noundef nonnull %2)
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @fgJoystick, i64 8), align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 212
  %33 = load i8, ptr %32, align 4, !tbaa !9
  %.not13.1 = icmp eq i8 %33, 0
  br i1 %.not13.1, label %34, label %.loopexit

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %.not14.1 = icmp eq ptr %35, null
  br i1 %.not14.1, label %.loopexit, label %36

36:                                               ; preds = %34
  call void @fgSetWindow(ptr noundef nonnull %0) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !14
  %39 = load float, ptr %2, align 16, !tbaa !15
  %40 = fmul float %39, 1.000000e+03
  %41 = fptosi float %40 to i32
  %42 = load float, ptr %7, align 4, !tbaa !15
  %43 = fmul float %42, 1.000000e+03
  %44 = fptosi float %43 to i32
  %45 = load float, ptr %8, align 8, !tbaa !15
  %46 = fmul float %45, 1.000000e+03
  %47 = fptosi float %46 to i32
  call void %37(i32 noundef %38, i32 noundef %41, i32 noundef %44, i32 noundef %47) #3
  br label %.loopexit

.loopexit:                                        ; preds = %28, %30, %34, %36, %4, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @fghJoystickRead(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @fgSetWindow(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !7, i64 212}
!10 = !{!"tagSFG_Joystick", !11, i64 0, !12, i64 8, !7, i64 12, !7, i64 76, !12, i64 204, !12, i64 208, !7, i64 212, !7, i64 213, !12, i64 344, !12, i64 348, !7, i64 352, !7, i64 416, !7, i64 480, !7, i64 544, !7, i64 608}
!11 = !{!"js_event", !12, i64 0, !13, i64 4, !7, i64 6, !7, i64 7}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass