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

@arr = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1
@.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.6 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @test_create() #0 {
  %1 = alloca ptr, align 8
  %2 = call ptr @darray_create(i64 noundef 2)
  store ptr %2, ptr @arr, align 8, !tbaa !5
  %3 = load ptr, ptr @arr, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %18, label %5

5:                                                ; preds = %0
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = call ptr @__errno_location() #4
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %5
  br label %15

11:                                               ; preds = %5
  %12 = call ptr @__errno_location() #4
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = call ptr @strerror(i32 noundef %13) #5
  br label %15

15:                                               ; preds = %11, %10
  %16 = phi ptr [ @.str.5, %10 ], [ %14, %11 ]
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 12, ptr noundef %16) #5
  store ptr @.str.6, ptr %1, align 8
  br label %73

18:                                               ; preds = %0
  %19 = load ptr, ptr @arr, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.darray, ptr %19, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %36, label %23

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

28:                                               ; preds = %23
  br label %33

29:                                               ; preds = %23
  %30 = call ptr @__errno_location() #4
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = call ptr @strerror(i32 noundef %31) #5
  br label %33

33:                                               ; preds = %29, %28
  %34 = phi ptr [ @.str.5, %28 ], [ %32, %29 ]
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.7, ptr noundef @.str.4, i32 noundef 13, ptr noundef %34) #5
  store ptr @.str.8, ptr %1, align 8
  br label %73

36:                                               ; preds = %18
  %37 = load ptr, ptr @arr, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.darray, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %54, label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call ptr @__errno_location() #4
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  br label %51

47:                                               ; preds = %41
  %48 = call ptr @__errno_location() #4
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = call ptr @strerror(i32 noundef %49) #5
  br label %51

51:                                               ; preds = %47, %46
  %52 = phi ptr [ @.str.5, %46 ], [ %50, %47 ]
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.9, ptr noundef @.str.4, i32 noundef 14, ptr noundef %52) #5
  store ptr @.str.10, ptr %1, align 8
  br label %73

54:                                               ; preds = %36
  %55 = load ptr, ptr @arr, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.darray, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = icmp ne ptr %57, null
  br i1 %58, label %72, label %59

59:                                               ; preds = %54
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call ptr @__errno_location() #4
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  br label %69

65:                                               ; preds = %59
  %66 = call ptr @__errno_location() #4
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = call ptr @strerror(i32 noundef %67) #5
  br label %69

69:                                               ; preds = %65, %64
  %70 = phi ptr [ @.str.5, %64 ], [ %68, %65 ]
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.11, ptr noundef @.str.4, i32 noundef 15, ptr noundef %70) #5
  store ptr @.str.12, ptr %1, align 8
  br label %73

72:                                               ; preds = %54
  store ptr null, ptr %1, align 8
  br label %73

73:                                               ; preds = %72, %69, %51, %33, %15
  %74 = load ptr, ptr %1, align 8
  ret ptr %74
}

declare ptr @darray_create(i64 noundef) #1

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #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 = { "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 = { 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 #4 = { nounwind willreturn memory(none) }
attributes #5 = { 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, !13, i64 16}
!12 = !{!"darray", !6, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !6, i64 0}


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

@arr = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1
@.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.6 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @test_create() local_unnamed_addr #0 {
  %1 = tail call ptr @darray_create(i64 noundef 2) #5
  store ptr %1, ptr @arr, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %2, label %12

2:                                                ; preds = %0
  %3 = load ptr, ptr @stderr, align 8, !tbaa !5
  %4 = tail call ptr @__errno_location() #6
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %9, label %7

7:                                                ; preds = %2
  %8 = tail call ptr @strerror(i32 noundef %5) #5
  br label %9

9:                                                ; preds = %2, %7
  %10 = phi ptr [ %8, %7 ], [ @.str.5, %2 ]
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 12, ptr noundef %10) #7
  br label %51

12:                                               ; preds = %0
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %.not6 = icmp eq i64 %14, 0
  br i1 %.not6, label %15, label %25

15:                                               ; preds = %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call ptr @__errno_location() #6
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %22, label %20

20:                                               ; preds = %15
  %21 = tail call ptr @strerror(i32 noundef %18) #5
  br label %22

22:                                               ; preds = %15, %20
  %23 = phi ptr [ %21, %20 ], [ @.str.5, %15 ]
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.4, i32 noundef 13, ptr noundef %23) #7
  br label %51

25:                                               ; preds = %12
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %39, label %29

29:                                               ; preds = %25
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = tail call ptr @__errno_location() #6
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %36, label %34

34:                                               ; preds = %29
  %35 = tail call ptr @strerror(i32 noundef %32) #5
  br label %36

36:                                               ; preds = %29, %34
  %37 = phi ptr [ %35, %34 ], [ @.str.5, %29 ]
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.4, i32 noundef 14, ptr noundef %37) #7
  br label %51

39:                                               ; preds = %25
  %40 = load ptr, ptr %1, align 8, !tbaa !15
  %.not7 = icmp eq ptr %40, null
  br i1 %.not7, label %41, label %51

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

46:                                               ; preds = %41
  %47 = tail call ptr @strerror(i32 noundef %44) #5
  br label %48

48:                                               ; preds = %41, %46
  %49 = phi ptr [ %47, %46 ], [ @.str.5, %41 ]
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.4, i32 noundef 15, ptr noundef %49) #7
  br label %51

51:                                               ; preds = %39, %48, %36, %22, %9
  %.0 = phi ptr [ @.str.12, %48 ], [ @.str.10, %36 ], [ @.str.8, %22 ], [ @.str.6, %9 ], [ null, %39 ]
  ret ptr %.0
}

declare ptr @darray_create(i64 noundef) local_unnamed_addr #1

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

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

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

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 = { "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 = { 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 #3 = { 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 #4 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"darray", !6, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !6, i64 0}


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