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

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

; 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
declare dso_local ptr @mrb_proc_new_cfunc(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @mrb_proc_new_cfunc_with_env(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call ptr @mrb_proc_new_cfunc(ptr noundef %12, ptr noundef %13)
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = call ptr @env_new(ptr noundef %15, i64 noundef %16)
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.RProc, ptr %18, i32 0, i32 5
  store ptr %17, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 8
  %22 = lshr i32 %21, 11
  %23 = or i32 %22, 1024
  %24 = load i32, ptr %20, align 8
  %25 = and i32 %23, 2097151
  %26 = shl i32 %25, 11
  %27 = and i32 %24, 2047
  %28 = or i32 %27, %26
  store i32 %28, ptr %20, align 8
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  call void @mrb_field_write_barrier(ptr noundef %29, ptr noundef %30, ptr noundef %31)
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 8
  %34 = lshr i32 %33, 11
  %35 = or i32 %34, 1048576
  %36 = load i32, ptr %32, align 8
  %37 = and i32 %35, 2097151
  %38 = shl i32 %37, 11
  %39 = and i32 %36, 2047
  %40 = or i32 %39, %38
  store i32 %40, ptr %32, align 8
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = mul i64 16, %42
  %44 = call ptr @mrb_malloc(ptr noundef %41, i64 noundef %43)
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.REnv, ptr %45, i32 0, i32 3
  store ptr %44, ptr %46, align 8, !tbaa !12
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %70

49:                                               ; preds = %4
  store i32 0, ptr %11, align 4, !tbaa !15
  br label %50

50:                                               ; preds = %66, %49
  %51 = load i32, ptr %11, align 4, !tbaa !15
  %52 = sext i32 %51 to i64
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = icmp slt i64 %52, %53
  br i1 %54, label %55, label %69

55:                                               ; preds = %50
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.REnv, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = load i32, ptr %11, align 4, !tbaa !15
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.mrb_value, ptr %58, i64 %60
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !15
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.mrb_value, ptr %62, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %61, ptr align 8 %65, i64 16, i1 false), !tbaa.struct !16
  br label %66

66:                                               ; preds = %55
  %67 = load i32, ptr %11, align 4, !tbaa !15
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %11, align 4, !tbaa !15
  br label %50, !llvm.loop !17

69:                                               ; preds = %50
  br label %98

70:                                               ; preds = %4
  store i32 0, ptr %11, align 4, !tbaa !15
  br label %71

71:                                               ; preds = %94, %70
  %72 = load i32, ptr %11, align 4, !tbaa !15
  %73 = sext i32 %72 to i64
  %74 = load i64, ptr %7, align 8, !tbaa !9
  %75 = icmp slt i64 %73, %74
  br i1 %75, label %76, label %97

76:                                               ; preds = %71
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.REnv, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !12
  %81 = load i32, ptr %11, align 4, !tbaa !15
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.mrb_value, ptr %80, i64 %82
  %84 = getelementptr inbounds %struct.mrb_value, ptr %83, i32 0, i32 1
  store i32 0, ptr %84, align 8, !tbaa !19
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.REnv, ptr %85, i32 0, i32 3
  %87 = load ptr, ptr %86, align 8, !tbaa !12
  %88 = load i32, ptr %11, align 4, !tbaa !15
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.mrb_value, ptr %87, i64 %89
  %91 = getelementptr inbounds %struct.mrb_value, ptr %90, i32 0, i32 0
  store i64 0, ptr %91, align 8, !tbaa !11
  br label %92

92:                                               ; preds = %77
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %11, align 4, !tbaa !15
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %11, align 4, !tbaa !15
  br label %71, !llvm.loop !21

97:                                               ; preds = %71
  br label %98

98:                                               ; preds = %97, %69
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret ptr %99
}

; Function Attrs: nounwind uwtable
declare hidden ptr @env_new(ptr noundef, i64 noundef) #1

declare void @mrb_field_write_barrier(ptr noundef, ptr noundef, ptr noundef) #2

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

; 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"REnv", !14, i64 0, !14, i64 1, !14, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{i64 0, i64 8, !11, i64 8, i64 4, !15}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !14, i64 8}
!20 = !{!"mrb_value", !7, i64 0, !14, i64 8}
!21 = distinct !{!21, !18}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @mrb_proc_new_cfunc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @mrb_proc_new_cfunc_with_env(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef readonly %3) local_unnamed_addr #0 {
  %5 = tail call ptr @mrb_proc_new_cfunc(ptr noundef %0, ptr noundef %1)
  %6 = tail call ptr @env_new(ptr noundef %0, i64 noundef %2)
  %7 = getelementptr inbounds i8, ptr %5, i64 40
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = load i32, ptr %5, align 8
  %9 = or i32 %8, 2097152
  store i32 %9, ptr %5, align 8
  tail call void @mrb_field_write_barrier(ptr noundef %0, ptr noundef nonnull %5, ptr noundef %6) #3
  %10 = load i32, ptr %6, align 8
  %11 = or i32 %10, -2147483648
  store i32 %11, ptr %6, align 8
  %12 = shl i64 %2, 4
  %13 = tail call ptr @mrb_malloc(ptr noundef %0, i64 noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %13, ptr %14, align 8, !tbaa !8
  %.not = icmp eq ptr %3, null
  %15 = icmp sgt i64 %2, 0
  br i1 %.not, label %.preheader, label %.preheader31

.preheader31:                                     ; preds = %4
  br i1 %15, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader31
  %xtraiter = and i64 %2, 1
  %16 = icmp eq i64 %2, 1
  br i1 %16, label %.loopexit.loopexit44.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, 9223372036854775806
  br label %.lr.ph

.preheader:                                       ; preds = %4
  br i1 %15, label %.lr.ph35.preheader, label %.loopexit

.lr.ph35.preheader:                               ; preds = %.preheader
  %xtraiter45 = and i64 %2, 1
  %17 = icmp eq i64 %2, 1
  br i1 %17, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph35.preheader.new

.lr.ph35.preheader.new:                           ; preds = %.lr.ph35.preheader
  %unroll_iter47 = and i64 %2, 9223372036854775806
  br label %.lr.ph35

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %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 ]
  %18 = load ptr, ptr %14, align 8, !tbaa !8
  %19 = getelementptr inbounds %struct.mrb_value, ptr %18, i64 %indvars.iv
  %20 = getelementptr inbounds %struct.mrb_value, ptr %3, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 8 dereferenceable(16) %20, i64 16, i1 false), !tbaa.struct !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = load ptr, ptr %14, align 8, !tbaa !8
  %22 = getelementptr inbounds %struct.mrb_value, ptr %21, i64 %indvars.iv.next
  %23 = getelementptr inbounds %struct.mrb_value, ptr %3, i64 %indvars.iv.next
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 8 dereferenceable(16) %23, i64 16, i1 false), !tbaa.struct !12
  %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 %.loopexit.loopexit44.unr-lcssa, label %.lr.ph, !llvm.loop !14

.lr.ph35:                                         ; preds = %.lr.ph35, %.lr.ph35.preheader.new
  %indvars.iv38 = phi i64 [ 0, %.lr.ph35.preheader.new ], [ %indvars.iv.next39.1, %.lr.ph35 ]
  %niter48 = phi i64 [ 0, %.lr.ph35.preheader.new ], [ %niter48.next.1, %.lr.ph35 ]
  %24 = load ptr, ptr %14, align 8, !tbaa !8
  %25 = getelementptr inbounds %struct.mrb_value, ptr %24, i64 %indvars.iv38, i32 1
  store i32 0, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds %struct.mrb_value, ptr %24, i64 %indvars.iv38
  store i64 0, ptr %26, align 8, !tbaa !5
  %indvars.iv.next39 = or disjoint i64 %indvars.iv38, 1
  %27 = load ptr, ptr %14, align 8, !tbaa !8
  %28 = getelementptr inbounds %struct.mrb_value, ptr %27, i64 %indvars.iv.next39, i32 1
  store i32 0, ptr %28, align 8, !tbaa !16
  %29 = getelementptr inbounds %struct.mrb_value, ptr %27, i64 %indvars.iv.next39
  store i64 0, ptr %29, align 8, !tbaa !5
  %indvars.iv.next39.1 = add nuw nsw i64 %indvars.iv38, 2
  %niter48.next.1 = add i64 %niter48, 2
  %niter48.ncmp.1 = icmp eq i64 %niter48.next.1, %unroll_iter47
  br i1 %niter48.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph35, !llvm.loop !18

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph35, %.lr.ph35.preheader
  %indvars.iv38.unr = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next39.1, %.lr.ph35 ]
  %lcmp.mod46.not = icmp eq i64 %xtraiter45, 0
  br i1 %lcmp.mod46.not, label %.loopexit, label %.lr.ph35.epil

.lr.ph35.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %30 = load ptr, ptr %14, align 8, !tbaa !8
  %31 = getelementptr inbounds %struct.mrb_value, ptr %30, i64 %indvars.iv38.unr, i32 1
  store i32 0, ptr %31, align 8, !tbaa !16
  %32 = getelementptr inbounds %struct.mrb_value, ptr %30, i64 %indvars.iv38.unr
  store i64 0, ptr %32, align 8, !tbaa !5
  br label %.loopexit

.loopexit.loopexit44.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %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 %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit44.unr-lcssa
  %33 = load ptr, ptr %14, align 8, !tbaa !8
  %34 = getelementptr inbounds %struct.mrb_value, ptr %33, i64 %indvars.iv.unr
  %35 = getelementptr inbounds %struct.mrb_value, ptr %3, i64 %indvars.iv.unr
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %34, ptr noundef nonnull align 8 dereferenceable(16) %35, i64 16, i1 false), !tbaa.struct !12
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit44.unr-lcssa, %.lr.ph35.epil, %.loopexit.loopexit.unr-lcssa, %.preheader31, %.preheader
  ret ptr %5
}

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

declare void @mrb_field_write_barrier(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @mrb_malloc(ptr noundef, i64 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) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 24}
!9 = !{!"REnv", !10, i64 0, !10, i64 1, !10, i64 1, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{i64 0, i64 8, !5, i64 8, i64 4, !13}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 8}
!17 = !{!"mrb_value", !6, i64 0, !10, i64 8}
!18 = distinct !{!18, !15}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass