; LLVM IR from Dovyski/opengl-demos :: src/model-md2/md2.ll (ZN9CMD2Model11RenderFrameEv)

; 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.CMD2Model = type <{ i32, i32, i32, [4 x i8], ptr, ptr, ptr, i32, %struct.animState_t, float, [4 x i8] }>
%struct.animState_t = type { i32, i32, i32, float, float, float, i32, i32, i32 }

@_ZN9CMD2Model6anormsE = external dso_local global [162 x [3 x float]], align 16
@_ZL6lcolor = external hidden global [3 x float], align 4
@_ZL9shadedots = external hidden global ptr, align 8
@_ZZN9CMD2Model11RenderFrameEvE8vertlist = external hidden global [2048 x [3 x float]], 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: mustprogress uwtable
define dso_local void @_ZN9CMD2Model11RenderFrameEv(ptr noundef nonnull align 8 dereferenceable(84) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = getelementptr inbounds %class.CMD2Model, ptr %7, i32 0, i32 5
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @glPushAttrib(i32 noundef 8)
  call void @glFrontFace(i32 noundef 2304)
  call void @glEnable(i32 noundef 2884)
  call void @glCullFace(i32 noundef 1029)
  call void @_ZN9CMD2Model15ProcessLightingEv(ptr noundef nonnull align 8 dereferenceable(84) %7)
  call void @_ZN9CMD2Model11InterpolateEPA3_f(ptr noundef nonnull align 8 dereferenceable(84) %7, ptr noundef @_ZZN9CMD2Model11RenderFrameEvE8vertlist)
  %10 = getelementptr inbounds %class.CMD2Model, ptr %7, i32 0, i32 7
  %11 = load i32, ptr %10, align 8, !tbaa !14
  call void @glBindTexture(i32 noundef 3553, i32 noundef %11)
  br label %12

12:                                               ; preds = %83, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %13, i32 1
  store ptr %14, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %13, align 4, !tbaa !15
  store i32 %15, ptr %4, align 4, !tbaa !15
  %16 = load i32, ptr %4, align 4, !tbaa !15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  store i32 3, ptr %5, align 4
  br label %81

19:                                               ; preds = %12
  %20 = load i32, ptr %4, align 4, !tbaa !15
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  call void @glBegin(i32 noundef 6)
  %23 = load i32, ptr %4, align 4, !tbaa !15
  %24 = sub nsw i32 0, %23
  store i32 %24, ptr %4, align 4, !tbaa !15
  br label %26

25:                                               ; preds = %19
  call void @glBegin(i32 noundef 5)
  br label %26

26:                                               ; preds = %25, %22
  br label %27

27:                                               ; preds = %75, %26
  %28 = load i32, ptr %4, align 4, !tbaa !15
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %30, label %80

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %31 = load ptr, ptr @_ZL9shadedots, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.CMD2Model, ptr %7, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %34, i64 2
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %33, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %31, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !17
  store float %42, ptr %6, align 4, !tbaa !17
  %43 = load float, ptr %6, align 4, !tbaa !17
  %44 = load float, ptr @_ZL6lcolor, align 4, !tbaa !17
  %45 = fmul float %43, %44
  %46 = load float, ptr %6, align 4, !tbaa !17
  %47 = load float, ptr getelementptr inbounds ([3 x float], ptr @_ZL6lcolor, i64 0, i64 1), align 4, !tbaa !17
  %48 = fmul float %46, %47
  %49 = load float, ptr %6, align 4, !tbaa !17
  %50 = load float, ptr getelementptr inbounds ([3 x float], ptr @_ZL6lcolor, i64 0, i64 2), align 4, !tbaa !17
  %51 = fmul float %49, %50
  call void @glColor3f(float noundef %45, float noundef %48, float noundef %51)
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds float, ptr %52, i64 0
  %54 = load float, ptr %53, align 4, !tbaa !17
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds float, ptr %55, i64 1
  %57 = load float, ptr %56, align 4, !tbaa !17
  call void @glTexCoord2f(float noundef %54, float noundef %57)
  %58 = getelementptr inbounds %class.CMD2Model, ptr %7, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds i32, ptr %60, i64 2
  %62 = load i32, ptr %61, align 4, !tbaa !15
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %59, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !15
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [162 x [3 x float]], ptr @_ZN9CMD2Model6anormsE, i64 0, i64 %66
  %68 = getelementptr inbounds [3 x float], ptr %67, i64 0, i64 0
  call void @glNormal3fv(ptr noundef %68)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds i32, ptr %69, i64 2
  %71 = load i32, ptr %70, align 4, !tbaa !15
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [2048 x [3 x float]], ptr @_ZZN9CMD2Model11RenderFrameEvE8vertlist, i64 0, i64 %72
  %74 = getelementptr inbounds [3 x float], ptr %73, i64 0, i64 0
  call void @glVertex3fv(ptr noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %75

75:                                               ; preds = %30
  %76 = load i32, ptr %4, align 4, !tbaa !15
  %77 = add nsw i32 %76, -1
  store i32 %77, ptr %4, align 4, !tbaa !15
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds i32, ptr %78, i64 3
  store ptr %79, ptr %3, align 8, !tbaa !5
  br label %27, !llvm.loop !18

80:                                               ; preds = %27
  call void @glEnd()
  store i32 0, ptr %5, align 4
  br label %81

81:                                               ; preds = %80, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %82 = load i32, ptr %5, align 4
  switch i32 %82, label %85 [
    i32 0, label %83
    i32 3, label %84
  ]

83:                                               ; preds = %81
  br label %12, !llvm.loop !20

84:                                               ; preds = %81
  call void @glDisable(i32 noundef 2884)
  call void @glPopAttrib()
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void

85:                                               ; preds = %81
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9CMD2Model15ProcessLightingEv(ptr noundef nonnull align 8 dereferenceable(84)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9CMD2Model11InterpolateEPA3_f(ptr noundef nonnull align 8 dereferenceable(84), ptr noundef) #2 align 2

declare void @glPushAttrib(i32 noundef) #3

declare void @glFrontFace(i32 noundef) #3

declare void @glEnable(i32 noundef) #3

declare void @glCullFace(i32 noundef) #3

declare void @glBindTexture(i32 noundef, i32 noundef) #3

declare void @glBegin(i32 noundef) #3

declare void @glColor3f(float noundef, float noundef, float noundef) #3

declare void @glTexCoord2f(float noundef, float noundef) #3

declare void @glNormal3fv(ptr noundef) #3

declare void @glVertex3fv(ptr noundef) #3

declare void @glEnd() #3

declare void @glDisable(i32 noundef) #3

declare void @glPopAttrib() #3

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 = { mustprogress 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 #3 = { "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, !6, i64 24}
!10 = !{!"_ZTS9CMD2Model", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !12, i64 44, !13, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS11animState_t", !11, i64 0, !11, i64 4, !11, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!13 = !{!"float", !7, i64 0}
!14 = !{!10, !11, i64 40}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 32}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@_ZN9CMD2Model6anormsE = external dso_local global [162 x [3 x float]], align 16
@_ZL6lcolor = external hidden local_unnamed_addr global [3 x float], align 4
@_ZL9shadedots = external hidden local_unnamed_addr global ptr, align 8
@_ZZN9CMD2Model11RenderFrameEvE8vertlist = external hidden global [2048 x [3 x float]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9CMD2Model11RenderFrameEv(ptr noundef nonnull align 8 dereferenceable(84) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @glPushAttrib(i32 noundef 8)
  tail call void @glFrontFace(i32 noundef 2304)
  tail call void @glEnable(i32 noundef 2884)
  tail call void @glCullFace(i32 noundef 1029)
  tail call void @_ZN9CMD2Model15ProcessLightingEv(ptr noundef nonnull align 8 dereferenceable(84) %0)
  tail call void @_ZN9CMD2Model11InterpolateEPA3_f(ptr noundef nonnull align 8 dereferenceable(84) %0, ptr noundef nonnull @_ZZN9CMD2Model11RenderFrameEvE8vertlist)
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load i32, ptr %4, align 8, !tbaa !13
  tail call void @glBindTexture(i32 noundef 3553, i32 noundef %5)
  %6 = load i32, ptr %3, align 4, !tbaa !14
  %.not25 = icmp eq i32 %6, 0
  br i1 %.not25, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  br label %8

8:                                                ; preds = %.lr.ph27, %._crit_edge
  %9 = phi i32 [ %6, %.lr.ph27 ], [ %47, %._crit_edge ]
  %.pn = phi ptr [ %3, %.lr.ph27 ], [ %45, %._crit_edge ]
  %10 = getelementptr inbounds i8, ptr %.pn, i64 4
  %11 = icmp slt i32 %9, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  tail call void @glBegin(i32 noundef 6)
  %13 = sub nsw i32 0, %9
  br label %.lr.ph.preheader

14:                                               ; preds = %8
  tail call void @glBegin(i32 noundef 5)
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12, %14
  %.11823.ph = phi i32 [ %9, %14 ], [ %13, %12 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.124 = phi ptr [ %45, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %.11823 = phi i32 [ %44, %.lr.ph ], [ %.11823.ph, %.lr.ph.preheader ]
  %15 = load ptr, ptr @_ZL9shadedots, align 8, !tbaa !15
  %16 = load ptr, ptr %7, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %.124, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr %16, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %15, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !17
  %25 = load float, ptr @_ZL6lcolor, align 4, !tbaa !17
  %26 = fmul float %24, %25
  %27 = load float, ptr getelementptr inbounds (i8, ptr @_ZL6lcolor, i64 4), align 4, !tbaa !17
  %28 = fmul float %24, %27
  %29 = load float, ptr getelementptr inbounds (i8, ptr @_ZL6lcolor, i64 8), align 4, !tbaa !17
  %30 = fmul float %24, %29
  tail call void @glColor3f(float noundef %26, float noundef %28, float noundef %30)
  %31 = load float, ptr %.124, align 4, !tbaa !17
  %32 = getelementptr inbounds i8, ptr %.124, i64 4
  %33 = load float, ptr %32, align 4, !tbaa !17
  tail call void @glTexCoord2f(float noundef %31, float noundef %33)
  %34 = load ptr, ptr %7, align 8, !tbaa !16
  %35 = load i32, ptr %17, align 4, !tbaa !14
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [162 x [3 x float]], ptr @_ZN9CMD2Model6anormsE, i64 0, i64 %39
  tail call void @glNormal3fv(ptr noundef nonnull %40)
  %41 = load i32, ptr %17, align 4, !tbaa !14
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2048 x [3 x float]], ptr @_ZZN9CMD2Model11RenderFrameEvE8vertlist, i64 0, i64 %42
  tail call void @glVertex3fv(ptr noundef nonnull %43)
  %44 = add nsw i32 %.11823, -1
  %45 = getelementptr inbounds i8, ptr %.124, i64 12
  %46 = icmp ugt i32 %.11823, 1
  br i1 %46, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph
  tail call void @glEnd()
  %47 = load i32, ptr %45, align 4, !tbaa !14
  %.not = icmp eq i32 %47, 0
  br i1 %.not, label %._crit_edge28, label %8

._crit_edge28:                                    ; preds = %._crit_edge, %1
  tail call void @glDisable(i32 noundef 2884)
  tail call void @glPopAttrib()
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9CMD2Model15ProcessLightingEv(ptr noundef nonnull align 8 dereferenceable(84)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9CMD2Model11InterpolateEPA3_f(ptr noundef nonnull align 8 dereferenceable(84), ptr noundef) local_unnamed_addr #1 align 2

declare void @glPushAttrib(i32 noundef) local_unnamed_addr #2

declare void @glFrontFace(i32 noundef) local_unnamed_addr #2

declare void @glEnable(i32 noundef) local_unnamed_addr #2

declare void @glCullFace(i32 noundef) local_unnamed_addr #2

declare void @glBindTexture(i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @glBegin(i32 noundef) local_unnamed_addr #2

declare void @glColor3f(float noundef, float noundef, float noundef) local_unnamed_addr #2

declare void @glTexCoord2f(float noundef, float noundef) local_unnamed_addr #2

declare void @glNormal3fv(ptr noundef) local_unnamed_addr #2

declare void @glVertex3fv(ptr noundef) local_unnamed_addr #2

declare void @glEnd() local_unnamed_addr #2

declare void @glDisable(i32 noundef) local_unnamed_addr #2

declare void @glPopAttrib() local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress 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" }

!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, !10, i64 24}
!6 = !{!"_ZTS9CMD2Model", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !11, i64 44, !12, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS11animState_t", !7, i64 0, !7, i64 4, !7, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 40}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !10, i64 32}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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