; LLVM IR from osmart/hole2 :: src/retired_routines (surface)

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

@tri_count = external dso_local global i32, align 4
@culled_tri_count = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@tri = external dso_local global [30000 x [5 x i32]], align 16
@culled_tri = external dso_local global [30000 x [6 x i32]], align 16
@.str.62 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @cull_triangles() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %50, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr @tri_count, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %53

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %9
  %11 = getelementptr inbounds [5 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %14
  %16 = getelementptr inbounds [6 x i32], ptr %15, i64 0, i64 0
  store i32 %12, ptr %16, align 8, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %18
  %20 = getelementptr inbounds [5 x i32], ptr %19, i64 0, i64 1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %23
  %25 = getelementptr inbounds [6 x i32], ptr %24, i64 0, i64 1
  store i32 %21, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %27
  %29 = getelementptr inbounds [5 x i32], ptr %28, i64 0, i64 2
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %32
  %34 = getelementptr inbounds [6 x i32], ptr %33, i64 0, i64 2
  store i32 %30, ptr %34, align 8, !tbaa !5
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %36
  %38 = getelementptr inbounds [5 x i32], ptr %37, i64 0, i64 3
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %41
  %43 = getelementptr inbounds [6 x i32], ptr %42, i64 0, i64 3
  store i32 %39, ptr %43, align 4, !tbaa !5
  %44 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %45
  %47 = getelementptr inbounds [6 x i32], ptr %46, i64 0, i64 4
  store i32 0, ptr %47, align 8, !tbaa !5
  %48 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @culled_tri_count, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %7
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !9

53:                                               ; preds = %3
  %54 = load ptr, ptr @stderr, align 8, !tbaa !11
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.62, i32 noundef %55) #3
  %57 = load ptr, ptr @stderr, align 8, !tbaa !11
  %58 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.63, i32 noundef %58) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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

@tri_count = external dso_local local_unnamed_addr global i32, align 4
@culled_tri_count = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@tri = external dso_local local_unnamed_addr global [30000 x [5 x i32]], align 16
@culled_tri = external dso_local local_unnamed_addr global [30000 x [6 x i32]], align 16
@.str.62 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @cull_triangles() local_unnamed_addr #1 {
  %1 = load i32, ptr @tri_count, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %18

.lr.ph.preheader:                                 ; preds = %0
  %culled_tri_count.promoted = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %3 = sext i32 %culled_tri_count.promoted to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %1, 1
  br i1 %4, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv8 = phi i64 [ %3, %.lr.ph.preheader.new ], [ %indvars.iv.next9.1, %.lr.ph ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %5 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %indvars.iv
  %6 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv8
  %7 = load <4 x i32>, ptr %5, align 8, !tbaa !5
  store <4 x i32> %7, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv8, i64 4
  store i32 0, ptr %8, align 8, !tbaa !5
  %indvars.iv.next9 = add nsw i64 %indvars.iv8, 1
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %indvars.iv.next
  %10 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv.next9
  %11 = load <4 x i32>, ptr %9, align 4, !tbaa !5
  store <4 x i32> %11, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv.next9, i64 4
  store i32 0, ptr %12, align 8, !tbaa !5
  %indvars.iv.next9.1 = add nsw i64 %indvars.iv8, 2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.next9.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %indvars.iv.next9.1, %.lr.ph ]
  %indvars.iv8.unr = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next9.1, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %13 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %indvars.iv.unr
  %14 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv8.unr
  %15 = load <4 x i32>, ptr %13, align 4, !tbaa !5
  store <4 x i32> %15, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds [30000 x [6 x i32]], ptr @culled_tri, i64 0, i64 %indvars.iv8.unr, i64 4
  store i32 0, ptr %16, align 8, !tbaa !5
  %indvars.iv.next9.epil = add nsw i64 %indvars.iv8.unr, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %indvars.iv.next9.lcssa = phi i64 [ %indvars.iv.next9.lcssa.ph, %._crit_edge.unr-lcssa ], [ %indvars.iv.next9.epil, %.lr.ph.epil ]
  %17 = trunc nsw i64 %indvars.iv.next9.lcssa to i32
  store i32 %17, ptr @culled_tri_count, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %0
  %19 = load ptr, ptr @stderr, align 8, !tbaa !11
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.62, i32 noundef 0) #2
  %21 = load ptr, ptr @stderr, align 8, !tbaa !11
  %22 = load i32, ptr @culled_tri_count, align 4, !tbaa !5
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.63, i32 noundef %22) #2
  ret void
}

attributes #0 = { nofree nounwind "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 = { nofree 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 = { cold 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass