; LLVM IR from omegaiota/DiffCloth :: external/nanogui/ext/coro (coro)

; 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.coro_stack = type { ptr, 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @coro_stack_alloc(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %2
  store i32 262144, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %11, %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.coro_stack, ptr %13, i32 0, i32 0
  store ptr null, ptr %14, align 8, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = mul i64 %16, 8
  %18 = call i64 @coro_pagesize()
  %19 = add i64 %17, %18
  %20 = sub i64 %19, 1
  %21 = call i64 @coro_pagesize()
  %22 = udiv i64 %20, %21
  %23 = call i64 @coro_pagesize()
  %24 = mul i64 %22, %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.coro_stack, ptr %25, i32 0, i32 1
  store i64 %24, ptr %26, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.coro_stack, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !14
  %30 = call i64 @coro_pagesize()
  %31 = mul i64 4, %30
  %32 = add i64 %29, %31
  store i64 %32, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %33 = load i64, ptr %6, align 8, !tbaa !15
  %34 = call ptr @mmap(ptr noundef null, i64 noundef %33, i32 noundef 7, i32 noundef 34, i32 noundef -1, i64 noundef 0) #3
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = icmp eq ptr %35, inttoptr (i64 -1 to ptr)
  br i1 %36, label %37, label %44

37:                                               ; preds = %12
  %38 = load i64, ptr %6, align 8, !tbaa !15
  %39 = call ptr @mmap(ptr noundef null, i64 noundef %38, i32 noundef 3, i32 noundef 34, i32 noundef -1, i64 noundef 0) #3
  store ptr %39, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp eq ptr %40, inttoptr (i64 -1 to ptr)
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %43, %12
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = call i64 @coro_pagesize()
  %47 = mul i64 4, %46
  %48 = call i32 @mprotect(ptr noundef %45, i64 noundef %47, i32 noundef 0) #3
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call i64 @coro_pagesize()
  %51 = mul i64 4, %50
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.coro_stack, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !11
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

56:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

; Function Attrs: nounwind uwtable
declare hidden i64 @coro_pagesize() #1

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i32 @mprotect(ptr noundef, i64 noundef, i32 noundef) #2

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 = { nounwind "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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"coro_stack", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @coro_stack_alloc(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  %spec.store.select = select i1 %.not, i32 262144, i32 %1
  store ptr null, ptr %0, align 8, !tbaa !5
  %3 = zext i32 %spec.store.select to i64
  %4 = shl nuw nsw i64 %3, 3
  %5 = tail call i64 @coro_pagesize()
  %6 = add nsw i64 %4, -1
  %7 = add i64 %6, %5
  %8 = tail call i64 @coro_pagesize()
  %9 = udiv i64 %7, %8
  %10 = tail call i64 @coro_pagesize()
  %11 = mul i64 %10, %9
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %11, ptr %12, align 8, !tbaa !11
  %13 = tail call i64 @coro_pagesize()
  %14 = shl i64 %13, 2
  %15 = add i64 %14, %11
  %16 = tail call ptr @mmap(ptr noundef null, i64 noundef %15, i32 noundef 7, i32 noundef 34, i32 noundef -1, i64 noundef 0) #2
  %17 = icmp eq ptr %16, inttoptr (i64 -1 to ptr)
  br i1 %17, label %18, label %21

18:                                               ; preds = %2
  %19 = tail call ptr @mmap(ptr noundef null, i64 noundef %15, i32 noundef 3, i32 noundef 34, i32 noundef -1, i64 noundef 0) #2
  %20 = icmp eq ptr %19, inttoptr (i64 -1 to ptr)
  br i1 %20, label %28, label %21

21:                                               ; preds = %18, %2
  %.0 = phi ptr [ %19, %18 ], [ %16, %2 ]
  %22 = tail call i64 @coro_pagesize()
  %23 = shl i64 %22, 2
  %24 = tail call i32 @mprotect(ptr noundef %.0, i64 noundef %23, i32 noundef 0) #2
  %25 = tail call i64 @coro_pagesize()
  %26 = shl i64 %25, 2
  %27 = getelementptr inbounds i8, ptr %.0, i64 %26
  store ptr %27, ptr %0, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %18, %21
  %.013 = phi i32 [ 1, %21 ], [ 0, %18 ]
  ret i32 %.013
}

; Function Attrs: nounwind uwtable
declare hidden i64 @coro_pagesize() local_unnamed_addr #0

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @mprotect(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

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 = { nounwind "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 0}
!6 = !{!"coro_stack", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}


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