; 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.11 = external hidden unnamed_addr constant [15 x i8], align 1
@_ZL9init_done = external hidden global i32, align 4
@_ZZ14cuLaunchKernelE9real_func = external hidden global ptr, align 8
@_ZGVZ14cuLaunchKernelE9real_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 @cuLaunchKernel(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10) #0 personality ptr @__gxx_personality_v0 {
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  store ptr %0, ptr %13, align 8, !tbaa !5
  store i32 %1, ptr %14, align 4, !tbaa !9
  store i32 %2, ptr %15, align 4, !tbaa !9
  store i32 %3, ptr %16, align 4, !tbaa !9
  store i32 %4, ptr %17, align 4, !tbaa !9
  store i32 %5, ptr %18, align 4, !tbaa !9
  store i32 %6, ptr %19, align 4, !tbaa !9
  store i32 %7, ptr %20, align 4, !tbaa !9
  store ptr %8, ptr %21, align 8, !tbaa !5
  store ptr %9, ptr %22, align 8, !tbaa !5
  store ptr %10, ptr %23, align 8, !tbaa !5
  %28 = call i32 @pthread_once(ptr noundef @_ZL9init_done, ptr noundef @_Z10initializev)
  %29 = load atomic i8, ptr @_ZGVZ14cuLaunchKernelE9real_func acquire, align 8
  %30 = icmp eq i8 %29, 0
  br i1 %30, label %31, label %37, !prof !11

31:                                               ; preds = %11
  %32 = call i32 @__cxa_guard_acquire(ptr @_ZGVZ14cuLaunchKernelE9real_func) #3
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = invoke noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef inttoptr (i64 -1 to ptr), ptr noundef @.str.11)
          to label %36 unwind label %43

36:                                               ; preds = %34
  store ptr %35, ptr @_ZZ14cuLaunchKernelE9real_func, align 8, !tbaa !5
  call void @__cxa_guard_release(ptr @_ZGVZ14cuLaunchKernelE9real_func) #3
  br label %37

37:                                               ; preds = %36, %31, %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #3
  store i32 0, ptr %26, align 4, !tbaa !12
  %38 = load i32, ptr @_ZL8hook_inf, align 8, !tbaa !14
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %37
  %41 = load i32, ptr getelementptr inbounds ([27 x i32], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 4), i64 0, i64 18), align 8, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr getelementptr inbounds ([27 x i32], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 4), i64 0, i64 18), align 8, !tbaa !9
  br label %47

43:                                               ; preds = %34
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %24, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %25, align 4
  call void @__cxa_guard_abort(ptr @_ZGVZ14cuLaunchKernelE9real_func) #3
  br label %106

47:                                               ; preds = %40, %37
  %48 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 2), i64 0, i64 18), align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %64

50:                                               ; preds = %47
  %51 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 2), i64 0, i64 18), align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = load i32, ptr %16, align 4, !tbaa !9
  %56 = load i32, ptr %17, align 4, !tbaa !9
  %57 = load i32, ptr %18, align 4, !tbaa !9
  %58 = load i32, ptr %19, align 4, !tbaa !9
  %59 = load i32, ptr %20, align 4, !tbaa !9
  %60 = load ptr, ptr %21, align 8, !tbaa !5
  %61 = load ptr, ptr %22, align 8, !tbaa !5
  %62 = load ptr, ptr %23, align 8, !tbaa !5
  %63 = call noundef i32 %51(ptr noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59, ptr noundef %60, ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %26, align 4, !tbaa !12
  br label %64

64:                                               ; preds = %50, %47
  %65 = load i32, ptr %26, align 4, !tbaa !12
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %64
  %68 = load i32, ptr %26, align 4, !tbaa !12
  store i32 %68, ptr %12, align 4
  store i32 1, ptr %27, align 4
  br label %104

69:                                               ; preds = %64
  %70 = load ptr, ptr @_ZZ14cuLaunchKernelE9real_func, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = load i32, ptr %15, align 4, !tbaa !9
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = load i32, ptr %17, align 4, !tbaa !9
  %76 = load i32, ptr %18, align 4, !tbaa !9
  %77 = load i32, ptr %19, align 4, !tbaa !9
  %78 = load i32, ptr %20, align 4, !tbaa !9
  %79 = load ptr, ptr %21, align 8, !tbaa !5
  %80 = load ptr, ptr %22, align 8, !tbaa !5
  %81 = load ptr, ptr %23, align 8, !tbaa !5
  %82 = call noundef i32 %70(ptr noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75, i32 noundef %76, i32 noundef %77, i32 noundef %78, ptr noundef %79, ptr noundef %80, ptr noundef %81)
  store i32 %82, ptr %26, align 4, !tbaa !12
  %83 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 3), i64 0, i64 18), align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %102

85:                                               ; preds = %69
  %86 = load i32, ptr %26, align 4, !tbaa !12
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %102

88:                                               ; preds = %85
  %89 = load ptr, ptr getelementptr inbounds ([27 x ptr], ptr getelementptr inbounds (%struct.hookInfo, ptr @_ZL8hook_inf, i32 0, i32 3), i64 0, i64 18), align 8, !tbaa !5
  %90 = load ptr, ptr %13, align 8, !tbaa !5
  %91 = load i32, ptr %14, align 4, !tbaa !9
  %92 = load i32, ptr %15, align 4, !tbaa !9
  %93 = load i32, ptr %16, align 4, !tbaa !9
  %94 = load i32, ptr %17, align 4, !tbaa !9
  %95 = load i32, ptr %18, align 4, !tbaa !9
  %96 = load i32, ptr %19, align 4, !tbaa !9
  %97 = load i32, ptr %20, align 4, !tbaa !9
  %98 = load ptr, ptr %21, align 8, !tbaa !5
  %99 = load ptr, ptr %22, align 8, !tbaa !5
  %100 = load ptr, ptr %23, align 8, !tbaa !5
  %101 = call noundef i32 %89(ptr noundef %90, i32 noundef %91, i32 noundef %92, i32 noundef %93, i32 noundef %94, i32 noundef %95, i32 noundef %96, i32 noundef %97, ptr noundef %98, ptr noundef %99, ptr noundef %100)
  store i32 %101, ptr %26, align 4, !tbaa !12
  br label %102

102:                                              ; preds = %88, %85, %69
  %103 = load i32, ptr %26, align 4, !tbaa !12
  store i32 %103, ptr %12, align 4
  store i32 1, ptr %27, align 4
  br label %104

104:                                              ; preds = %102, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #3
  %105 = load i32, ptr %12, align 4
  ret i32 %105

106:                                              ; preds = %43
  %107 = load ptr, ptr %24, align 8
  %108 = load i32, ptr %25, align 4
  %109 = insertvalue { ptr, i32 } poison, ptr %107, 0
  %110 = insertvalue { ptr, i32 } %109, i32 %108, 1
  resume { ptr, i32 } %110
}

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


; 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.11 = external hidden unnamed_addr constant [15 x i8], align 1
@_ZL9init_done = external hidden global i32, align 4
@_ZZ14cuLaunchKernelE9real_func = external hidden local_unnamed_addr global ptr, align 8
@_ZGVZ14cuLaunchKernelE9real_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 @cuLaunchKernel(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %12 = tail call i32 @pthread_once(ptr noundef nonnull @_ZL9init_done, ptr noundef nonnull @_Z10initializev)
  %13 = load atomic i8, ptr @_ZGVZ14cuLaunchKernelE9real_func acquire, align 8
  %14 = icmp eq i8 %13, 0
  br i1 %14, label %15, label %20, !prof !5

15:                                               ; preds = %11
  %16 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ14cuLaunchKernelE9real_func) #3
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %20, label %17

17:                                               ; preds = %15
  %18 = invoke noundef ptr @_ZL10real_dlsymPvPKc(ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull @.str.11)
          to label %19 unwind label %25

19:                                               ; preds = %17
  store ptr %18, ptr @_ZZ14cuLaunchKernelE9real_func, align 8, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ14cuLaunchKernelE9real_func) #3
  br label %20

20:                                               ; preds = %19, %15, %11
  %21 = load i32, ptr @_ZL8hook_inf, align 8, !tbaa !10
  %.not43 = icmp eq i32 %21, 0
  br i1 %.not43, label %27, label %22

22:                                               ; preds = %20
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 512), align 8, !tbaa !13
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 512), align 8, !tbaa !13
  br label %27

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

27:                                               ; preds = %22, %20
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 152), align 8, !tbaa !6
  %.not44 = icmp eq ptr %28, null
  br i1 %.not44, label %.thread, label %29

29:                                               ; preds = %27
  %30 = tail call noundef i32 %28(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10)
  %.not45 = icmp eq i32 %30, 0
  br i1 %.not45, label %.thread, label %38

.thread:                                          ; preds = %27, %29
  %31 = load ptr, ptr @_ZZ14cuLaunchKernelE9real_func, align 8, !tbaa !6
  %32 = tail call noundef i32 %31(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10)
  %33 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZL8hook_inf, i64 368), align 8, !tbaa !6
  %34 = icmp ne ptr %33, null
  %35 = icmp eq i32 %32, 0
  %or.cond = and i1 %35, %34
  br i1 %or.cond, label %36, label %38

36:                                               ; preds = %.thread
  %37 = tail call noundef i32 %33(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10)
  br label %38

38:                                               ; preds = %.thread, %36, %29
  %.040 = phi i32 [ %30, %29 ], [ %37, %36 ], [ %32, %.thread ]
  ret i32 %.040
}

; 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