; LLVM IR from NaokiHori/VerySimpleNSSolver :: src/tridiagonal_solver (main)

; 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.tridiagonal_solver_plan_t = type { i64, i64, i8, ptr }
%struct.tridiagonal_solver_internal_t = type { ptr, ptr }

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

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

15:                                               ; preds = %4
  %16 = load ptr, ptr @stderr, align 8, !tbaa !11
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str, i64 noundef %17, i64 noundef 3) #4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

19:                                               ; preds = %4
  %20 = call ptr @memory_alloc(i64 noundef 1, i64 noundef 32)
  %21 = load ptr, ptr %9, align 8, !tbaa !11
  store ptr %20, ptr %21, align 8, !tbaa !11
  %22 = call ptr @memory_alloc(i64 noundef 1, i64 noundef 16)
  %23 = load ptr, ptr %9, align 8, !tbaa !11
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %24, i32 0, i32 3
  store ptr %22, ptr %25, align 8, !tbaa !13
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !11
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %28, i32 0, i32 0
  store i64 %26, ptr %29, align 8, !tbaa !15
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !11
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %32, i32 0, i32 1
  store i64 %30, ptr %33, align 8, !tbaa !16
  %34 = load i8, ptr %8, align 1, !tbaa !9, !range !17, !noundef !18
  %35 = trunc i8 %34 to i1
  %36 = load ptr, ptr %9, align 8, !tbaa !11
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %37, i32 0, i32 2
  %39 = zext i1 %35 to i8
  store i8 %39, ptr %38, align 8, !tbaa !19
  %40 = load i64, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = mul i64 %40, %41
  %43 = call ptr @memory_alloc(i64 noundef %42, i64 noundef 8)
  %44 = load ptr, ptr %9, align 8, !tbaa !11
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = getelementptr inbounds %struct.tridiagonal_solver_internal_t, ptr %47, i32 0, i32 0
  store ptr %43, ptr %48, align 8, !tbaa !20
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = mul i64 %49, %50
  %52 = call ptr @memory_alloc(i64 noundef %51, i64 noundef 8)
  %53 = load ptr, ptr %9, align 8, !tbaa !11
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.tridiagonal_solver_plan_t, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.tridiagonal_solver_internal_t, ptr %56, i32 0, i32 1
  store ptr %52, ptr %57, align 8, !tbaa !22
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

58:                                               ; preds = %19, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %59 = load i32, ptr %5, align 4
  ret i32 %59
}

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

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

declare ptr @memory_alloc(i64 noundef, i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !12, i64 24}
!15 = !{!14, !6, i64 0}
!16 = !{!14, !6, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!14, !10, i64 16}
!20 = !{!21, !12, i64 0}
!21 = !{!"tridiagonal_solver_internal_t", !12, i64 0, !12, i64 8}
!22 = !{!21, !12, 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 [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tridiagonal_solver_init_plan(i64 noundef %0, i64 noundef %1, i1 noundef zeroext %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp ult i64 %0, 3
  br i1 %5, label %6, label %9

6:                                                ; preds = %4
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, i64 noundef %0, i64 noundef 3) #3
  br label %28

9:                                                ; preds = %4
  %10 = zext i1 %2 to i8
  %11 = tail call ptr @memory_alloc(i64 noundef 1, i64 noundef 32) #4
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = tail call ptr @memory_alloc(i64 noundef 1, i64 noundef 16) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %12, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  store i64 %0, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store i64 %1, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %15, i64 16
  store i8 %10, ptr %17, align 8, !tbaa !15
  %18 = mul i64 %1, %0
  %19 = tail call ptr @memory_alloc(i64 noundef %18, i64 noundef 8) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  store ptr %19, ptr %22, align 8, !tbaa !16
  %23 = tail call ptr @memory_alloc(i64 noundef %18, i64 noundef 8) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  store ptr %23, ptr %27, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %9, %6
  %.0 = phi i32 [ 1, %6 ], [ 0, %9 ]
  ret i32 %.0
}

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

declare ptr @memory_alloc(i64 noundef, i64 noundef) local_unnamed_addr #2

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 = { 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 = { "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 = { 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, !6, i64 24}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !12, i64 16}
!16 = !{!17, !6, i64 0}
!17 = !{!"tridiagonal_solver_internal_t", !6, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}


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