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

; 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.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 }
%struct.mrb_context = type { ptr, ptr, ptr, ptr, ptr, ptr, i8, ptr }
%struct.mrb_callinfo = type { i8, i8, i32, ptr, ptr, ptr, %union.anon }
%union.anon = type { ptr }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [28 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: nounwind uwtable
define dso_local i64 @mrb_fiber_yield(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca %struct.mrb_value, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.mrb_state, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mrb_context, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp ne ptr %14, null
  br i1 %15, label %22, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @mrb_intern_static(ptr noundef %19, ptr noundef @.str, i64 noundef 10)
  %21 = call ptr @mrb_exc_get_id(ptr noundef %18, i32 noundef %20)
  call void @mrb_raise(ptr noundef %17, ptr noundef %21, ptr noundef @.str.1) #5
  unreachable

22:                                               ; preds = %3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  call void @fiber_check_cfunc(ptr noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mrb_context, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds %struct.mrb_context, ptr %27, i32 0, i32 6
  %29 = load i8, ptr %28, align 8
  %30 = and i8 %29, -16
  %31 = or i8 %30, 1
  store i8 %31, ptr %28, align 8
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mrb_context, ptr %32, i32 0, i32 6
  %34 = load i8, ptr %33, align 8
  %35 = and i8 %34, -16
  %36 = or i8 %35, 3
  store i8 %36, ptr %33, align 8
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mrb_context, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  call void @fiber_switch_context(ptr noundef %37, ptr noundef %40)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mrb_context, ptr %41, i32 0, i32 0
  store ptr null, ptr %42, align 8, !tbaa !17
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mrb_context, ptr %43, i32 0, i32 6
  %45 = load i8, ptr %44, align 8
  %46 = lshr i8 %45, 4
  %47 = and i8 %46, 1
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %65

49:                                               ; preds = %22
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mrb_context, ptr %50, i32 0, i32 6
  %52 = load i8, ptr %51, align 8
  %53 = and i8 %52, -17
  %54 = or i8 %53, 0
  store i8 %54, ptr %51, align 8
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mrb_state, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.mrb_context, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = getelementptr inbounds %struct.mrb_callinfo, ptr %59, i32 0, i32 1
  store i8 3, ptr %60, align 1, !tbaa !20
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mrb_context, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = getelementptr inbounds %struct.mrb_callinfo, ptr %63, i32 -1
  store ptr %64, ptr %62, align 8, !tbaa !19
  br label %65

65:                                               ; preds = %49, %22
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mrb_state, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = getelementptr inbounds %struct.mrb_context, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !19
  %71 = getelementptr inbounds %struct.mrb_callinfo, ptr %70, i32 0, i32 6
  store ptr null, ptr %71, align 8, !tbaa !22
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load i64, ptr %6, align 8, !tbaa !9
  %75 = call i64 @fiber_result(ptr noundef %72, ptr noundef %73, i64 noundef %74)
  %76 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 0
  store i64 %75, ptr %76, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %77 = getelementptr inbounds %struct.mrb_value, ptr %4, i32 0, i32 0
  %78 = load i64, ptr %77, align 8
  ret i64 %78
}

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

declare ptr @mrb_exc_get_id(ptr noundef, i32 noundef) #3

declare i32 @mrb_intern_static(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @fiber_check_cfunc(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @fiber_switch_context(ptr noundef, ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync 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 = { 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 = { "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 }

!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, !6, i64 24}
!12 = !{!"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, !13, i64 184, !7, i64 296, !14, 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, !16, i64 9608}
!13 = !{!"mrb_gc", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !14, i64 40, !14, i64 44, !14, i64 48, !14, i64 52, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 80, !14, i64 88, !14, i64 92, !15, i64 96, !15, i64 96, !15, i64 96, !15, i64 96, !15, i64 96, !10, i64 104}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"mrb_context", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !15, i64 48, !6, i64 56}
!19 = !{!18, !6, i64 24}
!20 = !{!21, !7, i64 1}
!21 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !14, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32}
!22 = !{!7, !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"

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

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

7:                                                ; preds = %3
  %8 = tail call i32 @mrb_intern_static(ptr noundef nonnull %0, ptr noundef nonnull @.str, i64 noundef 10) #3
  %9 = tail call ptr @mrb_exc_get_id(ptr noundef nonnull %0, i32 noundef %8) #3
  tail call void @mrb_raise(ptr noundef nonnull %0, ptr noundef %9, ptr noundef nonnull @.str.1) #4
  unreachable

10:                                               ; preds = %3
  tail call void @fiber_check_cfunc(ptr noundef nonnull %0, ptr noundef nonnull %5)
  %11 = load ptr, ptr %5, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %11, i64 48
  %13 = load i8, ptr %12, align 8
  %14 = and i8 %13, -16
  %15 = or disjoint i8 %14, 1
  store i8 %15, ptr %12, align 8
  %16 = getelementptr inbounds i8, ptr %5, i64 48
  %17 = load i8, ptr %16, align 8
  %18 = and i8 %17, -16
  %19 = or disjoint i8 %18, 3
  store i8 %19, ptr %16, align 8
  %20 = load ptr, ptr %5, align 8, !tbaa !15
  tail call void @fiber_switch_context(ptr noundef nonnull %0, ptr noundef %20)
  store ptr null, ptr %5, align 8, !tbaa !15
  %21 = load i8, ptr %16, align 8
  %22 = and i8 %21, 16
  %.not19 = icmp eq i8 %22, 0
  br i1 %.not19, label %._crit_edge, label %23

._crit_edge:                                      ; preds = %10
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br label %32

23:                                               ; preds = %10
  %24 = and i8 %21, -17
  store i8 %24, ptr %16, align 8
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  store i8 3, ptr %28, align 1, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %5, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = getelementptr inbounds i8, ptr %30, i64 -40
  store ptr %31, ptr %29, align 8, !tbaa !17
  br label %32

32:                                               ; preds = %._crit_edge, %23
  %33 = phi ptr [ %.pre, %._crit_edge ], [ %25, %23 ]
  %34 = getelementptr inbounds i8, ptr %33, i64 24
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %35, i64 32
  store ptr null, ptr %36, align 8, !tbaa !20
  %37 = tail call i64 @fiber_result(ptr noundef nonnull %0, ptr noundef %2, i64 noundef %1)
  ret i64 %37
}

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

declare ptr @mrb_exc_get_id(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i64 @fiber_result(ptr noundef, ptr noundef, i64 noundef) 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 = { 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 }
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)"}
!5 = !{!6, !7, i64 24}
!6 = !{!"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, !10, i64 184, !8, i64 296, !12, 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, !14, i64 9608}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mrb_gc", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 80, !12, i64 88, !12, i64 92, !13, i64 96, !13, i64 96, !13, i64 96, !13, i64 96, !13, i64 96, !11, i64 104}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"mrb_context", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !12, i64 48, !13, i64 48, !7, i64 56}
!17 = !{!16, !7, i64 24}
!18 = !{!19, !8, i64 1}
!19 = !{!"", !8, i64 0, !8, i64 0, !8, i64 1, !12, i64 4, !7, i64 8, !7, i64 16, !7, i64 24, !8, i64 32}
!20 = !{!8, !8, i64 0}


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