; LLVM IR from harharkh/sb_desc :: src (vector)

; 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.sb_vec = type { i64, ptr, i8 }

@sb_error_log = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sb_vec_malloc(i64 noundef, i8 noundef signext) #0

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

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

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

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

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

13:                                               ; preds = %1
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 2
  br i1 %15, label %16, label %35

16:                                               ; preds = %13
  %17 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %23

21:                                               ; preds = %16
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %19
  %24 = phi ptr [ %20, %19 ], [ %22, %21 ]
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.48) #4
  %26 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %32

30:                                               ; preds = %23
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %30, %28
  %33 = phi ptr [ %29, %28 ], [ %31, %30 ]
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.1) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %115

35:                                               ; preds = %13
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load i64, ptr %5, align 8, !tbaa !11
  %39 = load i8, ptr %6, align 1, !tbaa !13
  %40 = call ptr @sb_vec_malloc(i64 noundef %38, i8 noundef signext %39)
  store ptr %40, ptr %8, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %37
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %63, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %51

49:                                               ; preds = %44
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %47
  %52 = phi ptr [ %48, %47 ], [ %50, %49 ]
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.49) #4
  %54 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %60

58:                                               ; preds = %51
  %59 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %58, %56
  %61 = phi ptr [ %57, %56 ], [ %59, %58 ]
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.1) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %114

63:                                               ; preds = %41
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.sb_vec, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  store ptr %68, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %106, %65
  %70 = load i64, ptr %10, align 8, !tbaa !11
  %71 = load i64, ptr %5, align 8, !tbaa !11
  %72 = icmp ult i64 %70, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  store i32 6, ptr %7, align 4
  br label %109

74:                                               ; preds = %69
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = load i64, ptr %10, align 8, !tbaa !11
  %78 = getelementptr inbounds double, ptr %76, i64 %77
  %79 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %75, ptr noundef @.str.50, ptr noundef %78)
  store i32 %79, ptr %4, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %74
  %81 = load i32, ptr %4, align 4, !tbaa !9
  %82 = icmp ne i32 %81, 1
  br i1 %82, label %83, label %103

83:                                               ; preds = %80
  %84 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %88

86:                                               ; preds = %83
  %87 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %90

88:                                               ; preds = %83
  %89 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %88, %86
  %91 = phi ptr [ %87, %86 ], [ %89, %88 ]
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str.48) #4
  %93 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %97

95:                                               ; preds = %90
  %96 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %99

97:                                               ; preds = %90
  %98 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %99

99:                                               ; preds = %97, %95
  %100 = phi ptr [ %96, %95 ], [ %98, %97 ]
  %101 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %100, ptr noundef @.str.1) #4
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  call void @sb_vec_free(ptr noundef %102)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %109

103:                                              ; preds = %80
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  br label %106

106:                                              ; preds = %105
  %107 = load i64, ptr %10, align 8, !tbaa !11
  %108 = add i64 %107, 1
  store i64 %108, ptr %10, align 8, !tbaa !11
  br label %69, !llvm.loop !16

109:                                              ; preds = %99, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %110 = load i32, ptr %7, align 4
  switch i32 %110, label %113 [
    i32 6, label %111
  ]

111:                                              ; preds = %109
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %112, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %113

113:                                              ; preds = %111, %109
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %114

114:                                              ; preds = %113, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %115

115:                                              ; preds = %114, %32
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %116 = load ptr, ptr %2, align 8
  ret ptr %116
}

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !12, i64 0, !6, i64 8, !7, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

@sb_error_log = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sb_vec_malloc(i64 noundef, i8 noundef signext) local_unnamed_addr #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_vec_fscanf(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  %4 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %0, ptr noundef nonnull @.str.38, ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  %.not = icmp eq i32 %4, 2
  br i1 %.not, label %14, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr @sb_error_log, align 8
  %.not23 = icmp eq ptr %6, null
  %7 = load ptr, ptr @stderr, align 8
  %8 = select i1 %.not23, ptr %7, ptr %6
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.48) #4
  %10 = load ptr, ptr @sb_error_log, align 8
  %.not24 = icmp eq ptr %10, null
  %11 = load ptr, ptr @stderr, align 8
  %12 = select i1 %.not24, ptr %11, ptr %10
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.1) #4
  br label %.loopexit

14:                                               ; preds = %1
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = load i8, ptr %3, align 1, !tbaa !9
  %17 = call ptr @sb_vec_malloc(i64 noundef %15, i8 noundef signext %16)
  %.not16 = icmp eq ptr %17, null
  br i1 %.not16, label %18, label %27

18:                                               ; preds = %14
  %19 = load ptr, ptr @sb_error_log, align 8
  %.not17 = icmp eq ptr %19, null
  %20 = load ptr, ptr @stderr, align 8
  %21 = select i1 %.not17, ptr %20, ptr %19
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.49) #4
  %23 = load ptr, ptr @sb_error_log, align 8
  %.not18 = icmp eq ptr %23, null
  %24 = load ptr, ptr @stderr, align 8
  %25 = select i1 %.not18, ptr %24, ptr %23
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.1) #4
  br label %.loopexit

27:                                               ; preds = %14
  %28 = getelementptr inbounds i8, ptr %17, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !10
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %.not2225.not = icmp eq i64 %30, 0
  br i1 %.not2225.not, label %.loopexit, label %.lr.ph

31:                                               ; preds = %.lr.ph
  %32 = add nuw i64 %.026, 1
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %.not22 = icmp ult i64 %32, %33
  br i1 %.not22, label %.lr.ph, label %.loopexit, !llvm.loop !13

.lr.ph:                                           ; preds = %27, %31
  %.026 = phi i64 [ %32, %31 ], [ 0, %27 ]
  %34 = getelementptr inbounds double, ptr %29, i64 %.026
  %35 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %0, ptr noundef nonnull @.str.50, ptr noundef %34) #4
  %.not19 = icmp eq i32 %35, 1
  br i1 %.not19, label %31, label %36

36:                                               ; preds = %.lr.ph
  %37 = load ptr, ptr @sb_error_log, align 8
  %.not20 = icmp eq ptr %37, null
  %38 = load ptr, ptr @stderr, align 8
  %39 = select i1 %.not20, ptr %38, ptr %37
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.48) #4
  %41 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %41, null
  %42 = load ptr, ptr @stderr, align 8
  %43 = select i1 %.not21, ptr %42, ptr %41
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.1) #4
  call void @sb_vec_free(ptr noundef nonnull %17)
  br label %.loopexit

.loopexit:                                        ; preds = %31, %27, %36, %18, %5
  %.3 = phi ptr [ null, %5 ], [ null, %18 ], [ null, %36 ], [ %17, %27 ], [ %17, %31 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret ptr %.3
}

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 8}
!11 = !{!"", !6, i64 0, !12, i64 8, !7, i64 16}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass