; LLVM IR from Dovyski/opengl-demos :: src/bumpmap/main.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"

%class.Vector = type { float, float, float }

@light = external dso_local global %class.Vector, align 4
@ang = external dso_local global float, align 4
@cont = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z14ilumina_difusa6Vectori(<2 x float>, float, i32 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7displayv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca float, align 4
  %6 = alloca %class.Vector, align 4
  %7 = alloca { <2 x float>, float }, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  call void @glClear(i32 noundef 16384)
  %10 = load i32, ptr @cont, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @cont, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  store i32 0, ptr %1, align 4, !tbaa !5
  %12 = load i32, ptr @cont, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 100
  br i1 %13, label %14, label %15

14:                                               ; preds = %0
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %21

15:                                               ; preds = %0
  %16 = load i32, ptr @cont, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 200
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %20

19:                                               ; preds = %15
  store i32 0, ptr @cont, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %18
  br label %21

21:                                               ; preds = %20, %14
  call void @glMatrixMode(i32 noundef 5889)
  call void @glLoadIdentity()
  call void @gluOrtho2D(double noundef 0.000000e+00, double noundef 4.000000e+02, double noundef 0.000000e+00, double noundef 4.000000e+02)
  call void @glMatrixMode(i32 noundef 5888)
  call void @glBegin(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 100, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %53, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 300
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %56

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 100, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %49, %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 300
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %52

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sitofp i32 %32 to float
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sitofp i32 %34 to float
  call void @_ZN6VectorC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %6, float noundef %33, float noundef 0.000000e+00, float noundef %35)
  %36 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %6, i64 12, i1 false)
  %37 = getelementptr inbounds { <2 x float>, float }, ptr %7, i32 0, i32 0
  %38 = load <2 x float>, ptr %37, align 4
  %39 = getelementptr inbounds { <2 x float>, float }, ptr %7, i32 0, i32 1
  %40 = load float, ptr %39, align 4
  %41 = call noundef float @_Z14ilumina_difusa6Vectori(<2 x float> %38, float %40, i32 noundef %36)
  store float %41, ptr %5, align 4, !tbaa !9
  %42 = load float, ptr %5, align 4, !tbaa !9
  %43 = load float, ptr %5, align 4, !tbaa !9
  %44 = load float, ptr %5, align 4, !tbaa !9
  call void @glColor3f(float noundef %42, float noundef %43, float noundef %44)
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sitofp i32 %45 to double
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sitofp i32 %47 to double
  call void @glVertex2d(double noundef %46, double noundef %48)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %49

49:                                               ; preds = %31
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !11

52:                                               ; preds = %30
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !13

56:                                               ; preds = %25
  call void @glEnd()
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %57 = load float, ptr @ang, align 4, !tbaa !9
  %58 = call noundef float @_ZSt3cosf(float noundef %57)
  %59 = fmul float 1.000000e+02, %58
  store float %59, ptr %8, align 4, !tbaa !9
  %60 = load float, ptr @ang, align 4, !tbaa !9
  %61 = call noundef float @_ZSt3sinf(float noundef %60)
  %62 = fmul float 1.000000e+02, %61
  store float %62, ptr %9, align 4, !tbaa !9
  %63 = load float, ptr %8, align 4, !tbaa !9
  %64 = fadd float %63, 2.000000e+02
  store float %64, ptr @light, align 4, !tbaa !14
  %65 = load float, ptr %9, align 4, !tbaa !9
  %66 = fadd float %65, 2.000000e+02
  store float %66, ptr getelementptr inbounds (%class.Vector, ptr @light, i32 0, i32 2), align 4, !tbaa !16
  %67 = load float, ptr @ang, align 4, !tbaa !9
  %68 = fpext float %67 to double
  %69 = fadd double %68, 3.000000e-02
  %70 = fptrunc double %69 to float
  store float %70, ptr @ang, align 4, !tbaa !9
  call void @glutSwapBuffers()
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  ret void
}

declare void @glClear(i32 noundef) #3

declare void @glMatrixMode(i32 noundef) #3

declare void @glLoadIdentity() #3

declare void @gluOrtho2D(double noundef, double noundef, double noundef, double noundef) #3

declare void @glBegin(i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6VectorC2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #4 align 2

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

declare void @glVertex2d(double noundef, double noundef) #3

declare void @glEnd() #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3cosf(float noundef) #5

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3sinf(float noundef) #5

declare void @glutSwapBuffers() #3

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { inlinehint 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTS6Vector", !10, i64 0, !10, i64 4, !10, i64 8}
!16 = !{!15, !10, i64 8}


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

%class.Vector = type { float, float, float }

@light = external dso_local local_unnamed_addr global %class.Vector, align 4
@ang = external dso_local local_unnamed_addr global float, align 4
@cont = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z14ilumina_difusa6Vectori(<2 x float>, float, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7displayv() local_unnamed_addr #0 {
  %1 = alloca %class.Vector, align 8
  tail call void @glClear(i32 noundef 16384)
  %2 = load i32, ptr @cont, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @cont, align 4, !tbaa !5
  %4 = icmp slt i32 %2, 99
  br i1 %4, label %8, label %5

5:                                                ; preds = %0
  %6 = icmp ult i32 %2, 199
  br i1 %6, label %8, label %7

7:                                                ; preds = %5
  store i32 0, ptr @cont, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %5, %0, %7
  %.0 = phi i32 [ 0, %7 ], [ 1, %0 ], [ 0, %5 ]
  tail call void @glMatrixMode(i32 noundef 5889)
  tail call void @glLoadIdentity()
  tail call void @gluOrtho2D(double noundef 0.000000e+00, double noundef 4.000000e+02, double noundef 0.000000e+00, double noundef 4.000000e+02)
  tail call void @glMatrixMode(i32 noundef 5888)
  tail call void @glBegin(i32 noundef 0)
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  br label %.preheader

.preheader:                                       ; preds = %8, %24
  %.01317 = phi i32 [ 100, %8 ], [ %25, %24 ]
  %9 = uitofp nneg i32 %.01317 to float
  %10 = uitofp nneg i32 %.01317 to double
  br label %26

11:                                               ; preds = %24
  call void @glEnd()
  %12 = load float, ptr @ang, align 4, !tbaa !9
  %13 = call noundef float @_ZSt3cosf(float noundef %12)
  %14 = fmul float %13, 1.000000e+02
  %15 = load float, ptr @ang, align 4, !tbaa !9
  %16 = call noundef float @_ZSt3sinf(float noundef %15)
  %17 = fmul float %16, 1.000000e+02
  %18 = fadd float %14, 2.000000e+02
  store float %18, ptr @light, align 4, !tbaa !11
  %19 = fadd float %17, 2.000000e+02
  store float %19, ptr getelementptr inbounds (i8, ptr @light, i64 8), align 4, !tbaa !13
  %20 = load float, ptr @ang, align 4, !tbaa !9
  %21 = fpext float %20 to double
  %22 = fadd double %21, 3.000000e-02
  %23 = fptrunc double %22 to float
  store float %23, ptr @ang, align 4, !tbaa !9
  call void @glutSwapBuffers()
  ret void

24:                                               ; preds = %26
  %25 = add nuw nsw i32 %.01317, 1
  %exitcond18.not = icmp eq i32 %25, 300
  br i1 %exitcond18.not, label %11, label %.preheader, !llvm.loop !14

26:                                               ; preds = %.preheader, %26
  %.01416 = phi i32 [ 100, %.preheader ], [ %30, %26 ]
  %27 = uitofp nneg i32 %.01416 to float
  call void @_ZN6VectorC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %1, float noundef %9, float noundef 0.000000e+00, float noundef %27)
  %.sroa.0.0.copyload = load <2 x float>, ptr %1, align 8
  %.sroa.2.0.copyload = load float, ptr %.sroa.2.0..sroa_idx, align 8
  %28 = call noundef float @_Z14ilumina_difusa6Vectori(<2 x float> %.sroa.0.0.copyload, float %.sroa.2.0.copyload, i32 noundef %.0)
  call void @glColor3f(float noundef %28, float noundef %28, float noundef %28)
  %29 = uitofp nneg i32 %.01416 to double
  call void @glVertex2d(double noundef %10, double noundef %29)
  %30 = add nuw nsw i32 %.01416, 1
  %exitcond.not = icmp eq i32 %30, 300
  br i1 %exitcond.not, label %24, label %26, !llvm.loop !16
}

declare void @glClear(i32 noundef) local_unnamed_addr #1

declare void @glMatrixMode(i32 noundef) local_unnamed_addr #1

declare void @glLoadIdentity() local_unnamed_addr #1

declare void @gluOrtho2D(double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

declare void @glBegin(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6VectorC2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #2 align 2

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

declare void @glVertex2d(double noundef, double noundef) local_unnamed_addr #1

declare void @glEnd() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3cosf(float noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3sinf(float noundef) local_unnamed_addr #3

declare void @glutSwapBuffers() local_unnamed_addr #1

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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 = { inlinehint 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6Vector", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass