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

; 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__._Z9DB_put_iniiiPvi = external hidden unnamed_addr constant [10 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: mustprogress uwtable
define dso_local noundef i32 @_Z9DB_put_iniiiPvi(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca %struct.timeval, align 8
  %17 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x ptr], ptr @p_def, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.RTDBdef, ptr %21, i32 0, i32 6
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10 x [100 x i32]], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100 x i32], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %12, align 4, !tbaa !5
  %30 = icmp eq i32 %29, -1
  br i1 %30, label %31, label %35

31:                                               ; preds = %5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, ptr noundef @.str.4, ptr noundef @__FUNCTION__._Z9DB_put_iniiiPvi, i32 noundef %32, i32 noundef %33)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %117

35:                                               ; preds = %5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 100
  br i1 %37, label %38, label %50

38:                                               ; preds = %35
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10 x [10 x ptr]], ptr @p_shared_mem, i64 0, i64 %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10 x ptr], ptr %41, i64 0, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = mul i64 %47, 56
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  store ptr %49, ptr %13, align 8, !tbaa !9
  br label %60

50:                                               ; preds = %35
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10 x ptr], ptr @p_local_mem, i64 0, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 100
  %57 = sext i32 %56 to i64
  %58 = mul i64 %57, 56
  %59 = getelementptr inbounds i8, ptr %54, i64 %58
  store ptr %59, ptr %13, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %50, %38
  %61 = load ptr, ptr %13, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.TRec, ptr %61, i32 0, i32 4
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = add nsw i32 %63, 1
  %65 = srem i32 %64, 2
  store i32 %65, ptr %15, align 4, !tbaa !5
  %66 = load ptr, ptr %13, align 8, !tbaa !9
  %67 = load ptr, ptr %13, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.TRec, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %66, i64 %70
  %72 = load i32, ptr %15, align 4, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.TRec, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !14
  %76 = mul nsw i32 %72, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %71, i64 %77
  store ptr %78, ptr %14, align 8, !tbaa !9
  %79 = load ptr, ptr %14, align 8, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = load ptr, ptr %13, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.TRec, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !14
  %84 = sext i32 %83 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %79, ptr align 1 %80, i64 %84, i1 false)
  %85 = call i32 @gettimeofday(ptr noundef %16, ptr noundef null) #5
  %86 = getelementptr inbounds %struct.timeval, ptr %16, i32 0, i32 0
  %87 = load i64, ptr %86, align 8, !tbaa !15
  %88 = load i32, ptr %11, align 4, !tbaa !5
  %89 = sdiv i32 %88, 1000
  %90 = sext i32 %89 to i64
  %91 = sub nsw i64 %87, %90
  %92 = load ptr, ptr %13, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.TRec, ptr %92, i32 0, i32 5
  %94 = load i32, ptr %15, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2 x %struct.timeval], ptr %93, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.timeval, ptr %96, i32 0, i32 0
  store i64 %91, ptr %97, align 8, !tbaa !15
  %98 = getelementptr inbounds %struct.timeval, ptr %16, i32 0, i32 1
  %99 = load i64, ptr %98, align 8, !tbaa !18
  %100 = load i32, ptr %11, align 4, !tbaa !5
  %101 = srem i32 %100, 1000
  %102 = mul nsw i32 %101, 1000
  %103 = sext i32 %102 to i64
  %104 = sub nsw i64 %99, %103
  %105 = load ptr, ptr %13, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct.TRec, ptr %105, i32 0, i32 5
  %107 = load i32, ptr %15, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [2 x %struct.timeval], ptr %106, i64 0, i64 %108
  %110 = getelementptr inbounds %struct.timeval, ptr %109, i32 0, i32 1
  store i64 %104, ptr %110, align 8, !tbaa !18
  %111 = load i32, ptr %15, align 4, !tbaa !5
  %112 = load ptr, ptr %13, align 8, !tbaa !9
  %113 = getelementptr inbounds %struct.TRec, ptr %112, i32 0, i32 4
  store i32 %111, ptr %113, align 8, !tbaa !11
  %114 = load ptr, ptr %13, align 8, !tbaa !9
  %115 = getelementptr inbounds %struct.TRec, ptr %114, i32 0, i32 1
  %116 = load i32, ptr %115, align 4, !tbaa !14
  store i32 %116, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %117

117:                                              ; preds = %60, %31
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %118 = load i32, ptr %6, align 4
  ret i32 %118
}

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

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

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 = { 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 nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS4TRec", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !7, i64 24}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !6, i64 4}
!15 = !{!16, !17, i64 0}
!16 = !{!"_ZTS7timeval", !17, i64 0, !17, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !17, 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__._Z9DB_put_iniiiPvi = external hidden unnamed_addr constant [10 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 nofree nounwind uwtable
define dso_local noundef i32 @_Z9DB_put_iniiiPvi(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  %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
  %10 = getelementptr inbounds i8, ptr %9, i64 96
  %11 = sext i32 %1 to i64
  %12 = sext i32 %2 to i64
  %13 = getelementptr inbounds [10 x [100 x i32]], ptr %10, i64 0, i64 %11, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %5
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, ptr noundef nonnull @.str.4, ptr noundef nonnull @__FUNCTION__._Z9DB_put_iniiiPvi, i32 noundef %2, i32 noundef %1)
  br label %57

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

57:                                               ; preds = %18, %16
  %.0 = phi i32 [ -1, %16 ], [ %56, %18 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  ret i32 %.0
}

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

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

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 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS4TRec", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !17, i64 0}
!16 = !{!"_ZTS7timeval", !17, i64 0, !17, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !17, i64 8}


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