; LLVM IR from jrl-umi3218/mc_rtc :: 3rd-party/qhull/src/libqhull_r (qset_r)

; 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.setT = type { i32, [1 x %union.setelemT] }
%union.setelemT = type { ptr }

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #2

; Function Attrs: nounwind uwtable
define dso_local void @qh_setappend2ndlast(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %26

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.setT, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.setT, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1 x %union.setelemT], ptr %17, i64 0, i64 %22
  store ptr %23, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %14, %3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @qh_setlarger(ptr noundef %27, ptr noundef %28)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.setT, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.setT, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1 x %union.setelemT], ptr %31, i64 0, i64 %36
  store ptr %37, ptr %7, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %26, %14
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 8, !tbaa !12
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 8, !tbaa !12
  %42 = sub nsw i32 %40, 1
  store i32 %42, ptr %10, align 4, !tbaa !13
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.setT, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %10, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1 x %union.setelemT], ptr %45, i64 0, i64 %47
  store ptr %48, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %union.setelemT, ptr %49, i64 -1
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %union.setelemT, ptr %51, i32 1
  store ptr %52, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %53, i64 8, i1 false), !tbaa.struct !14
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %54, align 8, !tbaa !12
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"setT", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{i64 0, i64 8, !12}


; 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"

%union.setelemT = type { ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @qh_setappend2ndlast(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %12, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load i32, ptr %4, align 8, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1 x %union.setelemT], ptr %6, i64 0, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %5, %3
  tail call void @qh_setlarger(ptr noundef %0, ptr noundef nonnull %1)
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %13, align 8, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1 x %union.setelemT], ptr %14, i64 0, i64 %16
  %.pre = load i32, ptr %17, align 8, !tbaa !12
  br label %18

18:                                               ; preds = %12, %5
  %19 = phi i32 [ %.pre, %12 ], [ %10, %5 ]
  %.0 = phi ptr [ %17, %12 ], [ %9, %5 ]
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %.0, align 8, !tbaa !12
  %21 = add nsw i32 %19, -1
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = sext i32 %21 to i64
  %25 = getelementptr inbounds [1 x %union.setelemT], ptr %23, i64 0, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 -8
  %27 = getelementptr inbounds i8, ptr %25, i64 8
  %28 = load i64, ptr %26, align 8, !tbaa !12
  store i64 %28, ptr %25, align 8, !tbaa !12
  store ptr null, ptr %27, align 8, !tbaa !12
  store ptr %2, ptr %26, align 8, !tbaa !12
  ret void
}

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" }

!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 0}
!10 = !{!"setT", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}


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