; LLVM IR from koshkin-sergey/mbOS :: Device/KMX32/Krechet1/Startup/gcc/startup_krechet1.ll_ (start)

; 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.__copy_table_t = type { ptr, ptr, i32 }
%struct.__zero_table_t = type { ptr, i32 }

@__copy_table_start__ = external constant %struct.__copy_table_t, align 8
@__copy_table_end__ = external constant %struct.__copy_table_t, align 8
@__zero_table_start__ = external constant %struct.__zero_table_t, align 8
@__zero_table_end__ = external constant %struct.__zero_table_t, align 8

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

6:                                                ; preds = %36, %0
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = icmp ult ptr %7, @__copy_table_end__
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %32, %10
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__copy_table_t, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i32 %12, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %35

18:                                               ; preds = %11
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.__copy_table_t, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.__copy_table_t, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  store i32 %25, ptr %31, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %18
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !9
  br label %11, !llvm.loop !15

35:                                               ; preds = %17
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.__copy_table_t, ptr %37, i32 1
  store ptr %38, ptr %1, align 8, !tbaa !5
  br label %6, !llvm.loop !17

39:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr @__zero_table_start__, ptr %4, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %63, %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = icmp ult ptr %41, @__zero_table_end__
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %66

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %59, %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.__zero_table_t, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !18
  %50 = icmp ult i32 %46, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %45
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %62

52:                                               ; preds = %45
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.__zero_table_t, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %55, i64 %57
  store i32 0, ptr %58, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %52
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = add i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !9
  br label %45, !llvm.loop !21

62:                                               ; preds = %51
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.__zero_table_t, ptr %64, i32 1
  store ptr %65, ptr %4, align 8, !tbaa !5
  br label %40, !llvm.loop !22

66:                                               ; preds = %43
  %67 = call i32 @main()
  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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @main() #2

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 = { "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 = !{!"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 16}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !10, i64 8}
!19 = !{!"", !6, i64 0, !10, i64 8}
!20 = !{!19, !6, i64 0}
!21 = distinct !{!21, !16}
!22 = distinct !{!22, !16}


; 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.__copy_table_t = type { ptr, ptr, i32 }
%struct.__zero_table_t = type { ptr, i32 }

@__copy_table_start__ = external constant %struct.__copy_table_t, align 8
@__copy_table_end__ = external constant %struct.__copy_table_t, align 8
@__zero_table_start__ = external constant %struct.__zero_table_t, align 8
@__zero_table_end__ = external constant %struct.__zero_table_t, align 8

; Function Attrs: nounwind uwtable
define dso_local void @__start() local_unnamed_addr #0 {
  %1 = icmp ult ptr @__copy_table_start__, @__copy_table_end__
  br i1 %1, label %.preheader19, label %.preheader18

.preheader19:                                     ; preds = %0, %._crit_edge
  %.01721 = phi ptr [ %21, %._crit_edge ], [ @__copy_table_start__, %0 ]
  %2 = getelementptr inbounds i8, ptr %.01721, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader19
  %4 = load ptr, ptr %.01721, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %.01721, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %wide.trip.count = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 8
  %7 = ptrtoint ptr %6 to i64
  %8 = ptrtoint ptr %4 to i64
  %9 = sub i64 %7, %8
  %diff.check = icmp ult i64 %9, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %10 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.prol
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.prol
  store i32 %11, ptr %12, align 4, !tbaa !13
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !14

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %13 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %14 = icmp ugt i64 %13, -4
  br i1 %14, label %._crit_edge, label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds i32, ptr %4, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %wide.load = load <4 x i32>, ptr %15, align 4, !tbaa !13
  %wide.load32 = load <4 x i32>, ptr %16, align 4, !tbaa !13
  %17 = getelementptr inbounds i32, ptr %6, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <4 x i32> %wide.load, ptr %17, align 4, !tbaa !13
  store <4 x i32> %wide.load32, ptr %18, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

.preheader18:                                     ; preds = %._crit_edge, %0
  %20 = icmp ult ptr @__zero_table_start__, @__zero_table_end__
  br i1 %20, label %.preheader, label %._crit_edge26

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader19
  %21 = getelementptr inbounds i8, ptr %.01721, i64 24
  %22 = icmp ult ptr %21, @__copy_table_end__
  br i1 %22, label %.preheader19, label %.preheader18, !llvm.loop !20

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %23 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  store i32 %24, ptr %25, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.next
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next
  store i32 %27, ptr %28, align 4, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %29 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.next.1
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next.1
  store i32 %30, ptr %31, align 4, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %32 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.next.2
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next.2
  store i32 %33, ptr %34, align 4, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !21

.preheader:                                       ; preds = %.preheader18, %._crit_edge24
  %.01525 = phi ptr [ %41, %._crit_edge24 ], [ @__zero_table_start__, %.preheader18 ]
  %35 = getelementptr inbounds i8, ptr %.01525, i64 8
  %36 = load i32, ptr %35, align 8, !tbaa !22
  %.not27 = icmp eq i32 %36, 0
  br i1 %.not27, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %.preheader
  %37 = load ptr, ptr %.01525, align 8, !tbaa !24
  %38 = zext i32 %36 to i64
  %39 = shl nuw nsw i64 %38, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %37, i8 0, i64 %39, i1 false), !tbaa !13
  br label %._crit_edge24

._crit_edge26:                                    ; preds = %._crit_edge24, %.preheader18
  %40 = tail call i32 @main() #3
  ret void

._crit_edge24:                                    ; preds = %.lr.ph23, %.preheader
  %41 = getelementptr inbounds i8, ptr %.01525, i64 16
  %42 = icmp ult ptr %41, @__zero_table_end__
  br i1 %42, label %.preheader, label %._crit_edge26, !llvm.loop !25
}

declare i32 @main() local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17, !18}
!22 = !{!23, !10, i64 8}
!23 = !{!"", !7, i64 0, !10, i64 8}
!24 = !{!23, !7, i64 0}
!25 = distinct !{!25, !17}


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