; 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: nounwind uwtable
define dso_local ptr @agoo_hook_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %15 = call noalias ptr @malloc(i64 noundef 56) #5
  store ptr %15, ptr %12, align 8, !tbaa !9
  %16 = load ptr, ptr %12, align 8, !tbaa !9
  %17 = icmp ne ptr null, %16
  br i1 %17, label %18, label %61

18:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store ptr null, ptr %13, align 8, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %31

21:                                               ; preds = %18
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = icmp ne i32 0, %22
  br i1 %23, label %24, label %30

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

27:                                               ; preds = %24
  %28 = load ptr, ptr %12, align 8, !tbaa !9
  call void @free(ptr noundef %28) #4
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %58

29:                                               ; preds = %24
  br label %30

30:                                               ; preds = %29, %21
  br label %38

31:                                               ; preds = %18
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = call noalias ptr @strdup(ptr noundef %32) #4
  store ptr %33, ptr %13, align 8, !tbaa !9
  %34 = icmp eq ptr null, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load ptr, ptr %12, align 8, !tbaa !9
  call void @free(ptr noundef %36) #4
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %58

37:                                               ; preds = %31
  br label %38

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

58:                                               ; preds = %38, %35, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %59 = load i32, ptr %14, align 4
  switch i32 %59, label %63 [
    i32 0, label %60
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60, %5
  %62 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %62, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %63

63:                                               ; preds = %61, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %64 = load ptr, ptr %6, align 8
  ret ptr %64
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

; 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 = { 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 #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 }
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 nounwind willreturn uwtable
define dso_local noalias noundef ptr @agoo_hook_create(i32 noundef %0, ptr noundef readonly %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #4
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %5
  %8 = icmp eq ptr %1, null
  br i1 %8, label %9, label %14

9:                                                ; preds = %7
  %.not26 = icmp eq i32 %0, 0
  br i1 %.not26, label %18, label %10

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

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

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

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

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

.critedge:                                        ; preds = %13, %17, %5, %18
  %.1 = phi ptr [ %6, %18 ], [ null, %5 ], [ null, %17 ], [ null, %13 ]
  ret ptr %.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 #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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 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