; LLVM IR from LeoVen/C-Macro-Collections :: tests (types)

; 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.struct_s = type { i32, i32, ptr, ptr, [10 x double] }
%struct.list1 = type { ptr, i64, i64, i32, ptr, ptr }
%struct.list1_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @l1_index_of(ptr noundef %0, ptr noundef byval(%struct.struct_s) align 8 %1, i1 noundef zeroext %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  %11 = zext i1 %2 to i8
  store i8 %11, ptr %6, align 1, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.list1, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp eq ptr %14, null
  br i1 %15, label %23, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.list1, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.list1_fval, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %16, %3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.list1, ptr %24, i32 0, i32 3
  store i32 11, ptr %25, align 8, !tbaa !17
  store i64 0, ptr %4, align 8
  br label %96

26:                                               ; preds = %16
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.list1, ptr %27, i32 0, i32 3
  store i32 0, ptr %28, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.list1, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !18
  store i64 %31, ptr %7, align 8, !tbaa !19
  %32 = load i8, ptr %6, align 1, !tbaa !9, !range !20, !noundef !21
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %63

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !19
  br label %35

35:                                               ; preds = %58, %34
  %36 = load i64, ptr %8, align 8, !tbaa !19
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.list1, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !18
  %40 = icmp ult i64 %36, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %35
  store i32 2, ptr %9, align 4
  br label %61

42:                                               ; preds = %35
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.list1, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.list1_fval, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.list1, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  %51 = load i64, ptr %8, align 8, !tbaa !19
  %52 = getelementptr inbounds %struct.struct_s, ptr %50, i64 %51
  %53 = call i32 %47(ptr noundef byval(%struct.struct_s) align 8 %52, ptr noundef byval(%struct.struct_s) align 8 %1)
  %54 = icmp eq i32 0, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %42
  %56 = load i64, ptr %8, align 8, !tbaa !19
  store i64 %56, ptr %7, align 8, !tbaa !19
  store i32 2, ptr %9, align 4
  br label %61

57:                                               ; preds = %42
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %8, align 8, !tbaa !19
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !19
  br label %35, !llvm.loop !23

61:                                               ; preds = %55, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %62

62:                                               ; preds = %61
  br label %94

63:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.list1, ptr %64, i32 0, i32 2
  %66 = load i64, ptr %65, align 8, !tbaa !18
  store i64 %66, ptr %10, align 8, !tbaa !19
  br label %67

67:                                               ; preds = %89, %63
  %68 = load i64, ptr %10, align 8, !tbaa !19
  %69 = icmp ugt i64 %68, 0
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  store i32 5, ptr %9, align 4
  br label %92

71:                                               ; preds = %67
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.list1, ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = getelementptr inbounds %struct.list1_fval, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.list1, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !22
  %80 = load i64, ptr %10, align 8, !tbaa !19
  %81 = sub i64 %80, 1
  %82 = getelementptr inbounds %struct.struct_s, ptr %79, i64 %81
  %83 = call i32 %76(ptr noundef byval(%struct.struct_s) align 8 %82, ptr noundef byval(%struct.struct_s) align 8 %1)
  %84 = icmp eq i32 0, %83
  br i1 %84, label %85, label %88

85:                                               ; preds = %71
  %86 = load i64, ptr %10, align 8, !tbaa !19
  %87 = sub i64 %86, 1
  store i64 %87, ptr %7, align 8, !tbaa !19
  store i32 5, ptr %9, align 4
  br label %92

88:                                               ; preds = %71
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %10, align 8, !tbaa !19
  %91 = add i64 %90, -1
  store i64 %91, ptr %10, align 8, !tbaa !19
  br label %67, !llvm.loop !25

92:                                               ; preds = %85, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93, %62
  %95 = load i64, ptr %7, align 8, !tbaa !19
  store i64 %95, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %96

96:                                               ; preds = %94, %23
  %97 = load i64, ptr %4, align 8
  ret i64 %97
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"list1", !6, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"list1_fval", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!12, !14, i64 24}
!18 = !{!12, !13, i64 16}
!19 = !{!13, !13, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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

%struct.struct_s = type { i32, i32, ptr, ptr, [10 x double] }

; Function Attrs: nounwind uwtable
define dso_local i64 @l1_index_of(ptr nocapture noundef %0, ptr noundef byval(%struct.struct_s) align 8 %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %10, label %7

7:                                                ; preds = %3
  %8 = load ptr, ptr %5, align 8, !tbaa !12
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %7, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 11, ptr %11, align 8, !tbaa !14
  br label %.loopexit

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i64, ptr %14, align 8, !tbaa !15
  br i1 %2, label %.preheader, label %.preheader25

.preheader:                                       ; preds = %12
  %.not31 = icmp eq i64 %15, 0
  br i1 %.not31, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %22
  %.02128 = phi i64 [ %23, %22 ], [ 0, %.preheader ]
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = load ptr, ptr %0, align 8, !tbaa !16
  %19 = getelementptr inbounds %struct.struct_s, ptr %18, i64 %.02128
  %20 = tail call i32 %17(ptr noundef byval(%struct.struct_s) align 8 %19, ptr noundef nonnull byval(%struct.struct_s) align 8 %1) #1
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %.lr.ph
  %23 = add nuw i64 %.02128, 1
  %24 = load i64, ptr %14, align 8, !tbaa !15
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %.lr.ph, label %.loopexit, !llvm.loop !17

.preheader25:                                     ; preds = %12, %26
  %.0 = phi i64 [ %30, %26 ], [ %15, %12 ]
  %.not = icmp eq i64 %.0, 0
  br i1 %.not, label %.loopexit, label %26

26:                                               ; preds = %.preheader25
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = load ptr, ptr %0, align 8, !tbaa !16
  %30 = add i64 %.0, -1
  %31 = getelementptr inbounds %struct.struct_s, ptr %29, i64 %30
  %32 = tail call i32 %28(ptr noundef byval(%struct.struct_s) align 8 %31, ptr noundef nonnull byval(%struct.struct_s) align 8 %1) #1
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %.loopexit, label %.preheader25, !llvm.loop !19

.loopexit:                                        ; preds = %26, %.preheader25, %22, %.lr.ph, %.preheader, %10
  %.023 = phi i64 [ 0, %10 ], [ 0, %.preheader ], [ %15, %22 ], [ %.02128, %.lr.ph ], [ %30, %26 ], [ %15, %.preheader25 ]
  ret i64 %.023
}

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 }

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


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