; LLVM IR from attractivechaos/klib :: knetfile (knet_seek)

; 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.knetFile_s = type { i32, i32, i64, ptr, ptr, i32, [4 x i32], i32, i32, i32, i32, ptr, ptr, ptr, i64, i64, ptr, ptr }

@stderr = external global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [16 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 willreturn memory(none)
declare ptr @__errno_location() #2

; Function Attrs: nounwind uwtable
define dso_local i64 @knet_seek(ptr noundef %0, i64 noundef %1, i32 noundef %2) #3 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  %10 = load i32, ptr %7, align 4, !tbaa !11
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %19

12:                                               ; preds = %3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.knetFile_s, ptr %14, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = icmp eq i64 %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i64 0, ptr %4, align 8
  br label %120

19:                                               ; preds = %12, %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.knetFile_s, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %40

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.knetFile_s, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = call i64 @lseek(i32 noundef %27, i64 noundef %28, i32 noundef %29) #4
  store i64 %30, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp eq i64 %31, -1
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %39

34:                                               ; preds = %24
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.knetFile_s, ptr %36, i32 0, i32 2
  store i64 %35, ptr %37, align 8, !tbaa !13
  %38 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %38, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %39

39:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %120

40:                                               ; preds = %19
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.knetFile_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !15
  %44 = icmp eq i32 %43, 2
  br i1 %44, label %45, label %78

45:                                               ; preds = %40
  %46 = load i32, ptr %7, align 4, !tbaa !11
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %54

48:                                               ; preds = %45
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.knetFile_s, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !13
  %53 = add nsw i64 %52, %49
  store i64 %53, ptr %51, align 8, !tbaa !13
  br label %74

54:                                               ; preds = %45
  %55 = load i32, ptr %7, align 4, !tbaa !11
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %61

57:                                               ; preds = %54
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.knetFile_s, ptr %59, i32 0, i32 2
  store i64 %58, ptr %60, align 8, !tbaa !13
  br label %73

61:                                               ; preds = %54
  %62 = load i32, ptr %7, align 4, !tbaa !11
  %63 = icmp eq i32 %62, 2
  br i1 %63, label %64, label %72

64:                                               ; preds = %61
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.knetFile_s, ptr %65, i32 0, i32 15
  %67 = load i64, ptr %66, align 8, !tbaa !17
  %68 = load i64, ptr %6, align 8, !tbaa !9
  %69 = add nsw i64 %67, %68
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.knetFile_s, ptr %70, i32 0, i32 2
  store i64 %69, ptr %71, align 8, !tbaa !13
  br label %72

72:                                               ; preds = %64, %61
  br label %73

73:                                               ; preds = %72, %57
  br label %74

74:                                               ; preds = %73, %48
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.knetFile_s, ptr %75, i32 0, i32 10
  store i32 0, ptr %76, align 8, !tbaa !18
  %77 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %77, ptr %4, align 8
  br label %120

78:                                               ; preds = %40
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.knetFile_s, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !15
  %82 = icmp eq i32 %81, 3
  br i1 %82, label %83, label %111

83:                                               ; preds = %78
  %84 = load i32, ptr %7, align 4, !tbaa !11
  %85 = icmp eq i32 %84, 2
  br i1 %85, label %86, label %90

86:                                               ; preds = %83
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str.21) #4
  %89 = call ptr @__errno_location() #5
  store i32 29, ptr %89, align 4, !tbaa !11
  store i64 -1, ptr %4, align 8
  br label %120

90:                                               ; preds = %83
  %91 = load i32, ptr %7, align 4, !tbaa !11
  %92 = icmp eq i32 %91, 1
  br i1 %92, label %93, label %99

93:                                               ; preds = %90
  %94 = load i64, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.knetFile_s, ptr %95, i32 0, i32 2
  %97 = load i64, ptr %96, align 8, !tbaa !13
  %98 = add nsw i64 %97, %94
  store i64 %98, ptr %96, align 8, !tbaa !13
  br label %107

99:                                               ; preds = %90
  %100 = load i32, ptr %7, align 4, !tbaa !11
  %101 = icmp eq i32 %100, 0
  br i1 %101, label %102, label %106

102:                                              ; preds = %99
  %103 = load i64, ptr %6, align 8, !tbaa !9
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.knetFile_s, ptr %104, i32 0, i32 2
  store i64 %103, ptr %105, align 8, !tbaa !13
  br label %106

106:                                              ; preds = %102, %99
  br label %107

107:                                              ; preds = %106, %93
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.knetFile_s, ptr %108, i32 0, i32 10
  store i32 0, ptr %109, align 8, !tbaa !18
  %110 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %110, ptr %4, align 8
  br label %120

111:                                              ; preds = %78
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  %114 = call ptr @__errno_location() #5
  store i32 22, ptr %114, align 4, !tbaa !11
  %115 = load ptr, ptr @stderr, align 8, !tbaa !5
  %116 = call ptr @__errno_location() #5
  %117 = load i32, ptr %116, align 4, !tbaa !11
  %118 = call ptr @strerror(i32 noundef %117) #4
  %119 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %115, ptr noundef @.str.22, ptr noundef %118) #4
  store i64 -1, ptr %4, align 8
  br label %120

120:                                              ; preds = %113, %107, %86, %74, %39, %18
  %121 = load i64, ptr %4, align 8
  ret i64 %121
}

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

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

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 willreturn memory(none) "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 }
attributes #5 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"knetFile_s", !12, i64 0, !12, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !7, i64 36, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 104, !6, i64 112, !6, i64 120}
!15 = !{!14, !12, i64 0}
!16 = !{!14, !12, i64 4}
!17 = !{!14, !10, i64 104}
!18 = !{!14, !12, i64 64}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.21 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [16 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: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @knet_seek(ptr nocapture noundef %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i64 %7, %1
  br i1 %8, label %55, label %9

9:                                                ; preds = %5, %3
  %10 = load i32, ptr %0, align 8, !tbaa !12
  switch i32 %10, label %50 [
    i32 1, label %11
    i32 2, label %18
    i32 3, label %36
  ]

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = tail call i64 @lseek(i32 noundef %13, i64 noundef %1, i32 noundef %2) #4
  %15 = icmp eq i64 %14, -1
  br i1 %15, label %55, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %14, ptr %17, align 8, !tbaa !5
  br label %55

18:                                               ; preds = %9
  %19 = icmp eq i32 %2, 1
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = add nsw i64 %22, %1
  store i64 %23, ptr %21, align 8, !tbaa !5
  br label %34

24:                                               ; preds = %18
  br i1 %4, label %25, label %27

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %26, align 8, !tbaa !5
  br label %34

27:                                               ; preds = %24
  %28 = icmp eq i32 %2, 2
  br i1 %28, label %29, label %34

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %0, i64 104
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = add nsw i64 %31, %1
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %32, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %25, %29, %27, %20
  %35 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %35, align 8, !tbaa !15
  br label %55

36:                                               ; preds = %9
  switch i32 %2, label %45 [
    i32 2, label %37
    i32 1, label %41
  ]

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !16
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.21) #5
  %40 = tail call ptr @__errno_location() #6
  store i32 29, ptr %40, align 4, !tbaa !17
  br label %55

41:                                               ; preds = %36
  %42 = getelementptr inbounds i8, ptr %0, i64 8
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = add nsw i64 %43, %1
  store i64 %44, ptr %42, align 8, !tbaa !5
  br label %48

45:                                               ; preds = %36
  br i1 %4, label %46, label %48

46:                                               ; preds = %45
  %47 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %45, %46, %41
  %49 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %49, align 8, !tbaa !15
  br label %55

50:                                               ; preds = %9
  %51 = tail call ptr @__errno_location() #6
  store i32 22, ptr %51, align 4, !tbaa !17
  %52 = load ptr, ptr @stderr, align 8, !tbaa !16
  %53 = tail call ptr @strerror(i32 noundef 22) #4
  %54 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef nonnull @.str.22, ptr noundef %53) #5
  br label %55

55:                                               ; preds = %16, %11, %5, %50, %48, %37, %34
  %.1 = phi i64 [ %1, %34 ], [ -1, %37 ], [ %1, %48 ], [ -1, %50 ], [ 0, %5 ], [ %1, %16 ], [ -1, %11 ]
  ret i64 %.1
}

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 "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 }
attributes #5 = { cold nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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, !10, i64 8}
!6 = !{!"knetFile_s", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !8, i64 36, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !10, i64 96, !10, i64 104, !11, i64 112, !11, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 104}
!15 = !{!6, !7, i64 64}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !7, i64 0}


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