; 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.RObject = type { i32, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; 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 void @mrb_obj_iv_set(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 %3, i32 %4) #1 {
  %6 = alloca %struct.mrb_value, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %struct.mrb_value, align 8
  %12 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  store i64 %3, ptr %12, align 8
  %13 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  store i32 %4, ptr %13, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 8
  %16 = lshr i32 %15, 11
  %17 = and i32 %16, 1048576
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %33

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call ptr @mrb_exc_get(ptr noundef %21, ptr noundef @.str)
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call { i64, i32 } @mrb_obj_value(ptr noundef %23)
  %25 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %26 = extractvalue { i64, i32 } %24, 0
  store i64 %26, ptr %25, align 8
  %27 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %28 = extractvalue { i64, i32 } %24, 1
  store i32 %28, ptr %27, align 8
  %29 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %30 = load i64, ptr %29, align 8
  %31 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %32 = load i32, ptr %31, align 8
  call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %20, ptr noundef %22, ptr noundef @.str.1, i64 %30, i32 %32) #6
  unreachable

33:                                               ; preds = %5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %38 = load i64, ptr %37, align 8
  %39 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %40 = load i32, ptr %39, align 8
  call void @assign_class_name(ptr noundef %34, ptr noundef %35, i32 noundef %36, i64 %38, i32 %40)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RObject, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = icmp ne ptr %43, null
  br i1 %44, label %50, label %45

45:                                               ; preds = %33
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call ptr @iv_new(ptr noundef %46)
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.RObject, ptr %48, i32 0, i32 3
  store ptr %47, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %45, %33
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.RObject, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %58 = load i64, ptr %57, align 8
  %59 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %60 = load i32, ptr %59, align 8
  call void @iv_put(ptr noundef %54, ptr noundef %55, i32 noundef %56, i64 %58, i32 %60)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mrb_write_barrier(ptr noundef %61, ptr noundef %62)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  ret void
}

; Function Attrs: noreturn
declare void @mrb_raisef(ptr noundef, ptr noundef, ptr noundef, ...) #2

declare ptr @mrb_exc_get(ptr noundef, ptr noundef) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @assign_class_name(ptr noundef, ptr noundef, i32 noundef, i64, i32) #4

; Function Attrs: nounwind uwtable
declare hidden ptr @iv_new(ptr noundef) #1

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

declare void @mrb_write_barrier(ptr noundef, ptr noundef) #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 = { noreturn "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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn }

!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, !6, i64 24}
!12 = !{!"RObject", !10, i64 0, !10, i64 1, !10, i64 1, !6, i64 8, !6, i64 16, !6, i64 24}


; 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"

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @mrb_obj_iv_set(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 %3, i32 %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %1, align 8
  %.not = icmp sgt i32 %6, -1
  br i1 %.not, label %12, label %7

7:                                                ; preds = %5
  %8 = tail call ptr @mrb_exc_get(ptr noundef %0, ptr noundef nonnull @.str) #4
  %9 = tail call { i64, i32 } @mrb_obj_value(ptr noundef nonnull %1)
  %10 = extractvalue { i64, i32 } %9, 0
  %11 = extractvalue { i64, i32 } %9, 1
  tail call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %0, ptr noundef %8, ptr noundef nonnull @.str.1, i64 %10, i32 %11) #5
  unreachable

12:                                               ; preds = %5
  tail call void @assign_class_name(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %2, i64 %3, i32 %4)
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not18 = icmp eq ptr %14, null
  br i1 %.not18, label %15, label %17

15:                                               ; preds = %12
  %16 = tail call ptr @iv_new(ptr noundef %0)
  store ptr %16, ptr %13, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %12
  %18 = phi ptr [ %16, %15 ], [ %14, %12 ]
  tail call void @iv_put(ptr noundef %0, ptr noundef %18, i32 noundef %2, i64 %3, i32 %4)
  tail call void @mrb_write_barrier(ptr noundef %0, ptr noundef nonnull %1) #4
  ret void
}

; Function Attrs: noreturn
declare void @mrb_raisef(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @mrb_exc_get(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @assign_class_name(ptr noundef, ptr noundef, i32 noundef, i64, i32) local_unnamed_addr #3

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

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

declare void @mrb_write_barrier(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 = { noreturn "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 = { 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 = { nounwind }
attributes #5 = { noreturn 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 24}
!6 = !{!"RObject", !7, i64 0, !7, i64 1, !7, i64 1, !10, i64 8, !10, i64 16, !10, i64 24}
!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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass