; LLVM IR from ohler55/agoo :: ext/agoo (hook)

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

@.str = external hidden unnamed_addr constant [1 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_hook_func_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = call noalias ptr @malloc(i64 noundef 56) #5
  store ptr %13, ptr %10, align 8, !tbaa !9
  %14 = load ptr, ptr %10, align 8, !tbaa !9
  %15 = icmp ne ptr null, %14
  br i1 %15, label %16, label %58

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr null, ptr %11, align 8, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = icmp eq ptr null, %17
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = icmp ne i32 0, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = call noalias ptr @strdup(ptr noundef @.str) #4
  store ptr %23, ptr %11, align 8, !tbaa !9
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %26) #4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %55

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27, %19
  br label %36

29:                                               ; preds = %16
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = call noalias ptr @strdup(ptr noundef %30) #4
  store ptr %31, ptr %11, align 8, !tbaa !9
  %32 = icmp eq ptr null, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %34) #4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %55

35:                                               ; preds = %29
  br label %36

36:                                               ; preds = %35, %28
  %37 = load ptr, ptr %11, align 8, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct._agooHook, ptr %38, i32 0, i32 2
  store ptr %37, ptr %39, align 8, !tbaa !11
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct._agooHook, ptr %40, i32 0, i32 0
  store ptr null, ptr %41, align 8, !tbaa !14
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct._agooHook, ptr %43, i32 0, i32 1
  store i32 %42, ptr %44, align 8, !tbaa !15
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct._agooHook, ptr %46, i32 0, i32 4
  store ptr %45, ptr %47, align 8, !tbaa !16
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct._agooHook, ptr %48, i32 0, i32 3
  store i32 70, ptr %49, align 8, !tbaa !17
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct._agooHook, ptr %51, i32 0, i32 5
  store ptr %50, ptr %52, align 8, !tbaa !18
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct._agooHook, ptr %53, i32 0, i32 6
  store i8 0, ptr %54, align 8, !tbaa !19
  store i32 0, ptr %12, align 4
  br label %55

55:                                               ; preds = %36, %33, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %56 = load i32, ptr %12, align 4
  switch i32 %56, label %60 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57, %4
  %59 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %59, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %60

60:                                               ; preds = %58, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %61 = load ptr, ptr %5, align 8
  ret ptr %61
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_agooHook", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !7, i64 32, !10, i64 40, !13, i64 48}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !10, i64 40}
!19 = !{!12, !13, i64 48}


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

@.str = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local noalias noundef ptr @agoo_hook_func_create(i32 noundef %0, ptr noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.critedge, label %6

6:                                                ; preds = %4
  %7 = icmp eq ptr %1, null
  br i1 %7, label %8, label %13

8:                                                ; preds = %6
  %.not25 = icmp eq i32 %0, 0
  br i1 %.not25, label %17, label %9

9:                                                ; preds = %8
  %10 = tail call noalias ptr @strdup(ptr noundef nonnull @.str) #5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %5) #5
  br label %.critedge

13:                                               ; preds = %6
  %14 = tail call noalias ptr @strdup(ptr noundef nonnull %1) #5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @free(ptr noundef nonnull %5) #5
  br label %.critedge

17:                                               ; preds = %13, %8, %9
  %.019 = phi ptr [ %10, %9 ], [ null, %8 ], [ %14, %13 ]
  %18 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %.019, ptr %18, align 8, !tbaa !5
  store ptr null, ptr %5, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %0, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %5, i64 32
  store ptr %2, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 70, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %5, i64 40
  store ptr %3, ptr %22, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %5, i64 48
  store i8 0, ptr %23, align 8, !tbaa !17
  br label %.critedge

.critedge:                                        ; preds = %12, %16, %4, %17
  %.1 = phi ptr [ %5, %17 ], [ null, %4 ], [ null, %16 ], [ null, %12 ]
  ret ptr %.1
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #1 = { mustprogress nofree nounwind willreturn 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 #2 = { 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 #3 = { mustprogress nounwind willreturn 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 = { nounwind allocsize(0) }
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, !7, i64 16}
!6 = !{!"_agooHook", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !8, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !7, i64 40}
!17 = !{!6, !11, i64 48}


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