; LLVM IR from umgefahren/server-language-benchmark :: C (server)

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

@.str.9 = external hidden unnamed_addr constant [13 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

declare void @perror(ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local i64 @read_line(i32 noundef %0, ptr noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %68, %2
  br label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = load i64, ptr %5, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  %18 = call i64 @read(i32 noundef %14, ptr noundef %17, i64 noundef 100)
  store i64 %18, ptr %8, align 8, !tbaa !11
  %19 = load i64, ptr %8, align 8, !tbaa !11
  %20 = load i64, ptr %6, align 8, !tbaa !11
  %21 = add nsw i64 %20, %19
  store i64 %21, ptr %6, align 8, !tbaa !11
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = load i64, ptr %5, align 8, !tbaa !11
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr %5, align 8, !tbaa !11
  %25 = load i64, ptr %8, align 8, !tbaa !11
  %26 = load i64, ptr %7, align 8, !tbaa !11
  %27 = add nsw i64 %26, %25
  store i64 %27, ptr %7, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !11
  %30 = mul i64 1, %29
  %31 = call ptr @realloc(ptr noundef %28, i64 noundef %30) #6
  store ptr %31, ptr %4, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %13
  call void @perror(ptr noundef @.str.9)
  call void @exit(i32 noundef 1) #7
  unreachable

35:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %36 = load i64, ptr %5, align 8, !tbaa !11
  store i64 %36, ptr %9, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %57, %35
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = load i64, ptr %5, align 8, !tbaa !11
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = add nsw i64 %39, %40
  %42 = icmp slt i64 %38, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  store i32 4, ptr %10, align 4
  br label %60

44:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = load i64, ptr %9, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !13
  store i8 %48, ptr %11, align 1, !tbaa !13
  %49 = load i8, ptr %11, align 1, !tbaa !13
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 10
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i32 4, ptr %10, align 4
  br label %54

53:                                               ; preds = %44
  store i32 0, ptr %10, align 4
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  %55 = load i32, ptr %10, align 4
  switch i32 %55, label %60 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %9, align 8, !tbaa !11
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %9, align 8, !tbaa !11
  br label %37, !llvm.loop !14

60:                                               ; preds = %54, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %8, align 8, !tbaa !11
  %63 = icmp slt i64 %62, 100
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i32 3, ptr %10, align 4
  br label %66

65:                                               ; preds = %61
  store i32 0, ptr %10, align 4
  br label %66

66:                                               ; preds = %65, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %67 = load i32, ptr %10, align 4
  switch i32 %67, label %71 [
    i32 0, label %68
    i32 3, label %69
  ]

68:                                               ; preds = %66
  br label %12

69:                                               ; preds = %66
  %70 = load i64, ptr %7, align 8, !tbaa !11
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i64 %70

71:                                               ; preds = %66
  unreachable
}

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 #3 = { nounwind allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }
attributes #7 = { noreturn 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@.str.9 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @read_line(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #3 {
  br label %3

3:                                                ; preds = %._crit_edge, %2
  %.027 = phi i64 [ 0, %2 ], [ %6, %._crit_edge ]
  %.026 = phi i64 [ 0, %2 ], [ %10, %._crit_edge ]
  %.025 = phi i64 [ 0, %2 ], [ %11, %._crit_edge ]
  %.0 = phi ptr [ %1, %2 ], [ %7, %._crit_edge ]
  %4 = getelementptr inbounds i8, ptr %.0, i64 %.025
  %5 = tail call i64 @read(i32 noundef %0, ptr noundef %4, i64 noundef 100) #5
  %6 = add nsw i64 %5, %.027
  %7 = tail call ptr @realloc(ptr noundef %.0, i64 noundef %6) #6
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %._crit_edge

9:                                                ; preds = %3
  tail call void @perror(ptr noundef nonnull @.str.9) #7
  tail call void @exit(i32 noundef 1) #8
  unreachable

._crit_edge:                                      ; preds = %3
  %10 = add nsw i64 %5, %.026
  %11 = add nsw i64 %5, %.025
  %12 = icmp slt i64 %5, 100
  br i1 %12, label %13, label %3

13:                                               ; preds = %._crit_edge
  ret i64 %10
}

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

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 = { noreturn 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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree "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 }
attributes #6 = { nounwind allocsize(1) }
attributes #7 = { cold }
attributes #8 = { noreturn 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)"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass