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

; 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.RHash = type { i32, 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nounwind uwtable
define dso_local void @mrb_hash_set(ptr noundef %0, i64 %1, i32 %2, i64 %3, i32 %4, ptr noundef byval(%struct.mrb_value) align 8 %5) #2 {
  %7 = alloca %struct.mrb_value, align 8
  %8 = alloca %struct.mrb_value, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.mrb_value, align 8
  %11 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  store i64 %1, ptr %11, align 8
  %12 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  store i32 %2, ptr %12, align 8
  %13 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %3, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %4, ptr %14, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 8
  call void @mrb_hash_modify(ptr noundef %15, i64 %17, i32 %19)
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %22 = load i64, ptr %21, align 8
  %23 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %24 = load i32, ptr %23, align 8
  %25 = call { i64, i32 } @ht_key(ptr noundef %20, i64 %22, i32 %24)
  %26 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  %27 = extractvalue { i64, i32 } %25, 0
  store i64 %27, ptr %26, align 8
  %28 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  %29 = extractvalue { i64, i32 } %25, 1
  store i32 %29, ptr %28, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mrb_value, ptr %7, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !10
  %33 = getelementptr inbounds %struct.RHash, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %36 = load i64, ptr %35, align 8
  %37 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %38 = load i32, ptr %37, align 8
  %39 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %40 = load i64, ptr %39, align 8
  %41 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %42 = load i32, ptr %41, align 8
  call void @ht_put(ptr noundef %30, ptr noundef %34, i64 %36, i32 %38, i64 %40, i32 %42)
  br label %43

43:                                               ; preds = %6
  %44 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = icmp ult i32 %45, 8
  br i1 %46, label %53, label %47

47:                                               ; preds = %43
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mrb_value, ptr %7, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !10
  %51 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !10
  call void @mrb_field_write_barrier(ptr noundef %48, ptr noundef %50, ptr noundef %52)
  br label %53

53:                                               ; preds = %47, %43
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !15
  %58 = icmp ult i32 %57, 8
  br i1 %58, label %65, label %59

59:                                               ; preds = %55
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mrb_value, ptr %7, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !10
  %63 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !10
  call void @mrb_field_write_barrier(ptr noundef %60, ptr noundef %62, ptr noundef %64)
  br label %65

65:                                               ; preds = %59, %55
  br label %66

66:                                               ; preds = %65
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i32 } @ht_key(ptr noundef, i64, i32) #3

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

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

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 = { inlinehint 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 #4 = { "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 #5 = { 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 32}
!14 = !{!"RHash", !12, i64 0, !12, i64 1, !12, i64 1, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!16, !12, i64 8}
!16 = !{!"mrb_value", !7, i64 0, !12, i64 8}


; 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
define dso_local void @mrb_hash_set(ptr noundef %0, i64 %1, i32 %2, i64 %3, i32 %4, ptr nocapture noundef readonly byval(%struct.mrb_value) align 8 %5) local_unnamed_addr #0 {
  tail call void @mrb_hash_modify(ptr noundef %0, i64 %1, i32 %2)
  %7 = tail call { i64, i32 } @ht_key(ptr noundef %0, i64 %3, i32 %4)
  %8 = extractvalue { i64, i32 } %7, 0
  %9 = extractvalue { i64, i32 } %7, 1
  %10 = inttoptr i64 %1 to ptr
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8
  %14 = getelementptr inbounds i8, ptr %5, i64 8
  %15 = load i32, ptr %14, align 8
  tail call void @ht_put(ptr noundef %0, ptr noundef %12, i64 %8, i32 %9, i64 %13, i32 %15)
  %16 = icmp ult i32 %9, 8
  %17 = inttoptr i64 %13 to ptr
  br i1 %16, label %20, label %18

18:                                               ; preds = %6
  %19 = inttoptr i64 %8 to ptr
  tail call void @mrb_field_write_barrier(ptr noundef %0, ptr noundef nonnull %10, ptr noundef %19) #3
  br label %20

20:                                               ; preds = %18, %6
  %21 = icmp ult i32 %15, 8
  br i1 %21, label %23, label %22

22:                                               ; preds = %20
  tail call void @mrb_field_write_barrier(ptr noundef %0, ptr noundef nonnull %10, ptr noundef %17) #3
  br label %23

23:                                               ; preds = %20, %22
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i32 } @ht_key(ptr noundef, i64, i32) local_unnamed_addr #1

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

declare void @mrb_field_write_barrier(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { inlinehint 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 = { 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 32}
!6 = !{!"RHash", !7, i64 0, !7, i64 1, !7, i64 1, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}


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