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

%struct.base_line = type { i32, i32, i32, i32, i32, i32, ptr, ptr }

@tri_count = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@dots = external dso_local global [30000 x [7 x double]], align 16
@tri = external dso_local global [30000 x [5 x i32]], align 16
@.str.20 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [45 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gen_triangle(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load i32, ptr @tri_count, align 4, !tbaa !9
  %5 = icmp eq i32 %4, 30000
  br i1 %5, label %6, label %11

6:                                                ; preds = %1
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef @.str.22) #3
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.20) #3
  call void @exit(i32 noundef 1) #4
  unreachable

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

48:                                               ; preds = %11
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.base_line, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %52
  %54 = getelementptr inbounds [7 x double], ptr %53, i64 0, i64 3
  %55 = load double, ptr %54, align 8, !tbaa !15
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.base_line, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %59
  %61 = getelementptr inbounds [7 x double], ptr %60, i64 0, i64 3
  %62 = load double, ptr %61, align 8, !tbaa !15
  %63 = fcmp oeq double %55, %62
  br i1 %63, label %64, label %79

64:                                               ; preds = %48, %11
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.base_line, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %68
  %70 = getelementptr inbounds [7 x double], ptr %69, i64 0, i64 3
  %71 = load double, ptr %70, align 8, !tbaa !15
  %72 = fptosi double %71 to i32
  %73 = load i32, ptr @tri_count, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %74
  %76 = getelementptr inbounds [5 x i32], ptr %75, i64 0, i64 3
  store i32 %72, ptr %76, align 4, !tbaa !9
  %77 = load i32, ptr @tri_count, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr @tri_count, align 4, !tbaa !9
  store i32 0, ptr %2, align 4
  br label %125

79:                                               ; preds = %48
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.base_line, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !13
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %83
  %85 = getelementptr inbounds [7 x double], ptr %84, i64 0, i64 3
  %86 = load double, ptr %85, align 8, !tbaa !15
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.base_line, ptr %87, i32 0, i32 2
  %89 = load i32, ptr %88, align 8, !tbaa !14
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %90
  %92 = getelementptr inbounds [7 x double], ptr %91, i64 0, i64 3
  %93 = load double, ptr %92, align 8, !tbaa !15
  %94 = fcmp oeq double %86, %93
  br i1 %94, label %95, label %110

95:                                               ; preds = %79
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.base_line, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 4, !tbaa !13
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %99
  %101 = getelementptr inbounds [7 x double], ptr %100, i64 0, i64 3
  %102 = load double, ptr %101, align 8, !tbaa !15
  %103 = fptosi double %102 to i32
  %104 = load i32, ptr @tri_count, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %105
  %107 = getelementptr inbounds [5 x i32], ptr %106, i64 0, i64 3
  store i32 %103, ptr %107, align 4, !tbaa !9
  %108 = load i32, ptr @tri_count, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr @tri_count, align 4, !tbaa !9
  store i32 0, ptr %2, align 4
  br label %125

110:                                              ; preds = %79
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.base_line, ptr %111, i32 0, i32 0
  %113 = load i32, ptr %112, align 8, !tbaa !11
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %114
  %116 = getelementptr inbounds [7 x double], ptr %115, i64 0, i64 3
  %117 = load double, ptr %116, align 8, !tbaa !15
  %118 = fptosi double %117 to i32
  %119 = load i32, ptr @tri_count, align 4, !tbaa !9
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %120
  %122 = getelementptr inbounds [5 x i32], ptr %121, i64 0, i64 3
  store i32 %118, ptr %122, align 4, !tbaa !9
  %123 = load i32, ptr @tri_count, align 4, !tbaa !9
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr @tri_count, align 4, !tbaa !9
  store i32 0, ptr %2, align 4
  br label %125

125:                                              ; preds = %110, %95, %64
  %126 = load i32, ptr %2, align 4
  ret i32 %126
}

attributes #0 = { 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 = { noreturn 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 }
attributes #4 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"base_line", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !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
@stderr = external local_unnamed_addr global ptr, align 8
@dots = external dso_local local_unnamed_addr global [30000 x [7 x double]], align 16
@tri = external dso_local local_unnamed_addr global [30000 x [5 x i32]], align 16
@.str.20 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [45 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: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @gen_triangle(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = load i32, ptr @tri_count, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 30000
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !9
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.22) #3
  %7 = load ptr, ptr @stderr, align 8, !tbaa !9
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.20) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

9:                                                ; preds = %1
  %10 = load i32, ptr %0, align 8, !tbaa !11
  %11 = sext i32 %2 to i64
  %12 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %11
  store i32 %10, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %11, i64 1
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %11, i64 2
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %0, align 8, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %20, i64 3
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %13, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %24, i64 3
  %26 = load double, ptr %25, align 8, !tbaa !15
  %27 = fcmp oeq double %22, %26
  br i1 %27, label %33, label %28

28:                                               ; preds = %9
  %29 = sext i32 %17 to i64
  %30 = getelementptr inbounds [30000 x [7 x double]], ptr @dots, i64 0, i64 %29, i64 3
  %31 = load double, ptr %30, align 8, !tbaa !15
  %32 = fcmp oeq double %22, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %28, %9
  %34 = fptosi double %22 to i32
  %35 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %11, i64 3
  store i32 %34, ptr %35, align 4, !tbaa !5
  br label %43

36:                                               ; preds = %28
  %37 = fcmp oeq double %26, %31
  %38 = getelementptr inbounds [30000 x [5 x i32]], ptr @tri, i64 0, i64 %11, i64 3
  br i1 %37, label %39, label %41

39:                                               ; preds = %36
  %40 = fptosi double %26 to i32
  store i32 %40, ptr %38, align 4, !tbaa !5
  br label %43

41:                                               ; preds = %36
  %42 = fptosi double %22 to i32
  store i32 %42, ptr %38, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %41, %39, %33
  %.sink = add nsw i32 %2, 1
  store i32 %.sink, ptr @tri_count, align 4, !tbaa !5
  ret i32 0
}

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 = { noreturn 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 = { cold nounwind }
attributes #4 = { noreturn 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 = !{!12, !6, i64 0}
!12 = !{!"base_line", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !10, i64 24, !10, i64 32}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}


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