; LLVM IR from NTHU-LSALAB/Gemini :: src (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.hookInfo = type <{ i32, [4 x i8], [27 x ptr], [27 x ptr], [27 x i32], [4 x i8] }>

@_ZL8hook_inf = external hidden global %struct.hookInfo, align 8
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@_ZL9init_done = external hidden global i32, align 4
@_ZZ18cuArray3DCreate_v2E9real_func = external hidden global ptr, align 8
@_ZGVZ18cuArray3DCreate_v2E9real_func = external hidden global i64, align 8

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef, ptr noundef) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local i32 @cuArray3DCreate_v2(ptr noundef %0, ptr noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %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
  %10 = call i32 @pthread_once(ptr noundef @_ZL9init_done, ptr noundef @_Z10initializev)
  %11 = load atomic i8, ptr @_ZGVZ18cuArray3DCreate_v2E9real_func acquire, align 8
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %13, label %19, !prof !9

13:                                               ; preds = %2
  %14 = call i32 @__cxa_guard_acquire(ptr @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = invoke noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef inttoptr (i64 -1 to ptr), ptr noundef @.str.7)
          to label %18 unwind label %25

18:                                               ; preds = %16
  store ptr %17, ptr @_ZZ18cuArray3DCreate_v2E9real_func, align 8, !tbaa !5
  call void @__cxa_guard_release(ptr @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  br label %19

19:                                               ; preds = %18, %13, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !10
  %20 = load i32, ptr @_ZL8hook_inf, align 8, !tbaa !12
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  %23 = load i32, ptr getelementptr inbounds ([27 x i32], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 4), i64 0, i64 5), align 4, !tbaa !15
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr getelementptr inbounds ([27 x i32], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 4), i64 0, i64 5), align 4, !tbaa !15
  br label %29

25:                                               ; preds = %16
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %6, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %7, align 4
  call void @__cxa_guard_abort(ptr @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  br label %61

29:                                               ; preds = %22, %19
  %30 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 2), i64 0, i64 5), align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %37

32:                                               ; preds = %29
  %33 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 2), i64 0, i64 5), align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call noundef i32 %33(ptr noundef %34, ptr noundef %35)
  store i32 %36, ptr %8, align 4, !tbaa !10
  br label %37

37:                                               ; preds = %32, %29
  %38 = load i32, ptr %8, align 4, !tbaa !10
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %37
  %41 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %41, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %59

42:                                               ; preds = %37
  %43 = load ptr, ptr @_ZZ18cuArray3DCreate_v2E9real_func, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call noundef i32 %43(ptr noundef %44, ptr noundef %45)
  store i32 %46, ptr %8, align 4, !tbaa !10
  %47 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 3), i64 0, i64 5), align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %57

49:                                               ; preds = %42
  %50 = load i32, ptr %8, align 4, !tbaa !10
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %57

52:                                               ; preds = %49
  %53 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 3), i64 0, i64 5), align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = call noundef i32 %53(ptr noundef %54, ptr noundef %55)
  store i32 %56, ptr %8, align 4, !tbaa !10
  br label %57

57:                                               ; preds = %52, %49, %42
  %58 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %59

59:                                               ; preds = %57, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %60 = load i32, ptr %3, align 4
  ret i32 %60

61:                                               ; preds = %25
  %62 = load ptr, ptr %6, align 8
  %63 = load i32, ptr %7, align 4
  %64 = insertvalue { ptr, i32 } poison, ptr %62, 0
  %65 = insertvalue { ptr, i32 } %64, i32 %63, 1
  resume { ptr, i32 } %65
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10initializev() #0

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

; Function Attrs: nounwind
declare i32 @__cxa_guard_acquire(ptr) #3

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

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

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!"branch_weights", i32 1, i32 1048575}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTS14cudaError_enum", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS8hookInfo", !14, i64 0, !7, i64 8, !7, i64 224, !7, i64 440}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}


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

%struct.hookInfo = type <{ i32, [4 x i8], [27 x ptr], [27 x ptr], [27 x i32], [4 x i8] }>

@_ZL8hook_inf = external hidden local_unnamed_addr global %struct.hookInfo, align 8
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@_ZL9init_done = external hidden global i32, align 4
@_ZZ18cuArray3DCreate_v2E9real_func = external hidden local_unnamed_addr global ptr, align 8
@_ZGVZ18cuArray3DCreate_v2E9real_func = external hidden global i64, align 8

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @cuArray3DCreate_v2(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = tail call i32 @pthread_once(ptr noundef nonnull @_ZL9init_done, ptr noundef nonnull @_Z10initializev)
  %4 = load atomic i8, ptr @_ZGVZ18cuArray3DCreate_v2E9real_func acquire, align 8
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %11, !prof !5

6:                                                ; preds = %2
  %7 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %6
  %9 = invoke noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull @.str.7)
          to label %10 unwind label %16

10:                                               ; preds = %8
  store ptr %9, ptr @_ZZ18cuArray3DCreate_v2E9real_func, align 8, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  br label %11

11:                                               ; preds = %10, %6, %2
  %12 = load i32, ptr @_ZL8hook_inf, align 8, !tbaa !10
  %.not16 = icmp eq i32 %12, 0
  br i1 %.not16, label %18, label %13

13:                                               ; preds = %11
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 460), align 4, !tbaa !13
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 460), align 4, !tbaa !13
  br label %18

16:                                               ; preds = %8
  %17 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_guard_abort(ptr nonnull @_ZGVZ18cuArray3DCreate_v2E9real_func) #3
  resume { ptr, i32 } %17

18:                                               ; preds = %13, %11
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 48), align 8, !tbaa !6
  %.not17 = icmp eq ptr %19, null
  br i1 %.not17, label %.thread, label %20

20:                                               ; preds = %18
  %21 = tail call noundef i32 %19(ptr noundef %0, ptr noundef %1)
  %.not18 = icmp eq i32 %21, 0
  br i1 %.not18, label %.thread, label %29

.thread:                                          ; preds = %18, %20
  %22 = load ptr, ptr @_ZZ18cuArray3DCreate_v2E9real_func, align 8, !tbaa !6
  %23 = tail call noundef i32 %22(ptr noundef %0, ptr noundef %1)
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 264), align 8, !tbaa !6
  %25 = icmp ne ptr %24, null
  %26 = icmp eq i32 %23, 0
  %or.cond = and i1 %26, %25
  br i1 %or.cond, label %27, label %29

27:                                               ; preds = %.thread
  %28 = tail call noundef i32 %24(ptr noundef %0, ptr noundef %1)
  br label %29

29:                                               ; preds = %.thread, %27, %20
  %.013 = phi i32 [ %21, %20 ], [ %28, %27 ], [ %23, %.thread ]
  ret i32 %.013
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10initializev() #0

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

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @__cxa_guard_abort(ptr) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #2

attributes #0 = { mustprogress 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 }
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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS8hookInfo", !12, i64 0, !8, i64 8, !8, i64 224, !8, i64 440}
!12 = !{!"int", !8, i64 0}
!13 = !{!12, !12, i64 0}


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