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

; 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.mrb_state = type { ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.mrb_gc, i32, ptr, [256 x i32], i64, [8 x i8], ptr, ptr, ptr, ptr, ptr, ptr, i16, i16 }
%struct.mrb_gc = type { ptr, ptr, ptr, i64, ptr, i32, i32, i32, i32, ptr, ptr, i64, i64, i32, i32, i8, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local void @mrb_print_backtrace(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.mrb_value, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.mrb_value, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.mrb_state, ptr %6, i32 0, i32 7
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %48

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

26:                                               ; preds = %11
  %27 = getelementptr inbounds %struct.mrb_value, ptr %3, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 1, ptr %4, align 4
  br label %48

31:                                               ; preds = %26, %11
  %32 = getelementptr inbounds %struct.mrb_value, ptr %3, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !18
  %34 = icmp eq i32 %33, 14
  br i1 %34, label %35, label %41

35:                                               ; preds = %31
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds { i64, i32 }, ptr %3, i32 0, i32 0
  %38 = load i64, ptr %37, align 8
  %39 = getelementptr inbounds { i64, i32 }, ptr %3, i32 0, i32 1
  %40 = load i32, ptr %39, align 8
  call void @print_backtrace(ptr noundef %36, i64 %38, i32 %40)
  br label %47

41:                                               ; preds = %31
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds { i64, i32 }, ptr %3, i32 0, i32 0
  %44 = load i64, ptr %43, align 8
  %45 = getelementptr inbounds { i64, i32 }, ptr %3, i32 0, i32 1
  %46 = load i32, ptr %45, align 8
  call void @print_packed_backtrace(ptr noundef %42, i64 %44, i32 %46)
  br label %47

47:                                               ; preds = %41, %35
  store i32 0, ptr %4, align 4
  br label %48

48:                                               ; preds = %47, %30, %10
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  %49 = load i32, ptr %4, align 4
  switch i32 %49, label %51 [
    i32 0, label %50
    i32 1, label %50
  ]

50:                                               ; preds = %48, %48
  ret void

51:                                               ; preds = %48
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

declare i32 @mrb_intern_static(ptr noundef, ptr noundef, i64 noundef) #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) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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 = { nocallback nofree nosync 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 56}
!10 = !{!"mrb_state", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !12, i64 200, !11, i64 312, !6, i64 320, !7, i64 328, !13, i64 1352, !7, i64 1360, !6, i64 1368, !6, i64 1376, !6, i64 1384, !6, i64 1392, !6, i64 1400, !6, i64 1408, !14, i64 1416, !14, i64 1418}
!11 = !{!"int", !7, i64 0}
!12 = !{!"mrb_gc", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !13, i64 72, !13, i64 80, !11, i64 88, !11, i64 92, !7, i64 96, !7, i64 96, !7, i64 96, !7, i64 96, !7, i64 96, !13, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{i64 0, i64 8, !16, i64 8, i64 4, !17}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"mrb_value", !7, i64 0, !11, i64 8}


; 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

; Function Attrs: nounwind uwtable
define dso_local void @mrb_print_backtrace(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %15, label %4

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

11:                                               ; preds = %4
  %12 = icmp eq i32 %8, 14
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  tail call void @print_backtrace(ptr noundef nonnull %0, i64 %7, i32 14)
  br label %15

14:                                               ; preds = %11
  tail call void @print_packed_backtrace(ptr noundef nonnull %0, i64 %7, i32 %8)
  br label %15

15:                                               ; preds = %13, %14, %4, %1
  ret void
}

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

declare i32 @mrb_intern_static(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

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 = { 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, !7, i64 56}
!6 = !{!"mrb_state", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !11, i64 200, !10, i64 312, !7, i64 320, !8, i64 328, !12, i64 1352, !8, i64 1360, !7, i64 1368, !7, i64 1376, !7, i64 1384, !7, i64 1392, !7, i64 1400, !7, i64 1408, !13, i64 1416, !13, i64 1418}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"mrb_gc", !7, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 64, !12, i64 72, !12, i64 80, !10, i64 88, !10, i64 92, !8, i64 96, !8, i64 96, !8, i64 96, !8, i64 96, !8, i64 96, !12, i64 104}
!12 = !{!"long", !8, i64 0}
!13 = !{!"short", !8, i64 0}


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