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

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

@p_def = external dso_local global [10 x ptr], align 16
@p_shared_mem = external dso_local global [10 x [10 x ptr]], align 16
@p_local_mem = external dso_local global [10 x ptr], align 16
@.str.4 = external hidden unnamed_addr constant [97 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [50 x i8], align 1
@__FUNCTION__._Z11DB_get_fromiiiPv = external hidden unnamed_addr constant [12 x i8], align 1

; 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

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

; 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) #2

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z11DB_get_fromiiiPv(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.timeval, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 3333
  br i1 %17, label %18, label %25

18:                                               ; preds = %4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x ptr], ptr @p_def, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.RTDBdef, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !11
  store i32 %24, ptr %7, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %18, %4
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x ptr], ptr @p_def, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.RTDBdef, ptr %29, i32 0, i32 6
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [10 x [100 x i32]], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %10, align 4, !tbaa !5
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %43

39:                                               ; preds = %25
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, ptr noundef @.str.4, ptr noundef @__FUNCTION__._Z11DB_get_fromiiiPv, i32 noundef %40, i32 noundef %41)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

43:                                               ; preds = %25
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 100
  br i1 %45, label %46, label %58

46:                                               ; preds = %43
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10 x [10 x ptr]], ptr @p_shared_mem, i64 0, i64 %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x ptr], ptr %49, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = mul i64 %55, 56
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  store ptr %57, ptr %11, align 8, !tbaa !9
  br label %68

58:                                               ; preds = %43
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x ptr], ptr @p_local_mem, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 100
  %65 = sext i32 %64 to i64
  %66 = mul i64 %65, 56
  %67 = getelementptr inbounds i8, ptr %62, i64 %66
  store ptr %67, ptr %11, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %58, %46
  %69 = load ptr, ptr %11, align 8, !tbaa !9
  %70 = load ptr, ptr %11, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.TRec, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 4, !tbaa !13
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %69, i64 %73
  store ptr %74, ptr %12, align 8, !tbaa !9
  %75 = load ptr, ptr %9, align 8, !tbaa !9
  %76 = load ptr, ptr %12, align 8, !tbaa !9
  %77 = load ptr, ptr %11, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.TRec, ptr %77, i32 0, i32 4
  %79 = load i32, ptr %78, align 8, !tbaa !15
  %80 = load ptr, ptr %11, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.TRec, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !16
  %83 = mul nsw i32 %79, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %76, i64 %84
  %86 = load ptr, ptr %11, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.TRec, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !16
  %89 = sext i32 %88 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %75, ptr align 1 %85, i64 %89, i1 false)
  %90 = call i32 @gettimeofday(ptr noundef %13, ptr noundef null) #6
  %91 = getelementptr inbounds %struct.timeval, ptr %13, i32 0, i32 0
  %92 = load i64, ptr %91, align 8, !tbaa !17
  %93 = load ptr, ptr %11, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.TRec, ptr %93, i32 0, i32 5
  %95 = load ptr, ptr %11, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.TRec, ptr %95, i32 0, i32 4
  %97 = load i32, ptr %96, align 8, !tbaa !15
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [2 x %struct.timeval], ptr %94, i64 0, i64 %98
  %100 = getelementptr inbounds %struct.timeval, ptr %99, i32 0, i32 0
  %101 = load i64, ptr %100, align 8, !tbaa !17
  %102 = sub nsw i64 %92, %101
  %103 = sitofp i64 %102 to double
  %104 = getelementptr inbounds %struct.timeval, ptr %13, i32 0, i32 1
  %105 = load i64, ptr %104, align 8, !tbaa !20
  %106 = load ptr, ptr %11, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct.TRec, ptr %106, i32 0, i32 5
  %108 = load ptr, ptr %11, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct.TRec, ptr %108, i32 0, i32 4
  %110 = load i32, ptr %109, align 8, !tbaa !15
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [2 x %struct.timeval], ptr %107, i64 0, i64 %111
  %113 = getelementptr inbounds %struct.timeval, ptr %112, i32 0, i32 1
  %114 = load i64, ptr %113, align 8, !tbaa !20
  %115 = sub nsw i64 %105, %114
  %116 = sitofp i64 %115 to double
  %117 = fdiv double %116, 1.000000e+03
  %118 = call double @llvm.fmuladd.f64(double %103, double 1.000000e+03, double %117)
  %119 = fptosi double %118 to i32
  store i32 %119, ptr %14, align 4, !tbaa !5
  %120 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %120, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

121:                                              ; preds = %68, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %122 = load i32, ptr %5, align 4
  ret i32 %122
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS7RTDBdef", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 48, !7, i64 52, !6, i64 92, !7, i64 96}
!13 = !{!14, !6, i64 12}
!14 = !{!"_ZTS4TRec", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !7, i64 24}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 4}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTS7timeval", !19, i64 0, !19, i64 8}
!19 = !{!"long", !7, i64 0}
!20 = !{!18, !19, i64 8}


; 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.timeval = type { i64, i64 }

@p_def = external dso_local local_unnamed_addr global [10 x ptr], align 16
@p_shared_mem = external dso_local local_unnamed_addr global [10 x [10 x ptr]], align 16
@p_local_mem = external dso_local local_unnamed_addr global [10 x ptr], align 16
@.str.4 = external hidden unnamed_addr constant [97 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [50 x i8], align 1
@__FUNCTION__._Z11DB_get_fromiiiPv = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

; Function Attrs: mustprogress 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) #2

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef i32 @_Z11DB_get_fromiiiPv(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #3 {
  %5 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %6 = icmp eq i32 %1, 3333
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [10 x ptr], ptr @p_def, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  br i1 %6, label %10, label %._crit_edge

10:                                               ; preds = %4
  %11 = load i32, ptr %9, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %10
  %.025 = phi i32 [ %11, %10 ], [ %1, %4 ]
  %12 = getelementptr inbounds i8, ptr %9, i64 96
  %13 = sext i32 %.025 to i64
  %14 = sext i32 %2 to i64
  %15 = getelementptr inbounds [10 x [100 x i32]], ptr %12, i64 0, i64 %13, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %20

18:                                               ; preds = %._crit_edge
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, ptr noundef nonnull @.str.4, ptr noundef nonnull @__FUNCTION__._Z11DB_get_fromiiiPv, i32 noundef %2, i32 noundef %.025)
  br label %59

20:                                               ; preds = %._crit_edge
  %21 = icmp slt i32 %16, 100
  %22 = getelementptr inbounds [10 x ptr], ptr @p_local_mem, i64 0, i64 %7
  %23 = add nsw i32 %16, -100
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [10 x [10 x ptr]], ptr @p_shared_mem, i64 0, i64 %7, i64 %13
  %26 = sext i32 %16 to i64
  %.sink32 = select i1 %21, i64 %26, i64 %24
  %.sink.in = select i1 %21, ptr %25, ptr %22
  %.sink = load ptr, ptr %.sink.in, align 8, !tbaa !5
  %27 = mul nsw i64 %.sink32, 56
  %28 = getelementptr inbounds i8, ptr %.sink, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 12
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %28, i64 %31
  %33 = getelementptr inbounds i8, ptr %28, i64 16
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %28, i64 4
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = mul nsw i32 %36, %34
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %32, i64 %38
  %40 = sext i32 %36 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 %39, i64 %40, i1 false)
  %41 = call i32 @gettimeofday(ptr noundef nonnull %5, ptr noundef null) #5
  %42 = load i64, ptr %5, align 8, !tbaa !17
  %43 = getelementptr inbounds i8, ptr %28, i64 24
  %44 = load i32, ptr %33, align 8, !tbaa !15
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2 x %struct.timeval], ptr %43, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !17
  %48 = sub nsw i64 %42, %47
  %49 = sitofp i64 %48 to double
  %50 = getelementptr inbounds i8, ptr %5, i64 8
  %51 = load i64, ptr %50, align 8, !tbaa !20
  %52 = getelementptr inbounds i8, ptr %46, i64 8
  %53 = load i64, ptr %52, align 8, !tbaa !20
  %54 = sub nsw i64 %51, %53
  %55 = sitofp i64 %54 to double
  %56 = fdiv double %55, 1.000000e+03
  %57 = tail call double @llvm.fmuladd.f64(double %49, double 1.000000e+03, double %56)
  %58 = fptosi double %57 to i32
  br label %59

59:                                               ; preds = %20, %18
  %.0 = phi i32 [ -1, %18 ], [ %58, %20 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS7RTDBdef", !11, i64 0, !11, i64 4, !7, i64 8, !11, i64 48, !7, i64 52, !11, i64 92, !7, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 12}
!14 = !{!"_ZTS4TRec", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 24}
!15 = !{!14, !11, i64 16}
!16 = !{!14, !11, i64 4}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTS7timeval", !19, i64 0, !19, i64 8}
!19 = !{!"long", !7, i64 0}
!20 = !{!18, !19, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass