; LLVM IR from simbody/simbody :: SimTKmath/Optimizers/src/IpOpt/IpJournalist.ll (ZN10SimTKIpopt11FileJournal4OpenEPKc)

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

%"class.SimTKIpopt::FileJournal" = type { %"class.SimTKIpopt::Journal.base", ptr }
%"class.SimTKIpopt::Journal.base" = type <{ %"class.SimTKIpopt::ReferencedObject.base", [4 x i8], %"class.std::__cxx11::basic_string", [15 x i32] }>
%"class.SimTKIpopt::ReferencedObject.base" = type <{ ptr, i32 }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@stdout = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10SimTKIpopt11FileJournal4OpenEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %24

10:                                               ; preds = %2
  %11 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr @stdout, align 8, !tbaa !5
  %14 = icmp ne ptr %12, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %10
  %16 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = icmp ne ptr %17, %18
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 @fclose(ptr noundef %22)
  br label %24

24:                                               ; preds = %20, %15, %10, %2
  %25 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  store ptr null, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @strcmp(ptr noundef @.str.3, ptr noundef %26) #3
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load ptr, ptr @stdout, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  store ptr %30, ptr %31, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  br label %50

32:                                               ; preds = %24
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i32 @strcmp(ptr noundef @.str.4, ptr noundef %33) #3
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  store ptr %37, ptr %38, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  br label %50

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call noalias ptr @fopen(ptr noundef %40, ptr noundef @.str.5)
  %42 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  store ptr %41, ptr %42, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.SimTKIpopt::FileJournal", ptr %6, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  store i1 true, ptr %3, align 1
  br label %50

47:                                               ; preds = %39
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  store i1 false, ptr %3, align 1
  br label %50

50:                                               ; preds = %49, %46, %36, %29
  %51 = load i1, ptr %3, align 1
  ret i1 %51
}

declare i32 @fclose(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

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 = { nounwind willreturn memory(read) "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 willreturn memory(read) }

!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, !6, i64 112}
!10 = !{!"_ZTSN10SimTKIpopt11FileJournalE", !11, i64 0, !6, i64 112}
!11 = !{!"_ZTSN10SimTKIpopt7JournalE", !12, i64 0, !14, i64 16, !7, i64 48}
!12 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, 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"

@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10SimTKIpopt11FileJournal4OpenEPKc(ptr nocapture noundef nonnull align 8 dereferenceable(120) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = load ptr, ptr @stdout, align 8
  %.not6 = icmp eq ptr %4, %5
  %or.cond = select i1 %.not, i1 true, i1 %.not6
  %6 = load ptr, ptr @stderr, align 8
  %.not7 = icmp eq ptr %4, %6
  %or.cond9 = select i1 %or.cond, i1 true, i1 %.not7
  br i1 %or.cond9, label %9, label %7

7:                                                ; preds = %2
  %8 = tail call i32 @fclose(ptr noundef nonnull %4)
  br label %9

9:                                                ; preds = %7, %2
  store ptr null, ptr %3, align 8, !tbaa !5
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull dereferenceable(1) %1) #3
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = load ptr, ptr @stdout, align 8, !tbaa !16
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %21

14:                                               ; preds = %9
  %15 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull dereferenceable(1) %1) #3
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = load ptr, ptr @stderr, align 8, !tbaa !16
  store ptr %18, ptr %3, align 8, !tbaa !5
  br label %21

19:                                               ; preds = %14
  %20 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.5)
  store ptr %20, ptr %3, align 8, !tbaa !5
  %.not8 = icmp ne ptr %20, null
  br label %21

21:                                               ; preds = %19, %17, %12
  %.0 = phi i1 [ true, %12 ], [ true, %17 ], [ %.not8, %19 ]
  ret i1 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

attributes #0 = { mustprogress nofree 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 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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, !14, i64 112}
!6 = !{!"_ZTSN10SimTKIpopt11FileJournalE", !7, i64 0, !14, i64 112}
!7 = !{!"_ZTSN10SimTKIpopt7JournalE", !8, i64 0, !12, i64 16, !10, i64 48}
!8 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !9, i64 8}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !15, i64 8, !10, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !14, i64 0}
!14 = !{!"any pointer", !10, i64 0}
!15 = !{!"long", !10, i64 0}
!16 = !{!14, !14, i64 0}


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