; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_log)

; 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.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleLog = type { i32, [128 x i8], [128 x i8], [16 x i8], i64, i32, i32, %struct.MThreadSignal, i32, i32, i32, i32, ptr, i32, i32, i32, ptr, ptr }
%struct.MThreadSignal = type { %union.pthread_mutex_t, %union.pthread_cond_t, %union.pthread_rwlock_t, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local void @endLog(ptr noundef) #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @LogFunction(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %8 = call ptr @GetHandle(ptr noundef %7, i32 noundef 504, i32 noundef 1060628209, ptr noundef @endLog)
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MHandle, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %32

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HandleLog, ptr %15, i32 0, i32 15
  store i32 0, ptr %16, align 8, !tbaa !12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.HandleLog, ptr %17, i32 0, i32 13
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %27, label %21

21:                                               ; preds = %14
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.HandleLog, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = icmp ne i32 %24, 0
  %26 = xor i1 %25, true
  br label %27

27:                                               ; preds = %21, %14
  %28 = phi i1 [ true, %14 ], [ %26, %21 ]
  %29 = zext i1 %28 to i32
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HandleLog, ptr %30, i32 0, i32 14
  store i32 %29, ptr %31, align 4, !tbaa !18
  store i32 1, ptr %5, align 4
  br label %67

32:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %55

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleLog, ptr %38, i32 0, i32 15
  store i32 0, ptr %39, align 8, !tbaa !12
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.HandleLog, ptr %40, i32 0, i32 13
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %50, label %44

44:                                               ; preds = %37
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.HandleLog, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !17
  %48 = icmp ne i32 %47, 0
  %49 = xor i1 %48, true
  br label %50

50:                                               ; preds = %44, %37
  %51 = phi i1 [ true, %37 ], [ %49, %44 ]
  %52 = zext i1 %51 to i32
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.HandleLog, ptr %53, i32 0, i32 14
  store i32 %52, ptr %54, align 4, !tbaa !18
  store i32 1, ptr %5, align 4
  br label %66

55:                                               ; preds = %32
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.HandleLog, ptr %57, i32 0, i32 16
  store ptr %56, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.HandleLog, ptr %59, i32 0, i32 15
  store i32 1, ptr %60, align 8, !tbaa !12
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.HandleLog, ptr %61, i32 0, i32 13
  %63 = load i32, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.HandleLog, ptr %64, i32 0, i32 14
  store i32 %63, ptr %65, align 4, !tbaa !18
  store i32 0, ptr %5, align 4
  br label %66

66:                                               ; preds = %55, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %67

67:                                               ; preds = %66, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %68 = load i32, ptr %5, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
    i32 1, label %69
  ]

69:                                               ; preds = %67, %67
  ret void

70:                                               ; preds = %67
  unreachable
}

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 = { "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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"MHandle", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 480}
!13 = !{!"HandleLog", !11, i64 0, !7, i64 4, !7, i64 132, !7, i64 260, !14, i64 280, !11, i64 288, !11, i64 292, !15, i64 296, !11, i64 448, !11, i64 452, !11, i64 456, !11, i64 460, !6, i64 464, !11, i64 472, !11, i64 476, !11, i64 480, !6, i64 488, !6, i64 496}
!14 = !{!"long", !7, i64 0}
!15 = !{!"MThreadSignal", !7, i64 0, !7, i64 40, !7, i64 88, !11, i64 144}
!16 = !{!13, !11, i64 472}
!17 = !{!13, !11, i64 0}
!18 = !{!13, !11, i64 476}
!19 = !{!13, !6, i64 488}


; 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 [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @endLog(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @LogFunction(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #2
  %3 = tail call ptr @GetHandle(ptr noundef %2, i32 noundef 504, i32 noundef 1060628209, ptr noundef nonnull @endLog) #2
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %0, null
  br i1 %6, label %7, label %14

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %5, i64 480
  store i32 0, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %5, i64 472
  %10 = load i32, ptr %9, align 8, !tbaa !15
  %.not19 = icmp eq i32 %10, 0
  br i1 %.not19, label %11, label %29

11:                                               ; preds = %7
  %12 = load i32, ptr %5, align 8, !tbaa !16
  %.not20 = icmp eq i32 %12, 0
  %13 = zext i1 %.not20 to i32
  br label %29

14:                                               ; preds = %1
  %15 = load ptr, ptr %0, align 8, !tbaa !17
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %24

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %5, i64 480
  store i32 0, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %5, i64 472
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %29

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 8, !tbaa !16
  %.not18 = icmp eq i32 %22, 0
  %23 = zext i1 %.not18 to i32
  br label %29

24:                                               ; preds = %14
  %25 = getelementptr inbounds i8, ptr %5, i64 488
  store ptr %15, ptr %25, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %5, i64 480
  store i32 1, ptr %26, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %5, i64 472
  %28 = load i32, ptr %27, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %17, %21, %7, %11, %24
  %.sink = phi i32 [ %28, %24 ], [ 1, %7 ], [ %13, %11 ], [ 1, %17 ], [ %23, %21 ]
  %30 = getelementptr inbounds i8, ptr %5, i64 476
  store i32 %.sink, ptr %30, align 4, !tbaa !19
  ret void
}

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 = { 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, !10, i64 16}
!6 = !{!"MHandle", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 480}
!12 = !{!"HandleLog", !7, i64 0, !8, i64 4, !8, i64 132, !8, i64 260, !13, i64 280, !7, i64 288, !7, i64 292, !14, i64 296, !7, i64 448, !7, i64 452, !7, i64 456, !7, i64 460, !10, i64 464, !7, i64 472, !7, i64 476, !7, i64 480, !10, i64 488, !10, i64 496}
!13 = !{!"long", !8, i64 0}
!14 = !{!"MThreadSignal", !8, i64 0, !8, i64 40, !8, i64 88, !7, i64 144}
!15 = !{!12, !7, i64 472}
!16 = !{!12, !7, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!12, !10, i64 488}
!19 = !{!12, !7, i64 476}


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