; LLVM IR from seppo0010/rlite :: src (rlite)

; 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.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, ptr, ptr, ptr }

@rl_data_type_header = external dso_local global %struct.rl_data_type, align 8
@stderr = external global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [24 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_has_flag(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_read_header(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.rlite, ptr %4, i32 0, i32 6
  store i64 200, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.rlite, ptr %6, i32 0, i32 8
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %19

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.rlite, ptr %11, i32 0, i32 6
  store i64 1024, ptr %12, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @rl_create_db(ptr noundef %13)
  store i32 %14, ptr %3, align 4, !tbaa !14
  %15 = load i32, ptr %3, align 4, !tbaa !14
  %16 = icmp ne i32 0, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %10
  br label %74

18:                                               ; preds = %10
  br label %73

19:                                               ; preds = %1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.rlite, ptr %20, i32 0, i32 8
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %66

24:                                               ; preds = %19
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = call i32 @file_driver_fp(ptr noundef %25)
  store i32 %26, ptr %3, align 4, !tbaa !14
  %27 = load i32, ptr %3, align 4, !tbaa !14
  %28 = icmp ne i32 0, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  br label %74

30:                                               ; preds = %24
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = call i32 @rl_apply_wal(ptr noundef %31)
  store i32 %32, ptr %3, align 4, !tbaa !14
  %33 = load i32, ptr %3, align 4, !tbaa !14
  %34 = icmp ne i32 0, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  br label %74

36:                                               ; preds = %30
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = call i32 @rl_read(ptr noundef %37, ptr noundef @rl_data_type_header, i64 noundef 0, ptr noundef null, ptr noundef null, i32 noundef 1)
  store i32 %38, ptr %3, align 4, !tbaa !14
  %39 = load i32, ptr %3, align 4, !tbaa !14
  %40 = icmp eq i32 %39, 3
  br i1 %40, label %41, label %60

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = call i32 @rl_has_flag(ptr noundef %42, i32 noundef 4)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %60

45:                                               ; preds = %41
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rlite, ptr %46, i32 0, i32 6
  store i64 1024, ptr %47, align 8, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = call i32 @rl_create_db(ptr noundef %48)
  store i32 %49, ptr %3, align 4, !tbaa !14
  %50 = load i32, ptr %3, align 4, !tbaa !14
  %51 = icmp ne i32 0, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %45
  br label %74

53:                                               ; preds = %45
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = call i32 @rl_write(ptr noundef %54, ptr noundef @rl_data_type_header, i64 noundef 0, ptr noundef null)
  store i32 %55, ptr %3, align 4, !tbaa !14
  %56 = load i32, ptr %3, align 4, !tbaa !14
  %57 = icmp ne i32 0, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  br label %74

59:                                               ; preds = %53
  br label %65

60:                                               ; preds = %41, %36
  %61 = load i32, ptr %3, align 4, !tbaa !14
  %62 = icmp ne i32 %61, 2
  br i1 %62, label %63, label %64

63:                                               ; preds = %60
  br label %74

64:                                               ; preds = %60
  br label %65

65:                                               ; preds = %64, %59
  br label %72

66:                                               ; preds = %19
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rlite, ptr %68, i32 0, i32 8
  %70 = load i32, ptr %69, align 8, !tbaa !13
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.21, i32 noundef %70) #4
  store i32 6, ptr %3, align 4, !tbaa !14
  br label %74

72:                                               ; preds = %65
  br label %73

73:                                               ; preds = %72, %18
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %74

74:                                               ; preds = %73, %66, %63, %58, %52, %35, %29, %17
  %75 = load i32, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %75
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_create_db(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @file_driver_fp(ptr noundef) #2

declare i32 @rl_apply_wal(ptr noundef) #3

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 = { 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 = { "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 48}
!10 = !{!"rlite", !11, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 64}
!14 = !{!12, !12, 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"

%struct.rl_data_type = type { ptr, ptr, ptr, ptr }

@rl_data_type_header = external dso_local global %struct.rl_data_type, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [24 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_has_flag(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_read_header(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 200, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = load i32, ptr %3, align 8, !tbaa !12
  switch i32 %4, label %19 [
    i32 0, label %5
    i32 1, label %7
  ]

5:                                                ; preds = %1
  store i64 1024, ptr %2, align 8, !tbaa !5
  %6 = tail call i32 @rl_create_db(ptr noundef nonnull %0)
  %.not32 = icmp eq i32 %6, 0
  br i1 %.not32, label %22, label %23

7:                                                ; preds = %1
  %8 = tail call i32 @file_driver_fp(ptr noundef nonnull %0)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %23

9:                                                ; preds = %7
  %10 = tail call i32 @rl_apply_wal(ptr noundef nonnull %0) #3
  %.not27 = icmp eq i32 %10, 0
  br i1 %.not27, label %11, label %23

11:                                               ; preds = %9
  %12 = tail call i32 @rl_read(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_header, i64 noundef 0, ptr noundef null, ptr noundef null, i32 noundef 1)
  switch i32 %12, label %23 [
    i32 3, label %13
    i32 2, label %22
  ]

13:                                               ; preds = %11
  %14 = tail call i32 @rl_has_flag(ptr noundef nonnull %0, i32 noundef 4)
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %23, label %15

15:                                               ; preds = %13
  store i64 1024, ptr %2, align 8, !tbaa !5
  %16 = tail call i32 @rl_create_db(ptr noundef nonnull %0)
  %.not30 = icmp eq i32 %16, 0
  br i1 %.not30, label %17, label %23

17:                                               ; preds = %15
  %18 = tail call i32 @rl_write(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_header, i64 noundef 0, ptr noundef null)
  %.not31 = icmp eq i32 %18, 0
  br i1 %.not31, label %22, label %23

19:                                               ; preds = %1
  %20 = load ptr, ptr @stderr, align 8, !tbaa !13
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.21, i32 noundef %4) #4
  br label %23

22:                                               ; preds = %11, %17, %5
  br label %23

23:                                               ; preds = %13, %11, %17, %15, %9, %7, %5, %22, %19
  %.0 = phi i32 [ %6, %5 ], [ 0, %22 ], [ %8, %7 ], [ %10, %9 ], [ %16, %15 ], [ %18, %17 ], [ 6, %19 ], [ %12, %11 ], [ 3, %13 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_create_db(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @file_driver_fp(ptr noundef) local_unnamed_addr #1

declare i32 @rl_apply_wal(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #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" }
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 }
attributes #4 = { cold 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 48}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 64}
!13 = !{!11, !11, i64 0}


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