; LLVM IR from h2o/h2o :: deps/mruby/mrbgems/mruby-error/src (exception)

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

; 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

declare i64 @mrb_protect_error(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @protect_body(ptr noundef, ptr noundef) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mrb_gc_arena_save(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mrb_gc_arena_restore(ptr noundef, i32 noundef) #4

declare void @mrb_gc_protect(ptr noundef, i64) #2

; Function Attrs: noreturn
declare void @mrb_exc_raise(ptr noundef, i64) #5

; Function Attrs: nounwind uwtable
define dso_local i64 @mrb_rescue_exceptions(ptr noundef %0, ptr noundef %1, i64 %2, ptr noundef %3, i64 %4, i64 noundef %5, ptr noundef %6) #3 {
  %8 = alloca %struct.mrb_value, align 8
  %9 = alloca %struct.mrb_value, align 8
  %10 = alloca %struct.mrb_value, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca %struct.protect_data, align 8
  %18 = alloca i8, align 1
  %19 = alloca i8, align 1
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca %struct.mrb_value, align 8
  %23 = getelementptr inbounds %struct.mrb_value, ptr %9, i32 0, i32 0
  store i64 %2, ptr %23, align 8
  %24 = getelementptr inbounds %struct.mrb_value, ptr %10, i32 0, i32 0
  store i64 %4, ptr %24, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i64 %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = call i32 @mrb_gc_arena_save(ptr noundef %25)
  store i32 %26, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #6
  %27 = getelementptr inbounds %struct.protect_data, ptr %17, i32 0, i32 0
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %28, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.protect_data, ptr %17, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 8 %9, i64 8, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.start.p0(i64 1, ptr %18) #6
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = call i64 @mrb_protect_error(ptr noundef %30, ptr noundef @protect_body, ptr noundef %17, ptr noundef %18)
  %32 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  store i64 %31, ptr %32, align 8
  %33 = load i8, ptr %18, align 1, !tbaa !17, !range !19, !noundef !20
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %77

35:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #6
  store i8 0, ptr %19, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  store i64 0, ptr %20, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %52, %35
  %37 = load i64, ptr %20, align 8, !tbaa !9
  %38 = load i64, ptr %14, align 8, !tbaa !9
  %39 = icmp slt i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 2, ptr %21, align 4
  br label %55

41:                                               ; preds = %36
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = load i64, ptr %20, align 8, !tbaa !9
  %45 = getelementptr inbounds ptr, ptr %43, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  %48 = load i64, ptr %47, align 8
  %49 = call zeroext i1 @mrb_obj_is_kind_of(ptr noundef %42, i64 %48, ptr noundef %46)
  br i1 %49, label %50, label %51

50:                                               ; preds = %41
  store i8 1, ptr %19, align 1, !tbaa !17
  store i32 2, ptr %21, align 4
  br label %55

51:                                               ; preds = %41
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %20, align 8, !tbaa !9
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %20, align 8, !tbaa !9
  br label %36, !llvm.loop !21

55:                                               ; preds = %50, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  br label %56

56:                                               ; preds = %55
  %57 = load i8, ptr %19, align 1, !tbaa !17, !range !19, !noundef !20
  %58 = trunc i8 %57 to i1
  br i1 %58, label %63, label %59

59:                                               ; preds = %56
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  %62 = load i64, ptr %61, align 8
  call void @mrb_exc_raise(ptr noundef %60, i64 %62) #7
  unreachable

63:                                               ; preds = %56
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mrb_state, ptr %64, i32 0, i32 6
  store ptr null, ptr %65, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #6
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mrb_value, ptr %10, i32 0, i32 0
  %69 = load i64, ptr %68, align 8
  %70 = call i64 %66(ptr noundef %67, i64 %69)
  %71 = getelementptr inbounds %struct.mrb_value, ptr %22, i32 0, i32 0
  store i64 %70, ptr %71, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %22, i64 8, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load i32, ptr %16, align 4, !tbaa !11
  call void @mrb_gc_arena_restore(ptr noundef %72, i32 noundef %73)
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  %76 = load i64, ptr %75, align 8
  call void @mrb_gc_protect(ptr noundef %74, i64 %76)
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #6
  br label %77

77:                                               ; preds = %63, %7
  store i32 1, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  %78 = getelementptr inbounds %struct.mrb_value, ptr %8, i32 0, i32 0
  %79 = load i64, ptr %78, align 8
  ret i64 %79
}

declare zeroext i1 @mrb_obj_is_kind_of(ptr noundef, i64, ptr noundef) #2

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 = { 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 = { 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 "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 #6 = { nounwind }
attributes #7 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"protect_data", !6, i64 0, !15, i64 8}
!15 = !{!"mrb_value", !10, i64 0}
!16 = !{i64 0, i64 8, !9}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!24, !6, i64 48}
!24 = !{!"mrb_state", !6, i64 0, !6, 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, !25, i64 184, !7, i64 296, !12, i64 8488, !6, i64 8496, !6, i64 8504, !6, i64 8512, !7, i64 8520, !10, i64 9544, !7, i64 9552, !6, i64 9560, !6, i64 9568, !6, i64 9576, !6, i64 9584, !6, i64 9592, !6, i64 9600, !26, i64 9608}
!25 = !{!"mrb_gc", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 80, !12, i64 88, !12, i64 92, !18, i64 96, !18, i64 96, !18, i64 96, !18, i64 96, !18, i64 96, !10, i64 104}
!26 = !{!"short", !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.protect_data = type { ptr, %struct.mrb_value }
%struct.mrb_value = type { i64 }

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

declare i64 @mrb_protect_error(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @protect_body(ptr noundef, ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mrb_gc_arena_save(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mrb_gc_arena_restore(ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @mrb_gc_protect(ptr noundef, i64) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @mrb_exc_raise(ptr noundef, i64) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i64 @mrb_rescue_exceptions(ptr noundef %0, ptr noundef %1, i64 %2, ptr nocapture noundef readonly %3, i64 %4, i64 noundef %5, ptr nocapture noundef readonly %6) local_unnamed_addr #2 {
  %8 = alloca %struct.protect_data, align 8
  %9 = alloca i8, align 1
  %10 = tail call i32 @mrb_gc_arena_save(ptr noundef %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #5
  store ptr %1, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 %2, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %9) #5
  %12 = call i64 @mrb_protect_error(ptr noundef %0, ptr noundef nonnull @protect_body, ptr noundef nonnull %8, ptr noundef nonnull %9) #5
  %13 = load i8, ptr %9, align 1, !tbaa !13, !range !15, !noundef !16
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %.preheader, label %24

.preheader:                                       ; preds = %7
  %15 = icmp sgt i64 %5, 0
  br i1 %15, label %.lr.ph, label %.critedge

16:                                               ; preds = %.lr.ph
  %17 = add nuw nsw i64 %.023, 1
  %exitcond.not = icmp eq i64 %17, %5
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !17

.lr.ph:                                           ; preds = %.preheader, %16
  %.023 = phi i64 [ %17, %16 ], [ 0, %.preheader ]
  %18 = getelementptr inbounds ptr, ptr %6, i64 %.023
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = call zeroext i1 @mrb_obj_is_kind_of(ptr noundef %0, i64 %12, ptr noundef %19) #5
  br i1 %20, label %21, label %16

.critedge:                                        ; preds = %16, %.preheader
  call void @mrb_exc_raise(ptr noundef %0, i64 %12) #6
  unreachable

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr null, ptr %22, align 8, !tbaa !20
  %23 = call i64 %3(ptr noundef %0, i64 %4) #5
  call void @mrb_gc_arena_restore(ptr noundef %0, i32 noundef %10)
  call void @mrb_gc_protect(ptr noundef %0, i64 %23) #5
  br label %24

24:                                               ; preds = %21, %7
  %.sroa.018.0 = phi i64 [ %23, %21 ], [ %12, %7 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  ret i64 %.sroa.018.0
}

declare zeroext i1 @mrb_obj_is_kind_of(ptr noundef, i64, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"protect_data", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mrb_value", !11, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !7, i64 48}
!21 = !{!"mrb_state", !7, i64 0, !7, 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, !22, i64 184, !8, i64 296, !23, i64 8488, !7, i64 8496, !7, i64 8504, !7, i64 8512, !8, i64 8520, !11, i64 9544, !8, i64 9552, !7, i64 9560, !7, i64 9568, !7, i64 9576, !7, i64 9584, !7, i64 9592, !7, i64 9600, !24, i64 9608}
!22 = !{!"mrb_gc", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !23, i64 40, !23, i64 44, !23, i64 48, !23, i64 52, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 80, !23, i64 88, !23, i64 92, !14, i64 96, !14, i64 96, !14, i64 96, !14, i64 96, !14, i64 96, !11, i64 104}
!23 = !{!"int", !8, i64 0}
!24 = !{!"short", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass