; LLVM IR from masyagin1998/GCI :: src/virtual-machine (virtual-machine)

; 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.VALUE = type { i8, %union.anon, i32 }
%union.anon = type { i64 }
%struct.VIRTUAL_MACHINE = type { ptr, ptr, ptr, ptr, i64, ptr, i32 }
%struct.OBJECT = type { i64, i64, [0 x %struct.PROPERTY] }
%struct.PROPERTY = type { i64, %struct.VALUE }

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

; 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 ptr @create_obj(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.VALUE, align 8
  %7 = alloca %struct.VALUE, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.VIRTUAL_MACHINE, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i64, ptr %10, i32 1
  store ptr %11, ptr %9, align 8, !tbaa !9
  %12 = load i64, ptr %10, align 8, !tbaa !13
  store i64 %12, ptr %4, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.VIRTUAL_MACHINE, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = load i64, ptr %4, align 8, !tbaa !13
  %17 = call ptr @garbage_collector_malloc_obj(ptr noundef %15, i64 noundef %16)
  store ptr %17, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %37, %1
  %19 = load i64, ptr %3, align 8, !tbaa !13
  %20 = load i64, ptr %4, align 8, !tbaa !13
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %40

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  call void @virtual_machine_stack_pop(ptr dead_on_unwind writable sret(%struct.VALUE) align 8 %6, ptr noundef %23)
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  call void @virtual_machine_stack_pop(ptr dead_on_unwind writable sret(%struct.VALUE) align 8 %7, ptr noundef %24)
  %25 = getelementptr inbounds %struct.VALUE, ptr %6, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.OBJECT, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %3, align 8, !tbaa !13
  %30 = getelementptr inbounds [0 x %struct.PROPERTY], ptr %28, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.PROPERTY, ptr %30, i32 0, i32 0
  store i64 %26, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.OBJECT, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %3, align 8, !tbaa !13
  %35 = getelementptr inbounds [0 x %struct.PROPERTY], ptr %33, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.PROPERTY, ptr %35, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 8 %7, i64 24, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  br label %37

37:                                               ; preds = %22
  %38 = load i64, ptr %3, align 8, !tbaa !13
  %39 = add i64 %38, 1
  store i64 %39, ptr %3, align 8, !tbaa !13
  br label %18, !llvm.loop !21

40:                                               ; preds = %18
  %41 = load i64, ptr %4, align 8, !tbaa !13
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.OBJECT, ptr %42, i32 0, i32 0
  store i64 %41, ptr %43, align 8, !tbaa !13
  %44 = load i64, ptr %4, align 8, !tbaa !13
  %45 = mul i64 %44, 2
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.OBJECT, ptr %46, i32 0, i32 1
  store i64 %45, ptr %47, align 8, !tbaa !13
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %48
}

declare ptr @garbage_collector_malloc_obj(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @virtual_machine_stack_pop(ptr dead_on_unwind noalias writable sret(%struct.VALUE) align 8, ptr noundef) #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) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !6, i64 8}
!10 = !{!"VIRTUAL_MACHINE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !12, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 40}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"PROPERTY", !11, i64 0, !18, i64 8}
!18 = !{!"VALUE", !7, i64 0, !7, i64 8, !12, i64 16}
!19 = !{i64 0, i64 1, !15, i64 8, i64 8, !15, i64 16, i64 4, !20}
!20 = !{!12, !12, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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.VALUE = type { i8, %union.anon, i32 }
%union.anon = type { i64 }
%struct.PROPERTY = type { i64, %struct.VALUE }

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

; Function Attrs: mustprogress 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 ptr @create_obj(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.VALUE, align 8
  %3 = alloca %struct.VALUE, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load i64, ptr %5, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = tail call ptr @garbage_collector_malloc_obj(ptr noundef %9, i64 noundef %7) #4
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = getelementptr inbounds i8, ptr %10, i64 16
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %.017 = phi i64 [ 0, %.lr.ph ], [ %17, %13 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #4
  call void @virtual_machine_stack_pop(ptr dead_on_unwind nonnull writable sret(%struct.VALUE) align 8 %2, ptr noundef %0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @virtual_machine_stack_pop(ptr dead_on_unwind nonnull writable sret(%struct.VALUE) align 8 %3, ptr noundef %0)
  %14 = load i64, ptr %11, align 8, !tbaa !14
  %15 = getelementptr inbounds [0 x %struct.PROPERTY], ptr %12, i64 0, i64 %.017
  store i64 %14, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 8 dereferenceable(24) %3, i64 24, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #4
  %17 = add nuw i64 %.017, 1
  %exitcond.not = icmp eq i64 %17, %7
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !20

._crit_edge:                                      ; preds = %13, %1
  store i64 %7, ptr %10, align 8, !tbaa !12
  %18 = shl i64 %7, 1
  %19 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 %18, ptr %19, align 8, !tbaa !12
  ret ptr %10
}

declare ptr @garbage_collector_malloc_obj(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @virtual_machine_stack_pop(ptr dead_on_unwind noalias writable sret(%struct.VALUE) align 8, ptr noundef) local_unnamed_addr #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) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !7, i64 8}
!6 = !{!"VIRTUAL_MACHINE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 40}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"PROPERTY", !10, i64 0, !17, i64 8}
!17 = !{!"VALUE", !8, i64 0, !8, i64 8, !11, i64 16}
!18 = !{i64 0, i64 1, !14, i64 8, i64 8, !14, i64 16, i64 4, !19}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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