; LLVM IR from jovanlanik/wip :: dungeon.d/src (d_menu)

; 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.wip_obj_t = type { %union.anon, %union.anon.0, %union.anon.2 }
%union.anon = type { [3 x float] }
%union.anon.0 = type { [3 x float] }
%union.anon.2 = type { [4 x float] }
%union.wip_globj_t = type { [16 x float] }
%struct.menu_item = type { i32, ptr, ptr }
%struct.menu = type { ptr, ptr, i32, ptr }
%struct.anon = type { float, float, float }

@drawMenu.init = external hidden global i32, align 4
@__const.drawMenu.axis = external hidden unnamed_addr constant [3 x float], align 4
@drawMenu.center = external hidden global %struct.wip_obj_t, align 4
@drawMenu.camera = external hidden global %struct.wip_obj_t, align 4
@drawMenu.offset = external hidden global %struct.wip_obj_t, align 4
@drawMenu.pv = external hidden global %union.wip_globj_t, align 8
@drawMenu.view = external hidden global %union.wip_globj_t, align 4
@drawMenu.projection = external hidden global %union.wip_globj_t, align 4
@drawMenu.default_model = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@glad_glClear = external global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @drawMenuItem(ptr noundef byval(%struct.menu_item) align 8, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @drawMenu(ptr noundef byval(%struct.menu) align 8 %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [3 x float], align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 @__const.drawMenu.axis, i64 12, i1 false)
  %9 = load i32, ptr @drawMenu.init, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %31

11:                                               ; preds = %3
  store i32 1, ptr @drawMenu.init, align 4, !tbaa !5
  %12 = call ptr @wip_makeObject(ptr noundef @drawMenu.center)
  %13 = call ptr @wip_makeObject(ptr noundef @drawMenu.camera)
  %14 = call ptr @wip_makeObject(ptr noundef @drawMenu.offset)
  %15 = load float, ptr getelementptr inbounds (%struct.anon, ptr @drawMenu.camera, i32 0, i32 1), align 4, !tbaa !11
  %16 = fpext float %15 to double
  %17 = fsub double %16, 2.750000e+00
  %18 = fptrunc double %17 to float
  store float %18, ptr getelementptr inbounds (%struct.anon, ptr @drawMenu.camera, i32 0, i32 1), align 4, !tbaa !11
  %19 = load float, ptr @drawMenu.offset, align 4, !tbaa !11
  %20 = fpext float %19 to double
  %21 = fadd double %20, 1.250000e+00
  %22 = fptrunc double %21 to float
  store float %22, ptr @drawMenu.offset, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %23 = call i32 @wip_getConfInt(ptr noundef @.str.2)
  %24 = sitofp i32 %23 to float
  %25 = call i32 @wip_getConfInt(ptr noundef @.str.3)
  %26 = sitofp i32 %25 to float
  %27 = fdiv float %24, %26
  store float %27, ptr %7, align 4, !tbaa !12
  %28 = load float, ptr %7, align 4, !tbaa !12
  call void @mat4x4_perspective(ptr noundef @drawMenu.projection, float noundef 0x3FF921FB60000000, float noundef %28, float noundef 0x3FB99999A0000000, float noundef 1.000000e+03)
  %29 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 0
  call void @mat4x4_look_at(ptr noundef @drawMenu.view, ptr noundef @drawMenu.camera, ptr noundef @drawMenu.center, ptr noundef %29)
  call void @mat4x4_mul(ptr noundef @drawMenu.pv, ptr noundef @drawMenu.projection, ptr noundef @drawMenu.view)
  %30 = call ptr @wip_openModel(ptr noundef @.str.4)
  store ptr %30, ptr @drawMenu.default_model, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %31

31:                                               ; preds = %11, %3
  %32 = load ptr, ptr @glad_glClear, align 8, !tbaa !9
  call void %32(i32 noundef 256)
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  br label %39

37:                                               ; preds = %31
  %38 = load ptr, ptr @drawMenu.default_model, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %37, %35
  %40 = phi ptr [ %36, %35 ], [ %38, %37 ]
  call void @drawModel(ptr noundef @drawMenu.offset, ptr noundef %40, ptr noundef byval(%union.wip_globj_t) align 8 @drawMenu.pv, ptr noundef null)
  %41 = load ptr, ptr @glad_glClear, align 8, !tbaa !9
  call void %41(i32 noundef 256)
  %42 = getelementptr inbounds %struct.menu, ptr %0, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  call void @drawStr(i32 noundef 10, i32 noundef 10, float noundef 1.600000e+01, ptr noundef %43)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %61, %39
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = getelementptr inbounds %struct.menu, ptr %0, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = icmp slt i32 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %64

50:                                               ; preds = %44
  %51 = getelementptr inbounds %struct.menu, ptr %0, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.menu_item, ptr %52, i64 %54
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = icmp eq i32 %57, %58
  %60 = zext i1 %59 to i32
  call void @drawMenuItem(ptr noundef byval(%struct.menu_item) align 8 %55, i32 noundef %56, i32 noundef %60)
  br label %61

61:                                               ; preds = %50
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %8, align 4, !tbaa !5
  br label %44, !llvm.loop !18

64:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #5
  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: 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) #2

declare ptr @wip_makeObject(ptr noundef) #3

declare i32 @wip_getConfInt(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_perspective(ptr noundef, float noundef, float noundef, float noundef, float noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_look_at(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_mul(ptr noundef, ptr noundef, ptr noundef) #4

declare ptr @wip_openModel(ptr noundef) #3

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

declare void @drawModel(ptr noundef, ptr noundef, ptr noundef byval(%union.wip_globj_t) align 8, ptr noundef) #3

declare void @drawStr(i32 noundef, i32 noundef, float noundef, ptr noundef) #3

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 = { nocallback nofree 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 = { inlinehint 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24}
!16 = !{!15, !6, i64 16}
!17 = !{!15, !10, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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.wip_obj_t = type { %union.anon, %union.anon.0, %union.anon.2 }
%union.anon = type { [3 x float] }
%union.anon.0 = type { [3 x float] }
%union.anon.2 = type { [4 x float] }
%union.wip_globj_t = type { [16 x float] }
%struct.menu_item = type { i32, ptr, ptr }
%struct.menu = type { ptr, ptr, i32, ptr }

@drawMenu.init = external hidden local_unnamed_addr global i32, align 4
@__const.drawMenu.axis = external hidden unnamed_addr constant [3 x float], align 4
@drawMenu.center = external hidden global %struct.wip_obj_t, align 4
@drawMenu.camera = external hidden global %struct.wip_obj_t, align 4
@drawMenu.offset = external hidden global %struct.wip_obj_t, align 4
@drawMenu.pv = external hidden global %union.wip_globj_t, align 8
@drawMenu.view = external hidden global %union.wip_globj_t, align 4
@drawMenu.projection = external hidden global %union.wip_globj_t, align 4
@drawMenu.default_model = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@glad_glClear = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @drawMenuItem(ptr noundef byval(%struct.menu_item) align 8, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drawMenu(ptr nocapture noundef readonly byval(%struct.menu) align 8 %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [3 x float], align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %4, ptr noundef nonnull align 4 dereferenceable(12) @__const.drawMenu.axis, i64 12, i1 false)
  %5 = load i32, ptr @drawMenu.init, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %21

7:                                                ; preds = %3
  store i32 1, ptr @drawMenu.init, align 4, !tbaa !5
  %8 = tail call ptr @wip_makeObject(ptr noundef nonnull @drawMenu.center) #5
  %9 = tail call ptr @wip_makeObject(ptr noundef nonnull @drawMenu.camera) #5
  %10 = tail call ptr @wip_makeObject(ptr noundef nonnull @drawMenu.offset) #5
  %11 = load float, ptr getelementptr inbounds (i8, ptr @drawMenu.camera, i64 4), align 4, !tbaa !9
  %12 = fadd float %11, -2.750000e+00
  store float %12, ptr getelementptr inbounds (i8, ptr @drawMenu.camera, i64 4), align 4, !tbaa !9
  %13 = load float, ptr @drawMenu.offset, align 4, !tbaa !9
  %14 = fadd float %13, 1.250000e+00
  store float %14, ptr @drawMenu.offset, align 4, !tbaa !9
  %15 = tail call i32 @wip_getConfInt(ptr noundef nonnull @.str.2) #5
  %16 = sitofp i32 %15 to float
  %17 = tail call i32 @wip_getConfInt(ptr noundef nonnull @.str.3) #5
  %18 = sitofp i32 %17 to float
  %19 = fdiv float %16, %18
  tail call void @mat4x4_perspective(ptr noundef nonnull @drawMenu.projection, float noundef 0x3FF921FB60000000, float noundef %19, float noundef 0x3FB99999A0000000, float noundef 1.000000e+03)
  call void @mat4x4_look_at(ptr noundef nonnull @drawMenu.view, ptr noundef nonnull @drawMenu.camera, ptr noundef nonnull @drawMenu.center, ptr noundef nonnull %4)
  call void @mat4x4_mul(ptr noundef nonnull @drawMenu.pv, ptr noundef nonnull @drawMenu.projection, ptr noundef nonnull @drawMenu.view)
  %20 = call ptr @wip_openModel(ptr noundef nonnull @.str.4) #5
  store ptr %20, ptr @drawMenu.default_model, align 8, !tbaa !10
  br label %21

21:                                               ; preds = %7, %3
  %22 = load ptr, ptr @glad_glClear, align 8, !tbaa !10
  call void %22(i32 noundef 256) #5
  %.not = icmp eq ptr %2, null
  %23 = load ptr, ptr @drawMenu.default_model, align 8
  %24 = select i1 %.not, ptr %23, ptr %2
  call void @drawModel(ptr noundef nonnull @drawMenu.offset, ptr noundef %24, ptr noundef nonnull byval(%union.wip_globj_t) align 8 @drawMenu.pv, ptr noundef null) #5
  %25 = load ptr, ptr @glad_glClear, align 8, !tbaa !10
  call void %25(i32 noundef 256) #5
  %26 = load ptr, ptr %0, align 8, !tbaa !12
  call void @drawStr(i32 noundef 10, i32 noundef 10, float noundef 1.600000e+01, ptr noundef %26) #5
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %21
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = zext i32 %1 to i64
  %wide.trip.count = zext nneg i32 %28 to i64
  br label %33

._crit_edge:                                      ; preds = %33, %21
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  ret void

33:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %34 = getelementptr inbounds %struct.menu_item, ptr %31, i64 %indvars.iv
  %35 = icmp eq i64 %indvars.iv, %32
  %36 = zext i1 %35 to i32
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  call void @drawMenuItem(ptr noundef byval(%struct.menu_item) align 8 %34, i32 noundef %37, i32 noundef %36)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %33, !llvm.loop !16
}

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

; Function Attrs: mustprogress 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) #2

declare ptr @wip_makeObject(ptr noundef) local_unnamed_addr #3

declare i32 @wip_getConfInt(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_perspective(ptr noundef, float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_look_at(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mat4x4_mul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @wip_openModel(ptr noundef) local_unnamed_addr #3

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

declare void @drawModel(ptr noundef, ptr noundef, ptr noundef byval(%union.wip_globj_t) align 8, ptr noundef) local_unnamed_addr #3

declare void @drawStr(i32 noundef, i32 noundef, float noundef, ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree 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 = { inlinehint 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 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!14 = !{!13, !6, i64 16}
!15 = !{!13, !11, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass