; LLVM IR from jingweizhanghuai/Morn :: src/ptc (morn_message)

; 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.HandleProcLock = type { i32, i32, i32, [256 x i8] }

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@__FUNCTION__.endProcLock = external hidden unnamed_addr constant [12 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
declare i32 @flock(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) #1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #2

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #2

declare i32 @close(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @remove(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @endProcLock(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.HandleProcLock, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %97

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HandleProcLock, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = call i32 @flock(i32 noundef %15, i32 noundef 2) #4
  br label %17

17:                                               ; preds = %12
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.HandleProcLock, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = call i64 @lseek(i32 noundef %21, i64 noundef 4, i32 noundef 0) #4
  %23 = icmp ne i64 %22, 4
  %24 = zext i1 %23 to i32
  store i32 %24, ptr %4, align 4, !tbaa !12
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %18
  %28 = load i32, ptr %4, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %28, i32 noundef -1, ptr noundef @.str, i32 noundef 779, ptr noundef @__FUNCTION__.endProcLock, ptr noundef @.str.1)
  br label %29

29:                                               ; preds = %27, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.HandleProcLock, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = call i64 @read(i32 noundef %35, ptr noundef %3, i64 noundef 4)
  %37 = icmp ne i64 %36, 4
  %38 = zext i1 %37 to i32
  store i32 %38, ptr %5, align 4, !tbaa !12
  %39 = load i32, ptr %5, align 4, !tbaa !12
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %32
  %42 = load i32, ptr %5, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %42, i32 noundef -1, ptr noundef @.str, i32 noundef 779, ptr noundef @__FUNCTION__.endProcLock, ptr noundef @.str.2)
  br label %43

43:                                               ; preds = %41, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %3, align 4, !tbaa !12
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %3, align 4, !tbaa !12
  br label %50

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.HandleProcLock, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = call i64 @lseek(i32 noundef %54, i64 noundef 4, i32 noundef 0) #4
  %56 = icmp ne i64 %55, 4
  %57 = zext i1 %56 to i32
  store i32 %57, ptr %6, align 4, !tbaa !12
  %58 = load i32, ptr %6, align 4, !tbaa !12
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %51
  %61 = load i32, ptr %6, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %61, i32 noundef -1, ptr noundef @.str, i32 noundef 781, ptr noundef @__FUNCTION__.endProcLock, ptr noundef @.str.1)
  br label %62

62:                                               ; preds = %60, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.HandleProcLock, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = call i64 @write(i32 noundef %68, ptr noundef %3, i64 noundef 4)
  %70 = icmp ne i64 %69, 4
  %71 = zext i1 %70 to i32
  store i32 %71, ptr %7, align 4, !tbaa !12
  %72 = load i32, ptr %7, align 4, !tbaa !12
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %65
  %75 = load i32, ptr %7, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %75, i32 noundef -1, ptr noundef @.str, i32 noundef 781, ptr noundef @__FUNCTION__.endProcLock, ptr noundef @.str.3)
  br label %76

76:                                               ; preds = %74, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.HandleProcLock, ptr %81, i32 0, i32 2
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = call i32 @flock(i32 noundef %83, i32 noundef 8) #4
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.HandleProcLock, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = call i32 @close(i32 noundef %87)
  %89 = load i32, ptr %3, align 4, !tbaa !12
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %96

91:                                               ; preds = %80
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.HandleProcLock, ptr %92, i32 0, i32 3
  %94 = getelementptr inbounds [256 x i8], ptr %93, i64 0, i64 0
  %95 = call i32 @remove(ptr noundef %94) #4
  br label %96

96:                                               ; preds = %91, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %97

97:                                               ; preds = %96, %1
  ret void
}

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

!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, !11, i64 8}
!10 = !{!"HandleProcLock", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, 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"

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@__FUNCTION__.endProcLock = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @flock(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #2

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

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

declare i32 @close(i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @endProcLock(ptr nocapture noundef readonly %0) local_unnamed_addr #5 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %34, label %5

5:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %6 = tail call i32 @flock(i32 noundef %4, i32 noundef 2) #6
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = tail call i64 @lseek(i32 noundef %7, i64 noundef 4, i32 noundef 0) #6
  %.not16 = icmp eq i64 %8, 4
  br i1 %.not16, label %10, label %9

9:                                                ; preds = %5
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 779, ptr noundef nonnull @__FUNCTION__.endProcLock, ptr noundef nonnull @.str.1) #6
  br label %10

10:                                               ; preds = %9, %5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = call i64 @read(i32 noundef %11, ptr noundef nonnull %2, i64 noundef 4) #6
  %.not17 = icmp eq i64 %12, 4
  br i1 %.not17, label %14, label %13

13:                                               ; preds = %10
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 779, ptr noundef nonnull @__FUNCTION__.endProcLock, ptr noundef nonnull @.str.2) #6
  br label %14

14:                                               ; preds = %13, %10
  %15 = load i32, ptr %2, align 4, !tbaa !10
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %2, align 4, !tbaa !10
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = tail call i64 @lseek(i32 noundef %17, i64 noundef 4, i32 noundef 0) #6
  %.not18 = icmp eq i64 %18, 4
  br i1 %.not18, label %20, label %19

19:                                               ; preds = %14
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 781, ptr noundef nonnull @__FUNCTION__.endProcLock, ptr noundef nonnull @.str.1) #6
  br label %20

20:                                               ; preds = %19, %14
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = call i64 @write(i32 noundef %21, ptr noundef nonnull %2, i64 noundef 4) #6
  %.not19 = icmp eq i64 %22, 4
  br i1 %.not19, label %24, label %23

23:                                               ; preds = %20
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 781, ptr noundef nonnull @__FUNCTION__.endProcLock, ptr noundef nonnull @.str.3) #6
  br label %24

24:                                               ; preds = %23, %20
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = tail call i32 @flock(i32 noundef %25, i32 noundef 8) #6
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = tail call i32 @close(i32 noundef %27) #6
  %29 = icmp eq i32 %16, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %24
  %31 = getelementptr inbounds i8, ptr %0, i64 12
  %32 = tail call i32 @remove(ptr noundef nonnull %31) #6
  br label %33

33:                                               ; preds = %30, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  br label %34

34:                                               ; preds = %33, %1
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nofree "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 = { nofree 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 #5 = { 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 #6 = { 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 8}
!6 = !{!"HandleProcLock", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}


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