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

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

@.str.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [36 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 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
define dso_local { i64, i32 } @mrb_convert_type(ptr noundef %0, i64 %1, i32 %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca %struct.mrb_value, align 8
  %8 = alloca %struct.mrb_value, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.mrb_value, align 8
  %14 = alloca i32, align 4
  %15 = alloca %struct.mrb_value, align 8
  %16 = alloca %struct.mrb_value, align 8
  %17 = alloca %struct.mrb_value, align 8
  %18 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %1, ptr %18, align 8
  %19 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %2, ptr %19, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %20 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !13
  store i32 1, ptr %14, align 4
  br label %65

25:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %30 = load i64, ptr %29, align 8
  %31 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %32 = load i32, ptr %31, align 8
  %33 = call { i64, i32 } @convert_type(ptr noundef %26, i64 %30, i32 %32, ptr noundef %27, ptr noundef %28, i8 noundef zeroext 1)
  %34 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 0
  %35 = extractvalue { i64, i32 } %33, 0
  store i64 %35, ptr %34, align 8
  %36 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 1
  %37 = extractvalue { i64, i32 } %33, 1
  store i32 %37, ptr %36, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %15, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  %38 = getelementptr inbounds %struct.mrb_value, ptr %13, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp ne i32 %39, %40
  br i1 %41, label %42, label %64

42:                                               ; preds = %25
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = call ptr @mrb_exc_get(ptr noundef %44, ptr noundef @.str.11)
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = call { i64, i32 } @mrb_str_new_cstr(ptr noundef %46, ptr noundef %47)
  %49 = getelementptr inbounds { i64, i32 }, ptr %16, i32 0, i32 0
  %50 = extractvalue { i64, i32 } %48, 0
  store i64 %50, ptr %49, align 8
  %51 = getelementptr inbounds { i64, i32 }, ptr %16, i32 0, i32 1
  %52 = extractvalue { i64, i32 } %48, 1
  store i32 %52, ptr %51, align 8
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = call { i64, i32 } @mrb_str_new_cstr(ptr noundef %53, ptr noundef %54)
  %56 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 0
  %57 = extractvalue { i64, i32 } %55, 0
  store i64 %57, ptr %56, align 8
  %58 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 1
  %59 = extractvalue { i64, i32 } %55, 1
  store i32 %59, ptr %58, align 8
  %60 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %61 = load i64, ptr %60, align 8
  %62 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %63 = load i32, ptr %62, align 8
  call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %43, ptr noundef %45, ptr noundef @.str.12, i64 %61, i32 %63, ptr noundef byval(%struct.mrb_value) align 8 %16, ptr noundef byval(%struct.mrb_value) align 8 %17) #6
  unreachable

64:                                               ; preds = %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !13
  store i32 1, ptr %14, align 4
  br label %65

65:                                               ; preds = %64, %24
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  %66 = load { i64, i32 }, ptr %7, align 8
  ret { i64, i32 } %66
}

; Function Attrs: nounwind uwtable
declare hidden { i64, i32 } @convert_type(ptr noundef, i64, i32, ptr noundef, ptr noundef, i8 noundef zeroext) #2

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

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

declare { i64, i32 } @mrb_str_new_cstr(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 = { 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 #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 }
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, !10, i64 8}
!12 = !{!"mrb_value", !7, i64 0, !10, i64 8}
!13 = !{i64 0, i64 8, !14, i64 8, i64 4, !9}
!14 = !{!7, !7, i64 0}


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

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

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_convert_type(ptr noundef %0, i64 %1, i32 %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = alloca %struct.mrb_value, align 8
  %8 = alloca %struct.mrb_value, align 8
  %9 = icmp eq i32 %2, %3
  br i1 %9, label %25, label %10

10:                                               ; preds = %6
  %11 = tail call { i64, i32 } @convert_type(ptr noundef %0, i64 %1, i32 %2, ptr noundef %4, ptr noundef %5, i8 noundef zeroext 1)
  %12 = extractvalue { i64, i32 } %11, 1
  %.not = icmp eq i32 %12, %3
  br i1 %.not, label %23, label %13

13:                                               ; preds = %10
  %14 = tail call ptr @mrb_exc_get(ptr noundef %0, ptr noundef nonnull @.str.11) #3
  %15 = tail call { i64, i32 } @mrb_str_new_cstr(ptr noundef %0, ptr noundef %4) #3
  %16 = extractvalue { i64, i32 } %15, 0
  store i64 %16, ptr %7, align 8
  %17 = getelementptr inbounds i8, ptr %7, i64 8
  %18 = extractvalue { i64, i32 } %15, 1
  store i32 %18, ptr %17, align 8
  %19 = tail call { i64, i32 } @mrb_str_new_cstr(ptr noundef %0, ptr noundef %5) #3
  %20 = extractvalue { i64, i32 } %19, 0
  store i64 %20, ptr %8, align 8
  %21 = getelementptr inbounds i8, ptr %8, i64 8
  %22 = extractvalue { i64, i32 } %19, 1
  store i32 %22, ptr %21, align 8
  tail call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %0, ptr noundef %14, ptr noundef nonnull @.str.12, i64 %1, i32 %2, ptr noundef nonnull byval(%struct.mrb_value) align 8 %7, ptr noundef nonnull byval(%struct.mrb_value) align 8 %8) #4
  unreachable

23:                                               ; preds = %10
  %24 = extractvalue { i64, i32 } %11, 0
  br label %25

25:                                               ; preds = %6, %23
  %.sroa.017.0 = phi i64 [ %24, %23 ], [ %1, %6 ]
  %.sroa.3.0 = phi i32 [ %3, %23 ], [ %2, %6 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.017.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.3.0, 1
  ret { i64, i32 } %.fca.1.insert
}

; Function Attrs: nounwind uwtable
declare hidden { i64, i32 } @convert_type(ptr noundef, i64, i32, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; 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

declare { i64, i32 } @mrb_str_new_cstr(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 = { nounwind }
attributes #4 = { 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)"}


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