; LLVM IR from cvitatma/DSA :: 01-preliminaries/preliminaries.ll (Z10structuresv)

; 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.record_type_1 = type { ptr, i32, i32 }
%struct.record_type_2 = type { %struct.record_type_1, %struct._addr }
%struct._addr = type { ptr }

@.str.47 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.61 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.62 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.63 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._Z10structuresv = external hidden unnamed_addr constant [18 x i8], align 1
@.str.64 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.66 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [7 x i8], align 1
@__const._Z10structuresv.ctypArr = external hidden unnamed_addr constant [2 x i32], align 4
@.str.68 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [7 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5pausev() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #6

; Function Attrs: nounwind
declare void @free(ptr noundef) #7

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10structuresv() #2 {
  %1 = alloca %struct.record_type_1, align 8
  %2 = alloca %struct.record_type_1, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca [2 x i32], align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #8
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #8
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.61, i64 noundef 16)
  call void @_Z5pausev()
  %14 = getelementptr inbounds %struct.record_type_1, ptr %1, i32 0, i32 1
  store i32 1, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #8
  store ptr @.str.62, ptr %3, align 8, !tbaa !12
  %15 = load ptr, ptr %3, align 8, !tbaa !12
  %16 = call noalias ptr @strdup(ptr noundef %15) #8
  %17 = getelementptr inbounds %struct.record_type_1, ptr %1, i32 0, i32 0
  store ptr %16, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds %struct.record_type_1, ptr %1, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %0
  br label %24

22:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str.63, ptr noundef @.str.47, i32 noundef 418, ptr noundef @__PRETTY_FUNCTION__._Z10structuresv) #9
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = getelementptr inbounds %struct.record_type_1, ptr %1, i32 0, i32 2
  store i32 1, ptr %25, align 4, !tbaa !14
  %26 = getelementptr inbounds %struct.record_type_1, ptr %2, i32 0, i32 1
  store i32 2, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #8
  store ptr @.str.64, ptr %4, align 8, !tbaa !12
  %27 = load ptr, ptr %4, align 8, !tbaa !12
  %28 = call noalias ptr @strdup(ptr noundef %27) #8
  %29 = getelementptr inbounds %struct.record_type_1, ptr %2, i32 0, i32 0
  store ptr %28, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.record_type_1, ptr %2, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  br label %36

34:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.65, ptr noundef @.str.47, i32 noundef 424, ptr noundef @__PRETTY_FUNCTION__._Z10structuresv) #9
  unreachable

35:                                               ; No predecessors!
  br label %36

36:                                               ; preds = %35, %33
  %37 = getelementptr inbounds %struct.record_type_1, ptr %2, i32 0, i32 2
  store i32 0, ptr %37, align 4, !tbaa !14
  %38 = getelementptr inbounds %struct.record_type_1, ptr %1, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  call void @free(ptr noundef %39) #8
  %40 = getelementptr inbounds %struct.record_type_1, ptr %2, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  call void @free(ptr noundef %41) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 2, ptr %5, align 4, !tbaa !15
  %42 = load i32, ptr %5, align 4, !tbaa !15
  %43 = zext i32 %42 to i64
  %44 = call ptr @llvm.stacksave.p0()
  store ptr %44, ptr %6, align 8
  %45 = alloca ptr, i64 %43, align 16
  store i64 %43, ptr %7, align 8
  %46 = getelementptr inbounds ptr, ptr %45, i64 0
  store ptr @.str.66, ptr %46, align 16, !tbaa !12
  %47 = getelementptr inbounds ptr, ptr %45, i64 1
  store ptr @.str.67, ptr %47, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 @__const._Z10structuresv.ctypArr, i64 8, i1 false)
  %48 = load i32, ptr %5, align 4, !tbaa !15
  %49 = zext i32 %48 to i64
  %50 = alloca %struct.record_type_1, i64 %49, align 16
  store i64 %49, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %51

51:                                               ; preds = %80, %36
  %52 = load i32, ptr %10, align 4, !tbaa !15
  %53 = load i32, ptr %5, align 4, !tbaa !15
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %83

56:                                               ; preds = %51
  %57 = load i32, ptr %10, align 4, !tbaa !15
  %58 = add nsw i32 %57, 1
  %59 = load i32, ptr %10, align 4, !tbaa !15
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 %60
  %62 = getelementptr inbounds %struct.record_type_1, ptr %61, i32 0, i32 1
  store i32 %58, ptr %62, align 8, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !15
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %45, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = call noalias ptr @strdup(ptr noundef %66) #8
  %68 = load i32, ptr %10, align 4, !tbaa !15
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 %69
  %71 = getelementptr inbounds %struct.record_type_1, ptr %70, i32 0, i32 0
  store ptr %67, ptr %71, align 16, !tbaa !13
  %72 = load i32, ptr %10, align 4, !tbaa !15
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [2 x i32], ptr %8, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = load i32, ptr %10, align 4, !tbaa !15
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 %77
  %79 = getelementptr inbounds %struct.record_type_1, ptr %78, i32 0, i32 2
  store i32 %75, ptr %79, align 4, !tbaa !14
  br label %80

80:                                               ; preds = %56
  %81 = load i32, ptr %10, align 4, !tbaa !15
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %10, align 4, !tbaa !15
  br label %51, !llvm.loop !17

83:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  %84 = call noalias ptr @malloc(i64 noundef 24) #10
  store ptr %84, ptr %11, align 8, !tbaa !12
  %85 = load ptr, ptr %11, align 8, !tbaa !12
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %88

87:                                               ; preds = %83
  br label %90

88:                                               ; preds = %83
  call void @__assert_fail(ptr noundef @.str.68, ptr noundef @.str.47, i32 noundef 447, ptr noundef @__PRETTY_FUNCTION__._Z10structuresv) #9
  unreachable

89:                                               ; No predecessors!
  br label %90

90:                                               ; preds = %89, %87
  %91 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 0
  %92 = load ptr, ptr %11, align 8, !tbaa !12
  %93 = getelementptr inbounds %struct.record_type_2, ptr %92, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %93, ptr align 16 %91, i64 16, i1 false), !tbaa.struct !19
  %94 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 0
  %95 = getelementptr inbounds %struct.record_type_1, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 16, !tbaa !13
  %97 = call noalias ptr @strdup(ptr noundef %96) #8
  %98 = load ptr, ptr %11, align 8, !tbaa !12
  %99 = getelementptr inbounds %struct.record_type_2, ptr %98, i32 0, i32 0
  %100 = getelementptr inbounds %struct.record_type_1, ptr %99, i32 0, i32 0
  store ptr %97, ptr %100, align 8, !tbaa !20
  %101 = load ptr, ptr %11, align 8, !tbaa !12
  %102 = getelementptr inbounds %struct.record_type_2, ptr %101, i32 0, i32 1
  %103 = getelementptr inbounds %struct._addr, ptr %102, i32 0, i32 0
  store ptr @.str.69, ptr %103, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store i32 0, ptr %12, align 4, !tbaa !15
  br label %104

104:                                              ; preds = %115, %90
  %105 = load i32, ptr %12, align 4, !tbaa !15
  %106 = load i32, ptr %5, align 4, !tbaa !15
  %107 = icmp slt i32 %105, %106
  br i1 %107, label %109, label %108

108:                                              ; preds = %104
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %118

109:                                              ; preds = %104
  %110 = load i32, ptr %12, align 4, !tbaa !15
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds %struct.record_type_1, ptr %50, i64 %111
  %113 = getelementptr inbounds %struct.record_type_1, ptr %112, i32 0, i32 0
  %114 = load ptr, ptr %113, align 16, !tbaa !13
  call void @free(ptr noundef %114) #8
  br label %115

115:                                              ; preds = %109
  %116 = load i32, ptr %12, align 4, !tbaa !15
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %12, align 4, !tbaa !15
  br label %104, !llvm.loop !24

118:                                              ; preds = %108
  %119 = load ptr, ptr %11, align 8, !tbaa !12
  %120 = getelementptr inbounds %struct.record_type_2, ptr %119, i32 0, i32 0
  %121 = getelementptr inbounds %struct.record_type_1, ptr %120, i32 0, i32 0
  %122 = load ptr, ptr %121, align 8, !tbaa !20
  call void @free(ptr noundef %122) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  %123 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %123)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #8
  ret void
}

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #7

attributes #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 = { mustprogress 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind allocsize(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 #6 = { noreturn 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { noreturn nounwind }
attributes #10 = { nounwind allocsize(0) }

!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, !10, i64 8}
!6 = !{!"_ZTS13record_type_1", !7, i64 0, !10, i64 8, !11, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS5ctype", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !11, i64 12}
!15 = !{!10, !10, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i64 0, i64 8, !12, i64 8, i64 4, !15, i64 12, i64 4, !16}
!20 = !{!21, !7, i64 0}
!21 = !{!"_ZTS13record_type_2", !6, i64 0, !22, i64 16}
!22 = !{!"_ZTS5_addr", !7, i64 0}
!23 = !{!21, !7, i64 16}
!24 = distinct !{!24, !18}


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

@.str.61 = external hidden unnamed_addr constant [56 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5pausev() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10structuresv() local_unnamed_addr #1 {
.preheader.preheader:
  %0 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.61, i64 noundef 16)
  tail call void @_Z5pausev()
  ret void
}

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

!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)"}


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