; LLVM IR from Siskin-framework/Rebol-SQLite :: src (sqlite-command-trace)

; 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.rxi_cmd_frame = type { [8 x %union.rxi_arg_val] }
%union.rxi_arg_val = type { %struct.anon.3 }
%struct.anon.3 = type { %union.anon, i32, i32 }
%union.anon = type { ptr }
%struct.Reb_Handle_Context = type { %union.anon.5, i32, i32, ptr }
%union.anon.5 = type { ptr }
%struct.anon.1 = type <{ ptr, i32 }>
%struct.reb_sqlite_context = type { ptr, ptr, i32, i32 }

@Handle_SQLiteDB = external global i32, align 4
@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @cmd_sqlite_trace(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %11, i64 0, i64 1
  %13 = getelementptr inbounds %struct.anon.3, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 4, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Reb_Handle_Context, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 4, !tbaa !9
  store ptr %17, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %26

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Reb_Handle_Context, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %24 = load i32, ptr @Handle_SQLiteDB, align 4, !tbaa !13
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %20, %2
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %29, i64 0, i64 1
  %31 = getelementptr inbounds %struct.anon.1, ptr %30, i32 0, i32 0
  store ptr @.str, ptr %31, align 4, !tbaa !9
  store i32 6, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %56

32:                                               ; No predecessors!
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33, %20
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %55

37:                                               ; preds = %34
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.reb_sqlite_context, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %55

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %44, i64 0, i64 2
  %46 = load i64, ptr %45, align 4, !tbaa !9
  %47 = and i64 %46, 15
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %8, align 4, !tbaa !13
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.reb_sqlite_context, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %8, align 4, !tbaa !13
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i32 @sqlite3_trace_v2(ptr noundef %51, i32 noundef %52, ptr noundef @trace_callback, ptr noundef %53)
  br label %55

55:                                               ; preds = %42, %37, %34
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

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

declare i32 @sqlite3_trace_v2(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @trace_callback(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 }

!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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 8}
!11 = !{!"Reb_Handle_Context", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 14, !6, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"reb_sqlite_context", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20}


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

@Handle_SQLiteDB = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 7) i32 @cmd_sqlite_trace(ptr nocapture noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 4, !tbaa !5
  %5 = load ptr, ptr %4, align 4, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %10, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load i32, ptr %7, align 4, !tbaa !8
  %9 = load i32, ptr @Handle_SQLiteDB, align 4, !tbaa !12
  %.not13 = icmp eq i32 %8, %9
  br i1 %.not13, label %11, label %10

10:                                               ; preds = %2, %6
  store ptr @.str, ptr %3, align 4, !tbaa !5
  br label %19

11:                                               ; preds = %6
  %12 = load ptr, ptr %5, align 8, !tbaa !13
  %.not14 = icmp eq ptr %12, null
  br i1 %.not14, label %19, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %14, align 4, !tbaa !5
  %16 = trunc i64 %15 to i32
  %17 = and i32 %16, 15
  %18 = tail call i32 @sqlite3_trace_v2(ptr noundef nonnull %12, i32 noundef %17, ptr noundef nonnull @trace_callback, ptr noundef nonnull %5) #2
  br label %19

19:                                               ; preds = %11, %13, %10
  %.0 = phi i32 [ 6, %10 ], [ 0, %13 ], [ 0, %11 ]
  ret i32 %.0
}

declare i32 @sqlite3_trace_v2(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @trace_callback(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #0

attributes #0 = { 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 #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"Reb_Handle_Context", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 14, !11, i64 16}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"reb_sqlite_context", !11, i64 0, !11, i64 8, !10, i64 16, !10, i64 20}


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