; 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_State = type { %struct.tagSFG_XYUse, %struct.tagSFG_XYUse, i32, i8, i32, i8, i8, i8, i8, i32, i32, i32, i32, i32, i64, %struct.tagSFG_List, %struct.tagSFG_List, ptr, i32, ptr, ptr, %struct.tagSFG_XYUse, i32, i32, i32, i32, ptr, i8, i8, i32, i32, i32, i32, i32, i32 }
%struct.tagSFG_List = type { ptr, ptr }
%struct.tagSFG_XYUse = type { i32, i32, i8 }

@fgState = external global %struct.tagSFG_State, align 8

; Function Attrs: nounwind uwtable
define dso_local void @fgInitialiseJoysticks() #0 {
  %1 = alloca i32, align 4
  %2 = load i8, ptr getelementptr inbounds (%struct.tagSFG_State, ptr @fgState, i32 0, i32 27), align 8, !tbaa !5
  %3 = icmp ne i8 %2, 0
  br i1 %3, label %14, label %4

4:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !14
  br label %5

5:                                                ; preds = %10, %4
  %6 = load i32, ptr %1, align 4, !tbaa !14
  %7 = icmp slt i32 %6, 2
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load i32, ptr %1, align 4, !tbaa !14
  call void @fghJoystickInit(i32 noundef %9)
  br label %10

10:                                               ; preds = %8
  %11 = load i32, ptr %1, align 4, !tbaa !14
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %1, align 4, !tbaa !14
  br label %5, !llvm.loop !15

13:                                               ; preds = %5
  store i8 1, ptr getelementptr inbounds (%struct.tagSFG_State, ptr @fgState, i32 0, i32 27), align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %14

14:                                               ; preds = %13, %0
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @fghJoystickInit(i32 noundef) #0

; 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, !9, i64 176}
!6 = !{!"tagSFG_State", !7, i64 0, !7, i64 12, !8, i64 24, !9, i64 28, !8, i64 32, !9, i64 36, !9, i64 37, !9, i64 38, !9, i64 39, !8, i64 40, !8, i64 44, !8, i64 48, !8, i64 52, !8, i64 56, !11, i64 64, !12, i64 72, !12, i64 88, !13, i64 104, !8, i64 112, !13, i64 120, !13, i64 128, !7, i64 136, !8, i64 148, !8, i64 152, !8, i64 156, !8, i64 160, !13, i64 168, !9, i64 176, !9, i64 177, !8, i64 180, !8, i64 184, !8, i64 188, !8, i64 192, !8, i64 196, !8, i64 200}
!7 = !{!"tagSFG_XYUse", !8, i64 0, !8, i64 4, !9, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"tagSFG_List", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.tagSFG_State = type { %struct.tagSFG_XYUse, %struct.tagSFG_XYUse, i32, i8, i32, i8, i8, i8, i8, i32, i32, i32, i32, i32, i64, %struct.tagSFG_List, %struct.tagSFG_List, ptr, i32, ptr, ptr, %struct.tagSFG_XYUse, i32, i32, i32, i32, ptr, i8, i8, i32, i32, i32, i32, i32, i32 }
%struct.tagSFG_List = type { ptr, ptr }
%struct.tagSFG_XYUse = type { i32, i32, i8 }

@fgState = external local_unnamed_addr global %struct.tagSFG_State, align 8

; Function Attrs: nounwind uwtable
define dso_local void @fgInitialiseJoysticks() local_unnamed_addr #0 {
  %1 = load i8, ptr getelementptr inbounds (i8, ptr @fgState, i64 176), align 8, !tbaa !5
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %.preheader.preheader, label %2

.preheader.preheader:                             ; preds = %0
  tail call void @fghJoystickInit(i32 noundef 0)
  tail call void @fghJoystickInit(i32 noundef 1)
  store i8 1, ptr getelementptr inbounds (i8, ptr @fgState, i64 176), align 8, !tbaa !5
  br label %2

2:                                                ; preds = %.preheader.preheader, %0
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @fghJoystickInit(i32 noundef) local_unnamed_addr #0

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

!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, !9, i64 176}
!6 = !{!"tagSFG_State", !7, i64 0, !7, i64 12, !8, i64 24, !9, i64 28, !8, i64 32, !9, i64 36, !9, i64 37, !9, i64 38, !9, i64 39, !8, i64 40, !8, i64 44, !8, i64 48, !8, i64 52, !8, i64 56, !11, i64 64, !12, i64 72, !12, i64 88, !13, i64 104, !8, i64 112, !13, i64 120, !13, i64 128, !7, i64 136, !8, i64 148, !8, i64 152, !8, i64 156, !8, i64 160, !13, i64 168, !9, i64 176, !9, i64 177, !8, i64 180, !8, i64 184, !8, i64 188, !8, i64 192, !8, i64 196, !8, i64 200}
!7 = !{!"tagSFG_XYUse", !8, i64 0, !8, i64 4, !9, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"tagSFG_List", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !9, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass