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

; 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.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [5 x i8], align 1

; 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) #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @mrb_convert_type(ptr noundef, i64, i32, i32 noundef, ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_Float(ptr noundef %0, i64 %1, i32 %2) #1 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = alloca %struct.mrb_value, align 8
  %6 = alloca ptr, align 8
  %7 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %7, align 8
  %8 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %8, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %20

12:                                               ; preds = %3
  %13 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call ptr @mrb_exc_get(ptr noundef %18, ptr noundef @.str.11)
  call void @mrb_raise(ptr noundef %17, ptr noundef %19, ptr noundef @.str.26) #5
  unreachable

20:                                               ; preds = %12, %3
  %21 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !9
  switch i32 %22, label %47 [
    i32 3, label %23
    i32 6, label %33
    i32 16, label %34
  ]

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mrb_value, ptr %5, i32 0, i32 0
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = sitofp i64 %26 to double
  %28 = call { i64, i32 } @mrb_float_value(ptr noundef %24, double noundef %27)
  %29 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %30 = extractvalue { i64, i32 } %28, 0
  store i64 %30, ptr %29, align 8
  %31 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %32 = extractvalue { i64, i32 } %28, 1
  store i32 %32, ptr %31, align 8
  br label %58

33:                                               ; preds = %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !13
  br label %58

34:                                               ; preds = %20
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %38 = load i64, ptr %37, align 8
  %39 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %40 = load i32, ptr %39, align 8
  %41 = call double @mrb_str_to_dbl(ptr noundef %36, i64 %38, i32 %40, i8 noundef zeroext 1)
  %42 = call { i64, i32 } @mrb_float_value(ptr noundef %35, double noundef %41)
  %43 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %44 = extractvalue { i64, i32 } %42, 0
  store i64 %44, ptr %43, align 8
  %45 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %46 = extractvalue { i64, i32 } %42, 1
  store i32 %46, ptr %45, align 8
  br label %58

47:                                               ; preds = %20
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %50 = load i64, ptr %49, align 8
  %51 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %52 = load i32, ptr %51, align 8
  %53 = call { i64, i32 } @mrb_convert_type(ptr noundef %48, i64 %50, i32 %52, i32 noundef 6, ptr noundef @.str.27, ptr noundef @.str.28)
  %54 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %55 = extractvalue { i64, i32 } %53, 0
  store i64 %55, ptr %54, align 8
  %56 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %57 = extractvalue { i64, i32 } %53, 1
  store i32 %57, ptr %56, align 8
  br label %58

58:                                               ; preds = %47, %34, %33, %23
  %59 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %59
}

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

declare double @mrb_str_to_dbl(ptr noundef, i64, i32, i8 noundef zeroext) #2

attributes #0 = { nocallback nofree 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 = { 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 = { 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 = { 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, !11, i64 8}
!10 = !{!"mrb_value", !7, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{i64 0, i64 8, !12, i64 8, i64 4, !14}
!14 = !{!11, !11, 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"

@.str.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @mrb_convert_type(ptr noundef, i64, i32, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: noreturn
declare void @mrb_raise(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_Float(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %4 = icmp ne i32 %2, 0
  %5 = icmp ne i64 %1, 0
  %or.cond = select i1 %4, i1 true, i1 %5
  br i1 %or.cond, label %8, label %6

6:                                                ; preds = %3
  %7 = tail call ptr @mrb_exc_get(ptr noundef %0, ptr noundef nonnull @.str.11) #4
  tail call void @mrb_raise(ptr noundef %0, ptr noundef %7, ptr noundef nonnull @.str.26) #5
  unreachable

8:                                                ; preds = %3
  switch i32 %2, label %19 [
    i32 3, label %9
    i32 6, label %23
    i32 16, label %14
  ]

9:                                                ; preds = %8
  %10 = sitofp i64 %1 to double
  %11 = tail call { i64, i32 } @mrb_float_value(ptr noundef %0, double noundef %10)
  %12 = extractvalue { i64, i32 } %11, 0
  %13 = extractvalue { i64, i32 } %11, 1
  br label %23

14:                                               ; preds = %8
  %15 = tail call double @mrb_str_to_dbl(ptr noundef %0, i64 %1, i32 16, i8 noundef zeroext 1) #4
  %16 = tail call { i64, i32 } @mrb_float_value(ptr noundef %0, double noundef %15)
  %17 = extractvalue { i64, i32 } %16, 0
  %18 = extractvalue { i64, i32 } %16, 1
  br label %23

19:                                               ; preds = %8
  %20 = tail call { i64, i32 } @mrb_convert_type(ptr noundef %0, i64 %1, i32 %2, i32 noundef 6, ptr noundef nonnull @.str.27, ptr noundef nonnull @.str.28)
  %21 = extractvalue { i64, i32 } %20, 0
  %22 = extractvalue { i64, i32 } %20, 1
  br label %23

23:                                               ; preds = %8, %19, %14, %9
  %.sroa.014.0 = phi i64 [ %21, %19 ], [ %17, %14 ], [ %12, %9 ], [ %1, %8 ]
  %.sroa.5.0 = phi i32 [ %22, %19 ], [ %18, %14 ], [ %13, %9 ], [ %2, %8 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.014.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.5.0, 1
  ret { i64, i32 } %.fca.1.insert
}

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

declare double @mrb_str_to_dbl(ptr noundef, i64, i32, i8 noundef zeroext) local_unnamed_addr #1

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 = { 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 = { 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)"}


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