; LLVM IR from SourajitaDewasi/ComputerNetworks :: MAC (CSMACD)

; 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.dataPacket = type { i32, i32, i32 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@A = external dso_local global [3 x %struct.dataPacket], align 16
@B = external dso_local global [2 x %struct.dataPacket], align 16
@i = external dso_local global i32, align 4
@j = external dso_local global i32, align 4
@check = external dso_local global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [212 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4CSMAii(i32 noundef, i32 noundef) #0

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i64 @time(ptr noundef null) #4
  %3 = trunc i64 %2 to i32
  call void @srand(i32 noundef %3) #4
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %20, %0
  %5 = load i32, ptr @i, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 3
  br i1 %6, label %7, label %23

7:                                                ; preds = %4
  %8 = load i32, ptr @i, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.dataPacket, ptr %10, i32 0, i32 0
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = load i32, ptr @i, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.dataPacket, ptr %14, i32 0, i32 1
  store i32 0, ptr %15, align 4, !tbaa !11
  %16 = load i32, ptr @i, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.dataPacket, ptr %18, i32 0, i32 2
  store i32 0, ptr %19, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %7
  %21 = load i32, ptr @i, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @i, align 4, !tbaa !5
  br label %4, !llvm.loop !13

23:                                               ; preds = %4
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %40, %23
  %25 = load i32, ptr @i, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 2
  br i1 %26, label %27, label %43

27:                                               ; preds = %24
  %28 = load i32, ptr @i, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.dataPacket, ptr %30, i32 0, i32 0
  store i32 0, ptr %31, align 4, !tbaa !9
  %32 = load i32, ptr @i, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.dataPacket, ptr %34, i32 0, i32 1
  store i32 0, ptr %35, align 4, !tbaa !11
  %36 = load i32, ptr @i, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.dataPacket, ptr %38, i32 0, i32 2
  store i32 0, ptr %39, align 4, !tbaa !12
  br label %40

40:                                               ; preds = %27
  %41 = load i32, ptr @i, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @i, align 4, !tbaa !5
  br label %24, !llvm.loop !15

43:                                               ; preds = %24
  store i32 0, ptr @i, align 4, !tbaa !5
  store i32 0, ptr @j, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %94, %43
  %45 = load i32, ptr getelementptr inbounds (%struct.dataPacket, ptr getelementptr inbounds ([3 x %struct.dataPacket], ptr @A, i64 0, i64 3), i32 0, i32 2), align 4, !tbaa !12
  %46 = icmp ne i32 %45, 1
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load i32, ptr getelementptr inbounds (%struct.dataPacket, ptr getelementptr inbounds ([2 x %struct.dataPacket], ptr @B, i64 0, i64 2), i32 0, i32 2), align 8, !tbaa !12
  %49 = icmp ne i32 %48, 1
  br label %50

50:                                               ; preds = %47, %44
  %51 = phi i1 [ false, %44 ], [ %49, %47 ]
  br i1 %51, label %52, label %95

52:                                               ; preds = %50
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.3)
  %54 = load i32, ptr @i, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.dataPacket, ptr %56, i32 0, i32 0
  store i32 1, ptr %57, align 4, !tbaa !9
  %58 = load i32, ptr @j, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.dataPacket, ptr %60, i32 0, i32 0
  store i32 1, ptr %61, align 4, !tbaa !9
  %62 = load i32, ptr @i, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.dataPacket, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !11
  %67 = load i32, ptr @j, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.dataPacket, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = call noundef i32 @_Z4CSMAii(i32 noundef %66, i32 noundef %71)
  %73 = load i32, ptr @check, align 4, !tbaa !5
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %83

75:                                               ; preds = %52
  %76 = load i32, ptr @j, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr @j, align 4, !tbaa !5
  %78 = load i32, ptr @j, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.dataPacket, ptr %80, i32 0, i32 2
  store i32 1, ptr %81, align 4, !tbaa !12
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.4)
  br label %83

83:                                               ; preds = %75, %52
  %84 = load i32, ptr @check, align 4, !tbaa !5
  %85 = icmp eq i32 %84, 1
  br i1 %85, label %86, label %94

86:                                               ; preds = %83
  %87 = load i32, ptr @i, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr @i, align 4, !tbaa !5
  %89 = load i32, ptr @i, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.dataPacket, ptr %91, i32 0, i32 2
  store i32 1, ptr %92, align 4, !tbaa !12
  %93 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.5)
  br label %94

94:                                               ; preds = %86, %83
  br label %44, !llvm.loop !16

95:                                               ; preds = %50
  %96 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.6)
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #3

attributes #0 = { 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 #1 = { inlinehint 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 #2 = { mustprogress norecurse 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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS10dataPacket", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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.dataPacket = type { i32, i32, i32 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@A = external dso_local local_unnamed_addr global [3 x %struct.dataPacket], align 16
@B = external dso_local local_unnamed_addr global [2 x %struct.dataPacket], align 16
@i = external dso_local local_unnamed_addr global i32, align 4
@j = external dso_local local_unnamed_addr global i32, align 4
@check = external dso_local local_unnamed_addr global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [212 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4CSMAii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
.preheader:
  %0 = tail call i64 @time(ptr noundef null) #5
  %1 = trunc i64 %0 to i32
  tail call void @srand(i32 noundef %1) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(36) @A, i8 0, i64 36, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) @B, i8 0, i64 24, i1 false), !tbaa !5
  store i32 0, ptr @i, align 4, !tbaa !5
  store i32 0, ptr @j, align 4, !tbaa !5
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 44), align 4, !tbaa !9
  %.not6 = icmp eq i32 %2, 1
  br i1 %.not6, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %34
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @B, i64 32), align 16, !tbaa !9
  %.not3 = icmp eq i32 %3, 1
  br i1 %.not3, label %.critedge, label %4

4:                                                ; preds = %.lr.ph
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.3)
  %6 = load i32, ptr @i, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %7
  store i32 1, ptr %8, align 4, !tbaa !11
  %9 = load i32, ptr @j, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %10
  store i32 1, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %7, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %10, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = tail call noundef i32 @_Z4CSMAii(i32 noundef %13, i32 noundef %15)
  %17 = load i32, ptr @check, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %4
  %20 = load i32, ptr @j, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @j, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x %struct.dataPacket], ptr @B, i64 0, i64 %22, i32 2
  store i32 1, ptr %23, align 4, !tbaa !9
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.4)
  %.pr = load i32, ptr @check, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %19, %4
  %26 = phi i32 [ %.pr, %19 ], [ %17, %4 ]
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load i32, ptr @i, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @i, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [3 x %struct.dataPacket], ptr @A, i64 0, i64 %31, i32 2
  store i32 1, ptr %32, align 4, !tbaa !9
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.5)
  br label %34

34:                                               ; preds = %28, %25
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 44), align 4, !tbaa !9
  %.not = icmp eq i32 %35, 1
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %34, %.preheader
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.6)
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 #1 = { inlinehint 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 #2 = { mustprogress norecurse 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS10dataPacket", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass