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

; 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 }
%struct.Reb_Series = type { ptr, i32, i32, i32, i32, %union.anon.6 }
%union.anon.6 = type { ptr }

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

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

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

28:                                               ; preds = %22, %2
  br label %29

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

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35, %22
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %38, i64 0, i64 2
  %40 = getelementptr inbounds { ptr, i64 }, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 4
  %42 = getelementptr inbounds { ptr, i64 }, ptr %39, i32 0, i32 1
  %43 = load i64, ptr %42, align 4
  %44 = call ptr @utf8_string(ptr %41, i64 %43)
  store ptr %44, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.reb_sqlite_context, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  store ptr %47, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Reb_Series, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 4, !tbaa !16
  %52 = call i32 @sqlite3_exec(ptr noundef %48, ptr noundef %51, ptr noundef @callback, ptr noundef null, ptr noundef null)
  store i32 %52, ptr %10, align 4, !tbaa !13
  %53 = load i32, ptr %10, align 4, !tbaa !13
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %65

55:                                               ; preds = %36
  %56 = load i32, ptr %10, align 4, !tbaa !13
  %57 = call ptr @sqlite3_errstr(i32 noundef %56)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = call ptr @sqlite3_errmsg(ptr noundef %58)
  %60 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef @error_buffer, i64 noundef 254, ptr noundef @.str.1, ptr noundef %57, ptr noundef %59) #4
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.rxi_cmd_frame, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds [8 x %union.rxi_arg_val], ptr %62, i64 0, i64 1
  %64 = getelementptr inbounds %struct.anon.1, ptr %63, i32 0, i32 0
  store ptr @error_buffer, ptr %64, align 4, !tbaa !9
  store i32 6, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %66

65:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %66

66:                                               ; preds = %65, %55, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %67 = load i32, ptr %3, align 4
  ret i32 %67
}

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

declare ptr @utf8_string(ptr, i64) #2

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

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

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

declare ptr @sqlite3_errstr(i32 noundef) #2

declare ptr @sqlite3_errmsg(ptr noundef) #2

; 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 "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 = !{!"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}
!16 = !{!17, !6, i64 0}
!17 = !{!"Reb_Series", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24}


; 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
@error_buffer = external global [255 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 7) i32 @cmd_sqlite_exec(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 %.sink.split, 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
  %.not15 = icmp eq i32 %8, %9
  br i1 %.not15, label %10, label %.sink.split

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = load ptr, ptr %11, align 4
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load i64, ptr %13, align 4
  %15 = tail call ptr @utf8_string(ptr %12, i64 %14) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !13
  %17 = load ptr, ptr %15, align 4, !tbaa !15
  %18 = tail call i32 @sqlite3_exec(ptr noundef %16, ptr noundef %17, ptr noundef nonnull @callback, ptr noundef null, ptr noundef null) #3
  %.not16 = icmp eq i32 %18, 0
  br i1 %.not16, label %23, label %19

19:                                               ; preds = %10
  %20 = tail call ptr @sqlite3_errstr(i32 noundef %18) #3
  %21 = tail call ptr @sqlite3_errmsg(ptr noundef %16) #3
  %22 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) @error_buffer, i64 noundef 254, ptr noundef nonnull @.str.1, ptr noundef %20, ptr noundef %21) #3
  br label %.sink.split

.sink.split:                                      ; preds = %6, %2, %19
  %error_buffer.sink = phi ptr [ @error_buffer, %19 ], [ @.str, %2 ], [ @.str, %6 ]
  store ptr %error_buffer.sink, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.sink.split, %10
  %.0 = phi i32 [ 0, %10 ], [ 6, %.sink.split ]
  ret i32 %.0
}

declare ptr @utf8_string(ptr, i64) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @sqlite3_errstr(i32 noundef) local_unnamed_addr #1

declare ptr @sqlite3_errmsg(ptr noundef) local_unnamed_addr #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 = { "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 = { 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 #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 = !{!"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}
!15 = !{!16, !11, i64 0}
!16 = !{!"Reb_Series", !11, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24}


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