; LLVM IR from mbheinen/bpa-ipf-tsp :: libgui (chgdata)

; 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.DBID = type { ptr, i64, i64, i64, i64, i64, i64, ptr, i64 }
%struct.schem = type { i8, i8, i64, i64, i64, ptr }

@chg_db = external hidden global %struct.DBID, align 8
@.str.1 = external hidden unnamed_addr constant [35 x i8], align 1
@chg_schema = external hidden global [2 x %struct.schem], align 16
@stat = external hidden global i32, align 4
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1

declare i32 @db_valid_db(ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @chg_create() #1 {
  %1 = alloca i32, align 4
  call void @db_init(ptr noundef @chg_db)
  %2 = call i32 @db_valid_db(ptr noundef @chg_db)
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 -1, ptr %1, align 4
  br label %13

6:                                                ; preds = %0
  %7 = call i32 @db_create(ptr noundef @chg_schema, i64 noundef 2, i64 noundef 0, ptr noundef @chg_db)
  store i32 %7, ptr @stat, align 4, !tbaa !5
  %8 = load i32, ptr @stat, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 -1, ptr %1, align 4
  br label %13

12:                                               ; preds = %6
  store i32 0, ptr %1, align 4
  br label %13

13:                                               ; preds = %12, %10, %4
  %14 = load i32, ptr %1, align 4
  ret i32 %14
}

declare void @db_init(ptr noundef) #0

declare i32 @db_create(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

attributes #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 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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.DBID = type { ptr, i64, i64, i64, i64, i64, i64, ptr, i64 }
%struct.schem = type { i8, i8, i64, i64, i64, ptr }

@chg_db = external hidden global %struct.DBID, align 8
@.str.1 = external hidden unnamed_addr constant [35 x i8], align 1
@chg_schema = external hidden global [2 x %struct.schem], align 16
@stat = external hidden local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1

declare i32 @db_valid_db(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @chg_create() local_unnamed_addr #2 {
  tail call void @db_init(ptr noundef nonnull @chg_db) #3
  %1 = tail call i32 @db_valid_db(ptr noundef nonnull @chg_db) #3
  %2 = icmp eq i32 %1, 0
  br i1 %2, label %.sink.split, label %3

3:                                                ; preds = %0
  %4 = tail call i32 @db_create(ptr noundef nonnull @chg_schema, i64 noundef 2, i64 noundef 0, ptr noundef nonnull @chg_db) #3
  store i32 %4, ptr @stat, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %6, label %.sink.split

.sink.split:                                      ; preds = %3, %0
  %.str.2.sink = phi ptr [ @.str.1, %0 ], [ @.str.2, %3 ]
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  br label %6

6:                                                ; preds = %.sink.split, %3
  %.0 = phi i32 [ 0, %3 ], [ -1, %.sink.split ]
  ret i32 %.0
}

declare void @db_init(ptr noundef) local_unnamed_addr #0

declare i32 @db_create(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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