; LLVM IR from cvra/robot-software :: lib/cmp/examples (example1)

; 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.cmp_ctx_s = type { i8, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.cmp_ctx_s, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [6 x i8], align 1
  %7 = alloca [12 x i8], align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 6, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 6, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 12, i1 false)
  %8 = call noalias ptr @fopen(ptr noundef @.str.1, ptr noundef @.str.2)
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  call void @error_and_exit(ptr noundef @.str.3)
  br label %12

12:                                               ; preds = %11, %0
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @cmp_init(ptr noundef %3, ptr noundef %13, ptr noundef @file_reader, ptr noundef @file_writer)
  %14 = call zeroext i1 @cmp_write_array(ptr noundef %3, i32 noundef 2)
  br i1 %14, label %17, label %15

15:                                               ; preds = %12
  %16 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %16)
  br label %17

17:                                               ; preds = %15, %12
  %18 = call zeroext i1 @cmp_write_str(ptr noundef %3, ptr noundef @.str.4, i32 noundef 5)
  br i1 %18, label %21, label %19

19:                                               ; preds = %17
  %20 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %20)
  br label %21

21:                                               ; preds = %19, %17
  %22 = call zeroext i1 @cmp_write_str(ptr noundef %3, ptr noundef @.str.5, i32 noundef 11)
  br i1 %22, label %25, label %23

23:                                               ; preds = %21
  %24 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %24)
  br label %25

25:                                               ; preds = %23, %21
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @rewind(ptr noundef %26)
  %27 = call zeroext i1 @cmp_read_array(ptr noundef %3, ptr noundef %4)
  br i1 %27, label %30, label %28

28:                                               ; preds = %25
  %29 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %29)
  br label %30

30:                                               ; preds = %28, %25
  %31 = call zeroext i1 @cmp_read_str_size(ptr noundef %3, ptr noundef %5)
  br i1 %31, label %34, label %32

32:                                               ; preds = %30
  %33 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %33)
  br label %34

34:                                               ; preds = %32, %30
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = icmp ugt i64 %36, 5
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  call void @error_and_exit(ptr noundef @.str.6)
  br label %39

39:                                               ; preds = %38, %34
  %40 = getelementptr inbounds [6 x i8], ptr %6, i64 0, i64 0
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = call zeroext i1 @read_bytes(ptr noundef %40, i64 noundef %42, ptr noundef %43)
  br i1 %44, label %47, label %45

45:                                               ; preds = %39
  %46 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %46)
  br label %47

47:                                               ; preds = %45, %39
  store i32 12, ptr %5, align 4, !tbaa !9
  %48 = getelementptr inbounds [12 x i8], ptr %7, i64 0, i64 0
  %49 = call zeroext i1 @cmp_read_str(ptr noundef %3, ptr noundef %48, ptr noundef %5)
  br i1 %49, label %52, label %50

50:                                               ; preds = %47
  %51 = call ptr @cmp_strerror(ptr noundef %3)
  call void @error_and_exit(ptr noundef %51)
  br label %52

52:                                               ; preds = %50, %47
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %53)
  %55 = getelementptr inbounds [6 x i8], ptr %6, i64 0, i64 0
  %56 = getelementptr inbounds [12 x i8], ptr %7, i64 0, i64 0
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %55, ptr noundef %56)
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = call i32 @fclose(ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 6, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @cmp_init(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @file_reader(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @file_writer(ptr noundef, ptr noundef, i64 noundef) #0

declare zeroext i1 @cmp_write_array(ptr noundef, i32 noundef) #3

declare ptr @cmp_strerror(ptr noundef) #3

declare zeroext i1 @cmp_write_str(ptr noundef, ptr noundef, i32 noundef) #3

declare void @rewind(ptr noundef) #3

declare zeroext i1 @cmp_read_array(ptr noundef, ptr noundef) #3

declare zeroext i1 @cmp_read_str_size(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @read_bytes(ptr noundef, i64 noundef, ptr noundef) #0

declare zeroext i1 @cmp_read_str(ptr noundef, ptr noundef, ptr noundef) #3

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

declare i32 @fclose(ptr noundef) #3

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"int", !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"

%struct.cmp_ctx_s = type { i8, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.cmp_ctx_s, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [6 x i8], align 1
  %5 = alloca [12 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 6, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %4, i8 0, i64 6, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(12) %5, i8 0, i64 12, i1 false)
  %6 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  tail call void @error_and_exit(ptr noundef nonnull @.str.3)
  br label %9

9:                                                ; preds = %8, %0
  call void @cmp_init(ptr noundef nonnull %1, ptr noundef %6, ptr noundef nonnull @file_reader, ptr noundef nonnull @file_writer) #5
  %10 = call zeroext i1 @cmp_write_array(ptr noundef nonnull %1, i32 noundef 2) #5
  br i1 %10, label %13, label %11

11:                                               ; preds = %9
  %12 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %12)
  br label %13

13:                                               ; preds = %11, %9
  %14 = call zeroext i1 @cmp_write_str(ptr noundef nonnull %1, ptr noundef nonnull @.str.4, i32 noundef 5) #5
  br i1 %14, label %17, label %15

15:                                               ; preds = %13
  %16 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %16)
  br label %17

17:                                               ; preds = %15, %13
  %18 = call zeroext i1 @cmp_write_str(ptr noundef nonnull %1, ptr noundef nonnull @.str.5, i32 noundef 11) #5
  br i1 %18, label %21, label %19

19:                                               ; preds = %17
  %20 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %20)
  br label %21

21:                                               ; preds = %19, %17
  call void @rewind(ptr noundef %6)
  %22 = call zeroext i1 @cmp_read_array(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  br i1 %22, label %25, label %23

23:                                               ; preds = %21
  %24 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %24)
  br label %25

25:                                               ; preds = %23, %21
  %26 = call zeroext i1 @cmp_read_str_size(ptr noundef nonnull %1, ptr noundef nonnull %3) #5
  br i1 %26, label %29, label %27

27:                                               ; preds = %25
  %28 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %28)
  br label %29

29:                                               ; preds = %27, %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp ugt i32 %30, 5
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  call void @error_and_exit(ptr noundef nonnull @.str.6)
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %29
  %34 = phi i32 [ %.pre, %32 ], [ %30, %29 ]
  %35 = zext i32 %34 to i64
  %36 = call zeroext i1 @read_bytes(ptr noundef nonnull %4, i64 noundef %35, ptr noundef %6)
  br i1 %36, label %39, label %37

37:                                               ; preds = %33
  %38 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %38)
  br label %39

39:                                               ; preds = %37, %33
  store i32 12, ptr %3, align 4, !tbaa !5
  %40 = call zeroext i1 @cmp_read_str(ptr noundef nonnull %1, ptr noundef nonnull %5, ptr noundef nonnull %3) #5
  br i1 %40, label %43, label %41

41:                                               ; preds = %39
  %42 = call ptr @cmp_strerror(ptr noundef nonnull %1) #5
  call void @error_and_exit(ptr noundef %42)
  br label %43

43:                                               ; preds = %41, %39
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %44)
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %47 = call i32 @fclose(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 6, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @cmp_init(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @file_reader(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @file_writer(ptr noundef, ptr noundef, i64 noundef) #0

declare zeroext i1 @cmp_write_array(ptr noundef, i32 noundef) local_unnamed_addr #4

declare ptr @cmp_strerror(ptr noundef) local_unnamed_addr #4

declare zeroext i1 @cmp_write_str(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #3

declare zeroext i1 @cmp_read_array(ptr noundef, ptr noundef) local_unnamed_addr #4

declare zeroext i1 @cmp_read_str_size(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @read_bytes(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @cmp_read_str(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 }

!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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass