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

; 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 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 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: noreturn
declare void @mrb_raisef(ptr noundef, ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mrb_obj_to_sym(ptr noundef %0, i64 %1, i32 %2) #3 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.mrb_value, align 8
  %8 = alloca %struct.mrb_value, align 8
  %9 = alloca %struct.mrb_value, align 8
  %10 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  store i64 %1, ptr %10, align 8
  %11 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  store i32 %2, ptr %11, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %12 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !9
  switch i32 %13, label %14 [
    i32 16, label %51
    i32 4, label %62
  ]

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %19 = load i32, ptr %18, align 8
  %20 = call { i64, i32 } @mrb_check_string_type(ptr noundef %15, i64 %17, i32 %19)
  %21 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  %22 = extractvalue { i64, i32 } %20, 0
  store i64 %22, ptr %21, align 8
  %23 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  %24 = extractvalue { i64, i32 } %20, 1
  store i32 %24, ptr %23, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  %25 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %50

28:                                               ; preds = %14
  %29 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %50, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %35 = load i64, ptr %34, align 8
  %36 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %37 = load i32, ptr %36, align 8
  %38 = call { i64, i32 } @mrb_inspect(ptr noundef %33, i64 %35, i32 %37)
  %39 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %40 = extractvalue { i64, i32 } %38, 0
  store i64 %40, ptr %39, align 8
  %41 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %42 = extractvalue { i64, i32 } %38, 1
  store i32 %42, ptr %41, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call ptr @mrb_exc_get(ptr noundef %44, ptr noundef @.str)
  %46 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %47 = load i64, ptr %46, align 8
  %48 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %49 = load i32, ptr %48, align 8
  call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %43, ptr noundef %45, ptr noundef @.str.3, i64 %47, i32 %49) #6
  unreachable

50:                                               ; preds = %28, %14
  br label %51

51:                                               ; preds = %50, %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  %54 = load i64, ptr %53, align 8
  %55 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  %56 = load i32, ptr %55, align 8
  %57 = call { i64, i32 } @mrb_str_intern(ptr noundef %52, i64 %54, i32 %56)
  %58 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 0
  %59 = extractvalue { i64, i32 } %57, 0
  store i64 %59, ptr %58, align 8
  %60 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 1
  %61 = extractvalue { i64, i32 } %57, 1
  store i32 %61, ptr %60, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %9, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  br label %62

62:                                               ; preds = %51, %3
  %63 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !13
  store i32 %64, ptr %6, align 4, !tbaa !14
  br label %65

65:                                               ; preds = %62
  %66 = load i32, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  ret i32 %66
}

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mrb_obj_to_sym(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #2 {
  switch i32 %2, label %4 [
    i32 16, label %15
    i32 4, label %18
  ]

4:                                                ; preds = %3
  %5 = tail call { i64, i32 } @mrb_check_string_type(ptr noundef %0, i64 %1, i32 %2) #3
  %6 = extractvalue { i64, i32 } %5, 0
  %7 = extractvalue { i64, i32 } %5, 1
  %8 = icmp ne i32 %7, 0
  %9 = icmp ne i64 %6, 0
  %or.cond = select i1 %8, i1 true, i1 %9
  br i1 %or.cond, label %15, label %10

10:                                               ; preds = %4
  %11 = tail call { i64, i32 } @mrb_inspect(ptr noundef %0, i64 0, i32 0) #3
  %12 = extractvalue { i64, i32 } %11, 0
  %13 = extractvalue { i64, i32 } %11, 1
  %14 = tail call ptr @mrb_exc_get(ptr noundef %0, ptr noundef nonnull @.str) #3
  tail call void (ptr, ptr, ptr, ...) @mrb_raisef(ptr noundef %0, ptr noundef %14, ptr noundef nonnull @.str.3, i64 %12, i32 %13) #4
  unreachable

15:                                               ; preds = %4, %3
  %.sroa.10.sroa.0.0.in.in = phi i64 [ %6, %4 ], [ %1, %3 ]
  %.sroa.10.sroa.9.0 = phi i32 [ %7, %4 ], [ %2, %3 ]
  %16 = tail call { i64, i32 } @mrb_str_intern(ptr noundef %0, i64 %.sroa.10.sroa.0.0.in.in, i32 %.sroa.10.sroa.9.0) #3
  %17 = extractvalue { i64, i32 } %16, 0
  br label %18

18:                                               ; preds = %15, %3
  %.sroa.013.1.in = phi i64 [ %17, %15 ], [ %1, %3 ]
  %.sroa.013.1 = trunc i64 %.sroa.013.1.in to i32
  ret i32 %.sroa.013.1
}

declare { i64, i32 } @mrb_check_string_type(ptr noundef, i64, i32) local_unnamed_addr #1

declare { i64, i32 } @mrb_inspect(ptr noundef, i64, i32) local_unnamed_addr #1

declare { i64, i32 } @mrb_str_intern(ptr noundef, i64, i32) local_unnamed_addr #1

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