; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/nghttp (variables)

; 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.mrb_value = type { %union.anon, i32 }
%union.anon = type { double }
%struct.RClass = type { i32, ptr, ptr, ptr, ptr, ptr }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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
declare hidden void @iv_foreach(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare { i64, i32 } @mrb_ary_new(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_mod_class_variables(ptr noundef %0, i64 %1, i32 %2) #2 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = alloca %struct.mrb_value, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.mrb_value, align 8
  %9 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %9, align 8
  %10 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %10, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call { i64, i32 } @mrb_ary_new(ptr noundef %11)
  %13 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %14 = extractvalue { i64, i32 } %12, 0
  store i64 %14, ptr %13, align 8
  %15 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %16 = extractvalue { i64, i32 } %12, 1
  store i32 %16, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  %17 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %22, %3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %30

22:                                               ; preds = %19
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.RClass, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  call void @iv_foreach(ptr noundef %23, ptr noundef %26, ptr noundef @cv_i, ptr noundef %4)
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.RClass, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  store ptr %29, ptr %7, align 8, !tbaa !5
  br label %19, !llvm.loop !16

30:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %31 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %31
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cv_i(ptr noundef, i32 noundef, i64, i32, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 = !{i64 0, i64 8, !10, i64 8, i64 4, !11}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"RClass", !12, i64 0, !12, i64 1, !12, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!14, !6, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"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.mrb_value = type { %union.anon, i32 }
%union.anon = type { double }

; Function Attrs: nounwind uwtable
declare hidden void @iv_foreach(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare { i64, i32 } @mrb_ary_new(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_mod_class_variables(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = tail call { i64, i32 } @mrb_ary_new(ptr noundef %0) #2
  %6 = extractvalue { i64, i32 } %5, 0
  %7 = extractvalue { i64, i32 } %5, 1
  store i64 %6, ptr %4, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %7, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !8
  %.not6 = icmp eq i64 %1, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %8 = inttoptr i64 %1 to ptr
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.07 = phi ptr [ %12, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %9 = getelementptr inbounds i8, ptr %.07, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  call void @iv_foreach(ptr noundef %0, ptr noundef %10, ptr noundef nonnull @cv_i, ptr noundef nonnull %4)
  %11 = getelementptr inbounds i8, ptr %.07, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.fca.0.load.pre = load i64, ptr %4, align 8
  %.fca.1.load.pre = load i32, ptr %.sroa.4.0..sroa_idx, align 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.fca.1.load = phi i32 [ %.fca.1.load.pre, %._crit_edge.loopexit ], [ %7, %3 ]
  %.fca.0.load = phi i64 [ %.fca.0.load.pre, %._crit_edge.loopexit ], [ %6, %3 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.fca.0.load, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.fca.1.load, 1
  ret { i64, i32 } %.fca.1.insert
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cv_i(ptr noundef, i32 noundef, i64, i32, ptr noundef) #0

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !12, i64 24}
!11 = !{!"RClass", !9, i64 0, !9, i64 1, !9, i64 1, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!11, !12, i64 40}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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