; LLVM IR from paroj/gltut :: Tut 06 Objects in Motion/Rotations.ll (Z7displayv)

; 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.Instance = type <{ ptr, %"struct.glm::detail::tvec3", [4 x i8] }>
%"struct.glm::detail::tvec3" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { float, float, float }
%"struct.glm::detail::tmat4x4" = type { [4 x %"struct.glm::detail::tvec4"] }
%"struct.glm::detail::tvec4" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float, float }

@theProgram = external dso_local global i32, align 4
@modelToCameraMatrixUnif = external dso_local global i32, align 4
@_funcptr_glUseProgram = external global ptr, align 8
@_funcptr_glUniformMatrix4fv = external global ptr, align 8
@vao = external dso_local global i32, align 4
@g_instanceList = external dso_local global [5 x %struct.Instance], align 16
@_funcptr_glBindVertexArray = external global ptr, align 8
@_funcptr_glClearColor = external global ptr, align 8
@_funcptr_glClearDepth = external global ptr, align 8
@_funcptr_glClear = external global ptr, align 8
@_funcptr_glDrawElements = external global ptr, align 8

; 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: mustprogress uwtable
define dso_local void @_Z7displayv() #1 {
  %1 = alloca float, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.glm::detail::tmat4x4", align 4
  %6 = load ptr, ptr @_funcptr_glClearColor, align 8, !tbaa !5
  call void %6(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %7 = load ptr, ptr @_funcptr_glClearDepth, align 8, !tbaa !5
  call void %7(double noundef 1.000000e+00)
  %8 = load ptr, ptr @_funcptr_glClear, align 8, !tbaa !5
  call void %8(i32 noundef 16640)
  %9 = load ptr, ptr @_funcptr_glUseProgram, align 8, !tbaa !5
  %10 = load i32, ptr @theProgram, align 4, !tbaa !9
  call void %9(i32 noundef %10)
  %11 = load ptr, ptr @_funcptr_glBindVertexArray, align 8, !tbaa !5
  %12 = load i32, ptr @vao, align 4, !tbaa !9
  call void %11(i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %13 = call i32 @glutGet(i32 noundef 700)
  %14 = sitofp i32 %13 to float
  %15 = fdiv float %14, 1.000000e+03
  store float %15, ptr %1, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %32, %0
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = icmp ult i64 %18, 5
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %35

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [5 x %struct.Instance], ptr @g_instanceList, i64 0, i64 %23
  store ptr %24, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #4
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load float, ptr %1, align 4, !tbaa !11
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind writable sret(%"struct.glm::detail::tmat4x4") align 4 %5, ptr noundef nonnull align 8 dereferenceable(20) %25, float noundef %26)
  store ptr %5, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %28 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %29)
  call void %27(i32 noundef %28, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %30)
  %31 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %31(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %32

32:                                               ; preds = %21
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !9
  br label %16, !llvm.loop !13

35:                                               ; preds = %20
  %36 = load ptr, ptr @_funcptr_glBindVertexArray, align 8, !tbaa !5
  call void %36(i32 noundef 0)
  %37 = load ptr, ptr @_funcptr_glUseProgram, align 8, !tbaa !5
  call void %37(i32 noundef 0)
  call void @glutSwapBuffers()
  call void @glutPostRedisplay()
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

declare i32 @glutGet(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind noalias writable sret(%"struct.glm::detail::tmat4x4") align 4, ptr noundef nonnull align 8 dereferenceable(20), float noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64)) #3

declare void @glutSwapBuffers() #2

declare void @glutPostRedisplay() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { 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, !12, i64 0}
!12 = !{!"float", !7, 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.Instance = type <{ ptr, %"struct.glm::detail::tvec3", [4 x i8] }>
%"struct.glm::detail::tvec3" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { float, float, float }
%"struct.glm::detail::tmat4x4" = type { [4 x %"struct.glm::detail::tvec4"] }
%"struct.glm::detail::tvec4" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float, float }

@theProgram = external dso_local local_unnamed_addr global i32, align 4
@modelToCameraMatrixUnif = external dso_local local_unnamed_addr global i32, align 4
@_funcptr_glUseProgram = external local_unnamed_addr global ptr, align 8
@_funcptr_glUniformMatrix4fv = external local_unnamed_addr global ptr, align 8
@vao = external dso_local local_unnamed_addr global i32, align 4
@g_instanceList = external dso_local global [5 x %struct.Instance], align 16
@_funcptr_glBindVertexArray = external local_unnamed_addr global ptr, align 8
@_funcptr_glClearColor = external local_unnamed_addr global ptr, align 8
@_funcptr_glClearDepth = external local_unnamed_addr global ptr, align 8
@_funcptr_glClear = external local_unnamed_addr global ptr, align 8
@_funcptr_glDrawElements = external local_unnamed_addr global ptr, align 8

; 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: mustprogress uwtable
define dso_local void @_Z7displayv() local_unnamed_addr #1 {
  %1 = alloca %"struct.glm::detail::tmat4x4", align 4
  %2 = load ptr, ptr @_funcptr_glClearColor, align 8, !tbaa !5
  tail call void %2(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %3 = load ptr, ptr @_funcptr_glClearDepth, align 8, !tbaa !5
  tail call void %3(double noundef 1.000000e+00)
  %4 = load ptr, ptr @_funcptr_glClear, align 8, !tbaa !5
  tail call void %4(i32 noundef 16640)
  %5 = load ptr, ptr @_funcptr_glUseProgram, align 8, !tbaa !5
  %6 = load i32, ptr @theProgram, align 4, !tbaa !9
  tail call void %5(i32 noundef %6)
  %7 = load ptr, ptr @_funcptr_glBindVertexArray, align 8, !tbaa !5
  %8 = load i32, ptr @vao, align 4, !tbaa !9
  tail call void %7(i32 noundef %8)
  %9 = tail call i32 @glutGet(i32 noundef 700)
  %10 = sitofp i32 %9 to float
  %11 = fdiv float %10, 1.000000e+03
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind nonnull writable sret(%"struct.glm::detail::tmat4x4") align 4 %1, ptr noundef nonnull align 8 dereferenceable(20) @g_instanceList, float noundef %11)
  %12 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %13 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %14 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %1)
  call void %12(i32 noundef %13, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %14)
  %15 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %15(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind nonnull writable sret(%"struct.glm::detail::tmat4x4") align 4 %1, ptr noundef nonnull align 8 dereferenceable(20) getelementptr inbounds (i8, ptr @g_instanceList, i64 24), float noundef %11)
  %16 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %17 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %18 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %1)
  call void %16(i32 noundef %17, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %18)
  %19 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %19(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind nonnull writable sret(%"struct.glm::detail::tmat4x4") align 4 %1, ptr noundef nonnull align 8 dereferenceable(20) getelementptr inbounds (i8, ptr @g_instanceList, i64 48), float noundef %11)
  %20 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %21 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %22 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %1)
  call void %20(i32 noundef %21, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %22)
  %23 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %23(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind nonnull writable sret(%"struct.glm::detail::tmat4x4") align 4 %1, ptr noundef nonnull align 8 dereferenceable(20) getelementptr inbounds (i8, ptr @g_instanceList, i64 72), float noundef %11)
  %24 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %25 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %26 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %1)
  call void %24(i32 noundef %25, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %26)
  %27 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %27(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  call void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind nonnull writable sret(%"struct.glm::detail::tmat4x4") align 4 %1, ptr noundef nonnull align 8 dereferenceable(20) getelementptr inbounds (i8, ptr @g_instanceList, i64 96), float noundef %11)
  %28 = load ptr, ptr @_funcptr_glUniformMatrix4fv, align 8, !tbaa !5
  %29 = load i32, ptr @modelToCameraMatrixUnif, align 4, !tbaa !9
  %30 = call noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64) %1)
  call void %28(i32 noundef %29, i32 noundef 1, i8 noundef zeroext 0, ptr noundef %30)
  %31 = load ptr, ptr @_funcptr_glDrawElements, align 8, !tbaa !5
  call void %31(i32 noundef 4, i32 noundef 24, i32 noundef 5123, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  %32 = load ptr, ptr @_funcptr_glBindVertexArray, align 8, !tbaa !5
  call void %32(i32 noundef 0)
  %33 = load ptr, ptr @_funcptr_glUseProgram, align 8, !tbaa !5
  call void %33(i32 noundef 0)
  call void @glutSwapBuffers()
  call void @glutPostRedisplay()
  ret void
}

declare i32 @glutGet(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Instance15ConstructMatrixEf(ptr dead_on_unwind noalias writable sret(%"struct.glm::detail::tmat4x4") align 4, ptr noundef nonnull align 8 dereferenceable(20), float noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN3glm9value_ptrIfEEPKT_RKNS_6detail7tmat4x4IS1_EE(ptr noundef nonnull align 4 dereferenceable(64)) local_unnamed_addr #3

declare void @glutSwapBuffers() local_unnamed_addr #2

declare void @glutPostRedisplay() local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass