; LLVM IR from kylewray/nova :: src/pomdp/policies (pomdp_alpha_vectors)

; 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.nova::NovaPOMDPAlphaVectors" = type { i32, i32, i32, ptr, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

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

12:                                               ; preds = %4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %13, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %31, label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = icmp ne ptr %20, null
  br i1 %21, label %31, label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %31, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %28, %25, %22, %17, %12, %4
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str, ptr noundef @.str.1) #4
  store i32 1, ptr %5, align 4
  br label %70

34:                                               ; preds = %28
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %36, i32 0, i32 0
  store i32 %35, ptr %37, align 8, !tbaa !14
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %39, i32 0, i32 1
  store i32 %38, ptr %40, align 4, !tbaa !15
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %42, i32 0, i32 2
  store i32 %41, ptr %43, align 8, !tbaa !16
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = mul i32 %46, %49
  %51 = zext i32 %50 to i64
  %52 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %51, i64 4)
  %53 = extractvalue { i64, i1 } %52, 1
  %54 = extractvalue { i64, i1 } %52, 0
  %55 = select i1 %53, i64 -1, i64 %54
  %56 = call noalias noundef nonnull ptr @_Znam(i64 noundef %55) #5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %57, i32 0, i32 3
  store ptr %56, ptr %58, align 8, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %59, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !16
  %62 = zext i32 %61 to i64
  %63 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %62, i64 4)
  %64 = extractvalue { i64, i1 } %63, 1
  %65 = extractvalue { i64, i1 } %63, 0
  %66 = select i1 %64, i64 -1, i64 %65
  %67 = call noalias noundef nonnull ptr @_Znam(i64 noundef %66) #5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.nova::NovaPOMDPAlphaVectors", ptr %68, i32 0, i32 4
  store ptr %67, ptr %69, align 8, !tbaa !13
  store i32 0, ptr %5, align 4
  br label %70

70:                                               ; preds = %34, %31
  %71 = load i32, ptr %5, align 4
  ret i32 %71
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTSN4nova21NovaPOMDPAlphaVectorsE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 4}
!16 = !{!12, !10, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local range(i32 0, 2) i32 @pomdp_alpha_vectors_initialize(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %16, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %16

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  %13 = icmp eq i32 %1, 0
  %or.cond = or i1 %13, %12
  %14 = icmp eq i32 %2, 0
  %or.cond3 = or i1 %14, %or.cond
  %15 = icmp eq i32 %3, 0
  %or.cond5 = or i1 %15, %or.cond3
  br i1 %or.cond5, label %16, label %19

16:                                               ; preds = %9, %6, %4
  %17 = load ptr, ptr @stderr, align 8, !tbaa !12
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #3
  br label %29

19:                                               ; preds = %9
  store i32 %1, ptr %0, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %20, align 4, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %3, ptr %21, align 8, !tbaa !15
  %22 = mul i32 %3, %1
  %23 = zext i32 %22 to i64
  %24 = shl nuw nsw i64 %23, 2
  %25 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %24) #4
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = zext i32 %3 to i64
  %27 = shl nuw nsw i64 %26, 2
  %28 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %27) #4
  store ptr %28, ptr %10, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %19, %16
  %.0 = phi i32 [ 1, %16 ], [ 0, %19 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { nofree 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 = { nobuiltin allocsize(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 = { cold nounwind }
attributes #4 = { builtin allocsize(0) }

!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, !10, i64 16}
!6 = !{!"_ZTSN4nova21NovaPOMDPAlphaVectorsE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 8}


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