; LLVM IR from nubot-nudt/simatch :: src/robot_code/world_model/rtdb/comm.ll (Z17update_stateTablev)

; 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._agent = type { i8, i8, i8, %struct.timeval, i32, i32, [10 x i8], i32 }
%struct.timeval = type { i64, i64 }

@myNumber = external dso_local global i32, align 4
@agent = external dso_local global [10 x %struct._agent], align 16

; 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: mustprogress nounwind uwtable
define dso_local void @_Z17update_stateTablev() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %185, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 10
  br i1 %5, label %6, label %188

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @myNumber, align 4, !tbaa !5
  %9 = icmp ne i32 %7, %8
  br i1 %9, label %10, label %184

10:                                               ; preds = %6
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %12
  %14 = getelementptr inbounds %struct._agent, ptr %13, i32 0, i32 0
  %15 = load i8, ptr %14, align 16, !tbaa !9
  %16 = sext i8 %15 to i32
  switch i32 %16, label %183 [
    i32 1, label %17
    i32 0, label %31
    i32 2, label %45
    i32 3, label %103
  ]

17:                                               ; preds = %10
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %19
  %21 = getelementptr inbounds %struct._agent, ptr %20, i32 0, i32 2
  %22 = load i8, ptr %21, align 2, !tbaa !13
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %17
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %27
  %29 = getelementptr inbounds %struct._agent, ptr %28, i32 0, i32 0
  store i8 3, ptr %29, align 16, !tbaa !9
  br label %30

30:                                               ; preds = %25, %17
  br label %183

31:                                               ; preds = %10
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %33
  %35 = getelementptr inbounds %struct._agent, ptr %34, i32 0, i32 2
  %36 = load i8, ptr %35, align 2, !tbaa !13
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %44

39:                                               ; preds = %31
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %41
  %43 = getelementptr inbounds %struct._agent, ptr %42, i32 0, i32 0
  store i8 2, ptr %43, align 16, !tbaa !9
  br label %44

44:                                               ; preds = %39, %31
  br label %183

45:                                               ; preds = %10
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %47
  %49 = getelementptr inbounds %struct._agent, ptr %48, i32 0, i32 2
  %50 = load i8, ptr %49, align 2, !tbaa !13
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %45
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %55
  %57 = getelementptr inbounds %struct._agent, ptr %56, i32 0, i32 0
  store i8 0, ptr %57, align 16, !tbaa !9
  br label %102

58:                                               ; preds = %45
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %94, %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = icmp slt i32 %60, 10
  br i1 %61, label %62, label %97

62:                                               ; preds = %59
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %64
  %66 = getelementptr inbounds %struct._agent, ptr %65, i32 0, i32 0
  %67 = load i8, ptr %66, align 16, !tbaa !9
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %70, label %93

70:                                               ; preds = %62
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %72
  %74 = getelementptr inbounds %struct._agent, ptr %73, i32 0, i32 6
  %75 = load i32, ptr %1, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10 x i8], ptr %74, i64 0, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !14
  %79 = sext i8 %78 to i32
  %80 = icmp eq i32 %79, 0
  br i1 %80, label %92, label %81

81:                                               ; preds = %70
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %83
  %85 = getelementptr inbounds %struct._agent, ptr %84, i32 0, i32 6
  %86 = load i32, ptr %1, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [10 x i8], ptr %85, i64 0, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !14
  %90 = sext i8 %89 to i32
  %91 = icmp eq i32 %90, 3
  br i1 %91, label %92, label %93

92:                                               ; preds = %81, %70
  br label %97

93:                                               ; preds = %81, %62
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %2, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %2, align 4, !tbaa !5
  br label %59, !llvm.loop !15

97:                                               ; preds = %92, %59
  %98 = load i32, ptr %1, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %99
  %101 = getelementptr inbounds %struct._agent, ptr %100, i32 0, i32 0
  store i8 1, ptr %101, align 16, !tbaa !9
  br label %102

102:                                              ; preds = %97, %53
  br label %183

103:                                              ; preds = %10
  %104 = load i32, ptr %1, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %105
  %107 = getelementptr inbounds %struct._agent, ptr %106, i32 0, i32 2
  %108 = load i8, ptr %107, align 2, !tbaa !13
  %109 = sext i8 %108 to i32
  %110 = icmp eq i32 %109, 1
  br i1 %110, label %111, label %120

111:                                              ; preds = %103
  %112 = load i32, ptr %1, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %113
  %115 = getelementptr inbounds %struct._agent, ptr %114, i32 0, i32 7
  store i32 0, ptr %115, align 4, !tbaa !17
  %116 = load i32, ptr %1, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %117
  %119 = getelementptr inbounds %struct._agent, ptr %118, i32 0, i32 0
  store i8 1, ptr %119, align 16, !tbaa !9
  br label %182

120:                                              ; preds = %103
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %121

121:                                              ; preds = %156, %120
  %122 = load i32, ptr %2, align 4, !tbaa !5
  %123 = icmp slt i32 %122, 10
  br i1 %123, label %124, label %159

124:                                              ; preds = %121
  %125 = load i32, ptr %2, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %126
  %128 = getelementptr inbounds %struct._agent, ptr %127, i32 0, i32 0
  %129 = load i8, ptr %128, align 16, !tbaa !9
  %130 = sext i8 %129 to i32
  %131 = icmp eq i32 %130, 1
  br i1 %131, label %132, label %155

132:                                              ; preds = %124
  %133 = load i32, ptr %2, align 4, !tbaa !5
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %134
  %136 = getelementptr inbounds %struct._agent, ptr %135, i32 0, i32 6
  %137 = load i32, ptr %1, align 4, !tbaa !5
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds [10 x i8], ptr %136, i64 0, i64 %138
  %140 = load i8, ptr %139, align 1, !tbaa !14
  %141 = sext i8 %140 to i32
  %142 = icmp eq i32 %141, 1
  br i1 %142, label %154, label %143

143:                                              ; preds = %132
  %144 = load i32, ptr %2, align 4, !tbaa !5
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %145
  %147 = getelementptr inbounds %struct._agent, ptr %146, i32 0, i32 6
  %148 = load i32, ptr %1, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [10 x i8], ptr %147, i64 0, i64 %149
  %151 = load i8, ptr %150, align 1, !tbaa !14
  %152 = sext i8 %151 to i32
  %153 = icmp eq i32 %152, 2
  br i1 %153, label %154, label %155

154:                                              ; preds = %143, %132
  br label %159

155:                                              ; preds = %143, %124
  br label %156

156:                                              ; preds = %155
  %157 = load i32, ptr %2, align 4, !tbaa !5
  %158 = add nsw i32 %157, 1
  store i32 %158, ptr %2, align 4, !tbaa !5
  br label %121, !llvm.loop !18

159:                                              ; preds = %154, %121
  %160 = load i32, ptr %1, align 4, !tbaa !5
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %161
  %163 = getelementptr inbounds %struct._agent, ptr %162, i32 0, i32 7
  %164 = load i32, ptr %163, align 4, !tbaa !17
  %165 = add nsw i32 %164, 1
  store i32 %165, ptr %163, align 4, !tbaa !17
  %166 = load i32, ptr %1, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %167
  %169 = getelementptr inbounds %struct._agent, ptr %168, i32 0, i32 7
  %170 = load i32, ptr %169, align 4, !tbaa !17
  %171 = icmp sge i32 %170, 10
  br i1 %171, label %172, label %181

172:                                              ; preds = %159
  %173 = load i32, ptr %1, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %174
  %176 = getelementptr inbounds %struct._agent, ptr %175, i32 0, i32 0
  store i8 0, ptr %176, align 16, !tbaa !9
  %177 = load i32, ptr %1, align 4, !tbaa !5
  %178 = sext i32 %177 to i64
  %179 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %178
  %180 = getelementptr inbounds %struct._agent, ptr %179, i32 0, i32 7
  store i32 0, ptr %180, align 4, !tbaa !17
  br label %181

181:                                              ; preds = %172, %159
  br label %182

182:                                              ; preds = %181, %111
  br label %183

183:                                              ; preds = %182, %102, %44, %30, %10
  br label %184

184:                                              ; preds = %183, %6
  br label %185

185:                                              ; preds = %184
  %186 = load i32, ptr %1, align 4, !tbaa !5
  %187 = add nsw i32 %186, 1
  store i32 %187, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !19

188:                                              ; preds = %3
  %189 = load i32, ptr @myNumber, align 4, !tbaa !5
  %190 = sext i32 %189 to i64
  %191 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %190
  %192 = getelementptr inbounds %struct._agent, ptr %191, i32 0, i32 0
  store i8 1, ptr %192, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"_ZTS6_agent", !7, i64 0, !7, i64 1, !7, i64 2, !11, i64 8, !6, i64 24, !6, i64 28, !7, i64 32, !6, i64 44}
!11 = !{!"_ZTS7timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !7, i64 2}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 44}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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._agent = type { i8, i8, i8, %struct.timeval, i32, i32, [10 x i8], i32 }
%struct.timeval = type { i64, i64 }

@myNumber = external dso_local local_unnamed_addr global i32, align 4
@agent = external dso_local local_unnamed_addr global [10 x %struct._agent], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z17update_stateTablev() local_unnamed_addr #0 {
  %1 = load i32, ptr @myNumber, align 4, !tbaa !5
  %2 = zext i32 %1 to i64
  br label %3

3:                                                ; preds = %0, %32
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %32 ]
  %.not = icmp eq i64 %indvars.iv, %2
  br i1 %.not, label %32, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 16, !tbaa !9
  switch i8 %6, label %32 [
    i8 1, label %7
    i8 0, label %12
    i8 2, label %17
    i8 3, label %22
  ]

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %5, i64 2
  %9 = load i8, ptr %8, align 2, !tbaa !13
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %32

11:                                               ; preds = %7
  store i8 3, ptr %5, align 16, !tbaa !9
  br label %32

12:                                               ; preds = %4
  %13 = getelementptr inbounds i8, ptr %5, i64 2
  %14 = load i8, ptr %13, align 2, !tbaa !13
  %15 = icmp eq i8 %14, 1
  br i1 %15, label %16, label %32

16:                                               ; preds = %12
  store i8 2, ptr %5, align 16, !tbaa !9
  br label %32

17:                                               ; preds = %4
  %18 = getelementptr inbounds i8, ptr %5, i64 2
  %19 = load i8, ptr %18, align 2, !tbaa !13
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %21, label %.preheader.preheader

.preheader.preheader:                             ; preds = %17
  store i8 1, ptr %5, align 16, !tbaa !9
  br label %32

21:                                               ; preds = %17
  store i8 0, ptr %5, align 16, !tbaa !9
  br label %32

22:                                               ; preds = %4
  %23 = getelementptr inbounds i8, ptr %5, i64 2
  %24 = load i8, ptr %23, align 2, !tbaa !13
  %25 = icmp eq i8 %24, 1
  %26 = getelementptr inbounds i8, ptr %5, i64 44
  br i1 %25, label %30, label %.preheader35.preheader

.preheader35.preheader:                           ; preds = %22
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !14
  %29 = icmp sgt i32 %27, 8
  br i1 %29, label %31, label %32

30:                                               ; preds = %22
  store i32 0, ptr %26, align 4, !tbaa !14
  store i8 1, ptr %5, align 16, !tbaa !9
  br label %32

31:                                               ; preds = %.preheader35.preheader
  store i8 0, ptr %5, align 16, !tbaa !9
  store i32 0, ptr %26, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %3, %30, %31, %.preheader35.preheader, %21, %.preheader.preheader, %12, %16, %7, %11, %4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10
  br i1 %exitcond.not, label %33, label %3, !llvm.loop !15

33:                                               ; preds = %32
  %34 = sext i32 %1 to i64
  %35 = getelementptr inbounds [10 x %struct._agent], ptr @agent, i64 0, i64 %34
  store i8 1, ptr %35, align 16, !tbaa !9
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"_ZTS6_agent", !7, i64 0, !7, i64 1, !7, i64 2, !11, i64 8, !6, i64 24, !6, i64 28, !7, i64 32, !6, i64 44}
!11 = !{!"_ZTS7timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !7, i64 2}
!14 = !{!10, !6, i64 44}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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