; LLVM IR from adventure-db/adventure :: src/repl (repl)

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

@cmds = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @repl(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = call ptr (...) @trie_create()
  store ptr %5, ptr @cmds, align 8, !tbaa !5
  call void (...) @register_cmds()
  call void @linenoiseSetCompletionCallback(ptr noundef @completion)
  call void @hello()
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call ptr @sdsnew(ptr noundef %6)
  store ptr %7, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %35, %18, %1
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call ptr @linenoise(ptr noundef %9)
  store ptr %10, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %37

12:                                               ; preds = %8
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  br label %8, !llvm.loop !10

19:                                               ; preds = %12
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i32 @repl_wants_exit(ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %37

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 @linenoiseHistoryAdd(ptr noundef %25)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i32 @repl_route_cmd(ptr noundef %27)
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %33

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %31)
  br label %33

33:                                               ; preds = %30, %24
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %36) #4
  br label %8, !llvm.loop !10

37:                                               ; preds = %23, %8
  call void @goodbye()
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sdsfree(ptr noundef %38)
  %39 = load ptr, ptr @cmds, align 8, !tbaa !5
  call void @trie_destroy(ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i32 0
}

declare ptr @trie_create(...) #1

declare void @register_cmds(...) #1

declare void @linenoiseSetCompletionCallback(ptr noundef) #1

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

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

declare ptr @sdsnew(ptr noundef) #1

declare ptr @linenoise(ptr noundef) #1

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

declare i32 @linenoiseHistoryAdd(ptr noundef) #1

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare void @sdsfree(ptr noundef) #1

declare void @trie_destroy(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @hello() #0

; Function Attrs: nounwind uwtable
declare hidden void @goodbye() #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 = { nocallback nofree nosync 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 = { 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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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

@cmds = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @repl(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr (...) @trie_create() #4
  store ptr %2, ptr @cmds, align 8, !tbaa !5
  tail call void (...) @register_cmds() #4
  tail call void @linenoiseSetCompletionCallback(ptr noundef nonnull @completion) #4
  tail call void @hello()
  %3 = tail call ptr @sdsnew(ptr noundef %0) #4
  %4 = tail call ptr @linenoise(ptr noundef %3) #4
  %.not10 = icmp eq ptr %4, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.backedge
  %5 = phi ptr [ %17, %.backedge ], [ %4, %1 ]
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %.backedge, label %8

8:                                                ; preds = %.lr.ph
  %9 = tail call i32 @repl_wants_exit(ptr noundef nonnull %5)
  %.not9 = icmp eq i32 %9, 0
  br i1 %.not9, label %10, label %._crit_edge

10:                                               ; preds = %8
  %11 = tail call i32 @linenoiseHistoryAdd(ptr noundef nonnull %5) #4
  %12 = tail call i32 @repl_route_cmd(ptr noundef nonnull %5)
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %5)
  br label %16

16:                                               ; preds = %14, %10
  tail call void @free(ptr noundef nonnull %5) #4
  br label %.backedge

.backedge:                                        ; preds = %16, %.lr.ph
  %17 = tail call ptr @linenoise(ptr noundef %3) #4
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.backedge, %8, %1
  tail call void @goodbye()
  tail call void @sdsfree(ptr noundef %3) #4
  %18 = load ptr, ptr @cmds, align 8, !tbaa !5
  tail call void @trie_destroy(ptr noundef %18) #4
  ret i32 0
}

declare ptr @trie_create(...) local_unnamed_addr #1

declare void @register_cmds(...) local_unnamed_addr #1

declare void @linenoiseSetCompletionCallback(ptr noundef) local_unnamed_addr #1

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

declare ptr @sdsnew(ptr noundef) local_unnamed_addr #1

declare ptr @linenoise(ptr noundef) local_unnamed_addr #1

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

declare i32 @linenoiseHistoryAdd(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

declare void @sdsfree(ptr noundef) local_unnamed_addr #1

declare void @trie_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @hello() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @goodbye() local_unnamed_addr #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 = { 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass