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

; 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.23 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.25 = 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

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
declare dso_local { i64, i32 } @mrb_to_int(ptr noundef, i64, i32) #4

declare { i64, i32 } @mrb_flo_to_fixnum(ptr noundef, i64, i32) #2

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @mrb_convert_to_integer(ptr noundef %0, i64 %1, i32 %2, i64 noundef %3) #4 {
  %5 = alloca %struct.mrb_value, align 8
  %6 = alloca %struct.mrb_value, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.mrb_value, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.mrb_value, align 8
  %12 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  store i64 %1, ptr %12, align 8
  %13 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  store i32 %2, ptr %13, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %14 = getelementptr inbounds %struct.mrb_value, ptr %6, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %29

17:                                               ; preds = %4
  %18 = getelementptr inbounds %struct.mrb_value, ptr %6, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %29, label %21

21:                                               ; preds = %17
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %89

25:                                               ; preds = %21
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call ptr @mrb_exc_get(ptr noundef %27, ptr noundef @.str.11)
  call void @mrb_raise(ptr noundef %26, ptr noundef %28, ptr noundef @.str.23) #6
  unreachable

29:                                               ; preds = %17, %4
  %30 = getelementptr inbounds %struct.mrb_value, ptr %6, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !11
  switch i32 %31, label %65 [
    i32 6, label %32
    i32 3, label %47
    i32 16, label %52
  ]

32:                                               ; preds = %29
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %89

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %39 = load i64, ptr %38, align 8
  %40 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %41 = load i32, ptr %40, align 8
  %42 = call { i64, i32 } @mrb_flo_to_fixnum(ptr noundef %37, i64 %39, i32 %41)
  %43 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %44 = extractvalue { i64, i32 } %42, 0
  store i64 %44, ptr %43, align 8
  %45 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %46 = extractvalue { i64, i32 } %42, 1
  store i32 %46, ptr %45, align 8
  store i32 1, ptr %10, align 4
  br label %104

47:                                               ; preds = %29
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  br label %89

51:                                               ; preds = %47
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !15
  store i32 1, ptr %10, align 4
  br label %104

52:                                               ; preds = %29
  br label %53

53:                                               ; preds = %87, %52
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %57 = load i64, ptr %56, align 8
  %58 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %59 = load i32, ptr %58, align 8
  %60 = call { i64, i32 } @mrb_str_to_inum(ptr noundef %54, i64 %57, i32 %59, i64 noundef %55, i8 noundef zeroext 1)
  %61 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %62 = extractvalue { i64, i32 } %60, 0
  store i64 %62, ptr %61, align 8
  %63 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %64 = extractvalue { i64, i32 } %60, 1
  store i32 %64, ptr %63, align 8
  store i32 1, ptr %10, align 4
  br label %104

65:                                               ; preds = %29
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %93

69:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %72 = load i64, ptr %71, align 8
  %73 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %74 = load i32, ptr %73, align 8
  %75 = call { i64, i32 } @mrb_check_string_type(ptr noundef %70, i64 %72, i32 %74)
  %76 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %77 = extractvalue { i64, i32 } %75, 0
  store i64 %77, ptr %76, align 8
  %78 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %79 = extractvalue { i64, i32 } %75, 1
  store i32 %79, ptr %78, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %11, i64 16, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  %80 = getelementptr inbounds %struct.mrb_value, ptr %9, i32 0, i32 1
  %81 = load i32, ptr %80, align 8, !tbaa !11
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %87

83:                                               ; preds = %69
  %84 = getelementptr inbounds %struct.mrb_value, ptr %9, i32 0, i32 0
  %85 = load i64, ptr %84, align 8, !tbaa !14
  %86 = icmp ne i64 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %83, %69
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !15
  br label %53

88:                                               ; preds = %83
  br label %89

89:                                               ; preds = %88, %50, %35, %24
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = call ptr @mrb_exc_get(ptr noundef %91, ptr noundef @.str.24)
  call void @mrb_raise(ptr noundef %90, ptr noundef %92, ptr noundef @.str.25) #6
  unreachable

93:                                               ; preds = %66
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  %96 = load i64, ptr %95, align 8
  %97 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  %98 = load i32, ptr %97, align 8
  %99 = call { i64, i32 } @mrb_to_int(ptr noundef %94, i64 %96, i32 %98)
  %100 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  %101 = extractvalue { i64, i32 } %99, 0
  store i64 %101, ptr %100, align 8
  %102 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  %103 = extractvalue { i64, i32 } %99, 1
  store i32 %103, ptr %102, align 8
  store i32 1, ptr %10, align 4
  br label %104

104:                                              ; preds = %93, %53, %51, %36
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  %105 = load { i64, i32 }, ptr %5, align 8
  ret { i64, i32 } %105
}

declare { i64, i32 } @mrb_str_to_inum(ptr noundef, i64, i32, i64 noundef, i8 noundef zeroext) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"mrb_value", !7, i64 0, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{i64 0, i64 8, !14, i64 8, i64 4, !16}
!16 = !{!13, !13, 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.23 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [36 x i8], align 1

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

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

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

declare { i64, i32 } @mrb_flo_to_fixnum(ptr noundef, i64, i32) local_unnamed_addr #0

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

7:                                                ; preds = %4
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %8, label %28

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

10:                                               ; preds = %4
  switch i32 %2, label %21 [
    i32 6, label %11
    i32 3, label %16
    i32 16, label %17
  ]

11:                                               ; preds = %10
  %.not32 = icmp eq i64 %3, 0
  br i1 %.not32, label %12, label %28

12:                                               ; preds = %11
  %13 = tail call { i64, i32 } @mrb_flo_to_fixnum(ptr noundef %0, i64 %1, i32 6) #3
  %14 = extractvalue { i64, i32 } %13, 0
  %15 = extractvalue { i64, i32 } %13, 1
  br label %34

16:                                               ; preds = %10
  %.not31 = icmp eq i64 %3, 0
  br i1 %.not31, label %34, label %28

17:                                               ; preds = %22, %10
  %.sroa.019.0 = phi i64 [ %1, %10 ], [ %24, %22 ]
  %.sroa.8.0 = phi i32 [ %2, %10 ], [ %25, %22 ]
  %18 = tail call { i64, i32 } @mrb_str_to_inum(ptr noundef %0, i64 %.sroa.019.0, i32 %.sroa.8.0, i64 noundef %3, i8 noundef zeroext 1) #3
  %19 = extractvalue { i64, i32 } %18, 0
  %20 = extractvalue { i64, i32 } %18, 1
  br label %34

21:                                               ; preds = %10
  %.not33 = icmp eq i64 %3, 0
  br i1 %.not33, label %30, label %22

22:                                               ; preds = %21
  %23 = tail call { i64, i32 } @mrb_check_string_type(ptr noundef %0, i64 %1, i32 %2)
  %24 = extractvalue { i64, i32 } %23, 0
  %25 = extractvalue { i64, i32 } %23, 1
  %26 = icmp ne i32 %25, 0
  %27 = icmp ne i64 %24, 0
  %or.cond5 = select i1 %26, i1 true, i1 %27
  br i1 %or.cond5, label %17, label %28

28:                                               ; preds = %22, %16, %11, %7
  %29 = tail call ptr @mrb_exc_get(ptr noundef %0, ptr noundef nonnull @.str.24) #3
  tail call void @mrb_raise(ptr noundef %0, ptr noundef %29, ptr noundef nonnull @.str.25) #4
  unreachable

30:                                               ; preds = %21
  %31 = tail call { i64, i32 } @mrb_to_int(ptr noundef %0, i64 %1, i32 %2)
  %32 = extractvalue { i64, i32 } %31, 0
  %33 = extractvalue { i64, i32 } %31, 1
  br label %34

34:                                               ; preds = %16, %30, %17, %12
  %.sroa.029.0 = phi i64 [ %19, %17 ], [ %32, %30 ], [ %14, %12 ], [ %1, %16 ]
  %.sroa.530.0 = phi i32 [ %20, %17 ], [ %33, %30 ], [ %15, %12 ], [ 3, %16 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.029.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.530.0, 1
  ret { i64, i32 } %.fca.1.insert
}

declare { i64, i32 } @mrb_str_to_inum(ptr noundef, i64, i32, i64 noundef, i8 noundef zeroext) local_unnamed_addr #0

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

attributes #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 = { 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 = { 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: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass