; LLVM IR from adventure-db/adventure :: tests/struct (darray_tests)

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

@test1 = external dso_local global ptr, align 8
@arr = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [41 x i8], align 1

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #0

declare i32 @darray_push(ptr noundef, ptr noundef) #2

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

declare ptr @darray_pop(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @test_auto_expand() #4 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 10000, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %15, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %18

11:                                               ; preds = %6
  %12 = load ptr, ptr @arr, align 8, !tbaa !9
  %13 = load ptr, ptr @test1, align 8, !tbaa !9
  %14 = call i32 @darray_push(ptr noundef %12, ptr noundef %13)
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !11

18:                                               ; preds = %10
  %19 = load ptr, ptr @arr, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.darray, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = icmp eq i64 %21, %23
  br i1 %24, label %38, label %25

25:                                               ; preds = %18
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = call ptr @__errno_location() #6
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  br label %35

31:                                               ; preds = %25
  %32 = call ptr @__errno_location() #6
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call ptr @strerror(i32 noundef %33) #5
  br label %35

35:                                               ; preds = %31, %30
  %36 = phi ptr [ @.str.5, %30 ], [ %34, %31 ]
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str.25, ptr noundef @.str.4, i32 noundef 59, ptr noundef %36) #5
  store ptr @.str.26, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %97

38:                                               ; preds = %18
  %39 = load ptr, ptr @arr, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.darray, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !16
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp uge i64 %41, %43
  br i1 %44, label %45, label %53

45:                                               ; preds = %38
  %46 = load ptr, ptr @arr, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.darray, ptr %46, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !16
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = mul nsw i32 2, %49
  %51 = sext i32 %50 to i64
  %52 = icmp ule i64 %48, %51
  br i1 %52, label %66, label %53

53:                                               ; preds = %45, %38
  %54 = load ptr, ptr @stderr, align 8, !tbaa !9
  %55 = call ptr @__errno_location() #6
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  br label %63

59:                                               ; preds = %53
  %60 = call ptr @__errno_location() #6
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = call ptr @strerror(i32 noundef %61) #5
  br label %63

63:                                               ; preds = %59, %58
  %64 = phi ptr [ @.str.5, %58 ], [ %62, %59 ]
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.27, ptr noundef @.str.4, i32 noundef 60, ptr noundef %64) #5
  store ptr @.str.28, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %97

66:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %75, %66
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %78

72:                                               ; preds = %67
  %73 = load ptr, ptr @arr, align 8, !tbaa !9
  %74 = call ptr @darray_pop(ptr noundef %73)
  br label %75

75:                                               ; preds = %72
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !5
  br label %67, !llvm.loop !17

78:                                               ; preds = %71
  %79 = load ptr, ptr @arr, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.darray, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !13
  %82 = icmp eq i64 %81, 0
  br i1 %82, label %96, label %83

83:                                               ; preds = %78
  %84 = load ptr, ptr @stderr, align 8, !tbaa !9
  %85 = call ptr @__errno_location() #6
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %83
  br label %93

89:                                               ; preds = %83
  %90 = call ptr @__errno_location() #6
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = call ptr @strerror(i32 noundef %91) #5
  br label %93

93:                                               ; preds = %89, %88
  %94 = phi ptr [ @.str.5, %88 ], [ %92, %89 ]
  %95 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str.21, ptr noundef @.str.4, i32 noundef 66, ptr noundef %94) #5
  store ptr @.str.22, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %97

96:                                               ; preds = %78
  store ptr null, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %97

97:                                               ; preds = %96, %93, %63, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %98 = load ptr, ptr %1, align 8
  ret ptr %98
}

attributes #0 = { 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 #1 = { nounwind willreturn memory(none) "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 8}
!14 = !{!"darray", !10, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 16}
!17 = distinct !{!17, !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"

@test1 = external dso_local local_unnamed_addr global ptr, align 8
@arr = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [41 x i8], align 1

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

declare i32 @darray_push(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @darray_pop(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @test_auto_expand() local_unnamed_addr #4 {
  br label %6

1:                                                ; preds = %6
  %2 = load ptr, ptr @arr, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !9
  %5 = icmp eq i64 %4, 10000
  br i1 %5, label %21, label %11

6:                                                ; preds = %0, %6
  %.0915 = phi i32 [ 0, %0 ], [ %10, %6 ]
  %7 = load ptr, ptr @arr, align 8, !tbaa !5
  %8 = load ptr, ptr @test1, align 8, !tbaa !5
  %9 = tail call i32 @darray_push(ptr noundef %7, ptr noundef %8) #5
  %10 = add nuw nsw i32 %.0915, 1
  %exitcond.not = icmp eq i32 %10, 10000
  br i1 %exitcond.not, label %1, label %6, !llvm.loop !12

11:                                               ; preds = %1
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call ptr @__errno_location() #6
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %18, label %16

16:                                               ; preds = %11
  %17 = tail call ptr @strerror(i32 noundef %14) #5
  br label %18

18:                                               ; preds = %11, %16
  %19 = phi ptr [ %17, %16 ], [ @.str.5, %11 ]
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.25, ptr noundef nonnull @.str.4, i32 noundef 59, ptr noundef %19) #7
  br label %53

21:                                               ; preds = %1
  %22 = getelementptr inbounds i8, ptr %2, i64 16
  %23 = load i64, ptr %22, align 8, !tbaa !16
  %24 = add i64 %23, -10000
  %or.cond = icmp ult i64 %24, 10001
  br i1 %or.cond, label %.preheader, label %25

25:                                               ; preds = %21
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = tail call ptr @__errno_location() #6
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %32, label %30

30:                                               ; preds = %25
  %31 = tail call ptr @strerror(i32 noundef %28) #5
  br label %32

32:                                               ; preds = %25, %30
  %33 = phi ptr [ %31, %30 ], [ @.str.5, %25 ]
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.27, ptr noundef nonnull @.str.4, i32 noundef 60, ptr noundef %33) #7
  br label %53

35:                                               ; preds = %.preheader
  %36 = load ptr, ptr @arr, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %53, label %43

.preheader:                                       ; preds = %21, %.preheader
  %.016 = phi i32 [ %42, %.preheader ], [ 0, %21 ]
  %40 = load ptr, ptr @arr, align 8, !tbaa !5
  %41 = tail call ptr @darray_pop(ptr noundef %40) #5
  %42 = add nuw nsw i32 %.016, 1
  %exitcond17.not = icmp eq i32 %42, 10000
  br i1 %exitcond17.not, label %35, label %.preheader, !llvm.loop !17

43:                                               ; preds = %35
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = tail call ptr @__errno_location() #6
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %50, label %48

48:                                               ; preds = %43
  %49 = tail call ptr @strerror(i32 noundef %46) #5
  br label %50

50:                                               ; preds = %43, %48
  %51 = phi ptr [ %49, %48 ], [ @.str.5, %43 ]
  %52 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.4, i32 noundef 66, ptr noundef %51) #7
  br label %53

53:                                               ; preds = %35, %50, %32, %18
  %.010 = phi ptr [ @.str.22, %50 ], [ @.str.28, %32 ], [ @.str.26, %18 ], [ null, %35 ]
  ret ptr %.010
}

attributes #0 = { 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 #1 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { "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 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }
attributes #7 = { cold 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 8}
!10 = !{!"darray", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !11, i64 16}
!17 = distinct !{!17, !13}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass