; LLVM IR from holzschu/ios_system :: shell_cmds/hexdump (hexdump)

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

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@blocksize = external dso_local global i32, align 4
@fshead = external dso_local global ptr, align 8
@exitval = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %8 = call ptr @setlocale(i32 noundef 6, ptr noundef @.str) #6
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds ptr, ptr %9, i64 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = call ptr @rindex(ptr noundef %11, i32 noundef 111) #7
  store ptr %12, ptr %7, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %18

14:                                               ; preds = %2
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = call i32 @strcmp(ptr noundef %15, ptr noundef @.str.1) #7
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %14, %2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  call void @newsyntax(i32 noundef %19, ptr noundef %5)
  br label %22

20:                                               ; preds = %14
  %21 = load i32, ptr %4, align 4, !tbaa !5
  call void @oldsyntax(i32 noundef %21, ptr noundef %5)
  br label %22

22:                                               ; preds = %20, %18
  store i32 0, ptr @blocksize, align 4, !tbaa !5
  %23 = load ptr, ptr @fshead, align 8, !tbaa !9
  store ptr %23, ptr %6, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %42, %22
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %46

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = call i32 @size(ptr noundef %28)
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct._fs, ptr %30, i32 0, i32 2
  store i32 %29, ptr %31, align 8, !tbaa !11
  %32 = load i32, ptr @blocksize, align 4, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct._fs, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %27
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct._fs, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !11
  store i32 %40, ptr @blocksize, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %37, %27
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct._fs, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  store ptr %45, ptr %6, align 8, !tbaa !9
  br label %24, !llvm.loop !14

46:                                               ; preds = %24
  %47 = load ptr, ptr @fshead, align 8, !tbaa !9
  store ptr %47, ptr %6, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %53, %46
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  call void @rewrite(ptr noundef %52)
  br label %53

53:                                               ; preds = %51
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct._fs, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  store ptr %56, ptr %6, align 8, !tbaa !9
  br label %48, !llvm.loop !16

57:                                               ; preds = %48
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = call i32 @next(ptr noundef %58)
  call void @display()
  %60 = load i32, ptr @exitval, align 4, !tbaa !5
  call void @exit(i32 noundef %60) #8
  unreachable
}

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

; Function Attrs: nounwind
declare ptr @setlocale(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare ptr @rindex(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

declare void @newsyntax(i32 noundef, ptr noundef) #4

declare void @oldsyntax(i32 noundef, ptr noundef) #4

declare i32 @size(ptr noundef) #4

declare void @rewrite(ptr noundef) #4

declare i32 @next(ptr noundef) #4

declare void @display() #4

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

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 = { 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 willreturn memory(read) "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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
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)"}
!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, !6, i64 16}
!12 = !{!"_fs", !10, i64 0, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@blocksize = external dso_local local_unnamed_addr global i32, align 4
@fshead = external dso_local local_unnamed_addr global ptr, align 8
@exitval = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = tail call ptr @setlocale(i32 noundef 6, ptr noundef nonnull @.str) #6
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = tail call ptr @rindex(ptr noundef %5, i32 noundef 111) #7
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %7

7:                                                ; preds = %2
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.1) #7
  %.not13 = icmp eq i32 %8, 0
  br i1 %.not13, label %10, label %9

9:                                                ; preds = %7, %2
  call void @newsyntax(i32 noundef %0, ptr noundef nonnull %3) #6
  br label %11

10:                                               ; preds = %7
  call void @oldsyntax(i32 noundef %0, ptr noundef nonnull %3) #6
  br label %11

11:                                               ; preds = %10, %9
  store i32 0, ptr @blocksize, align 4, !tbaa !9
  %.016 = load ptr, ptr @fshead, align 8, !tbaa !5
  %.not1417 = icmp eq ptr %.016, null
  br i1 %.not1417, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %17
  %.119.pre = load ptr, ptr @fshead, align 8, !tbaa !5
  %.not1520 = icmp eq ptr %.119.pre, null
  br i1 %.not1520, label %._crit_edge, label %.lr.ph22

.lr.ph:                                           ; preds = %11, %17
  %.018 = phi ptr [ %.0, %17 ], [ %.016, %11 ]
  %12 = call i32 @size(ptr noundef nonnull %.018) #6
  %13 = getelementptr inbounds i8, ptr %.018, i64 16
  store i32 %12, ptr %13, align 8, !tbaa !11
  %14 = load i32, ptr @blocksize, align 4, !tbaa !9
  %15 = icmp slt i32 %14, %12
  br i1 %15, label %16, label %17

16:                                               ; preds = %.lr.ph
  store i32 %12, ptr @blocksize, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %.lr.ph, %16
  %.0 = load ptr, ptr %.018, align 8, !tbaa !5
  %.not14 = icmp eq ptr %.0, null
  br i1 %.not14, label %.preheader, label %.lr.ph, !llvm.loop !13

.lr.ph22:                                         ; preds = %.preheader, %.lr.ph22
  %.121 = phi ptr [ %.1, %.lr.ph22 ], [ %.119.pre, %.preheader ]
  call void @rewrite(ptr noundef nonnull %.121) #6
  %.1 = load ptr, ptr %.121, align 8, !tbaa !5
  %.not15 = icmp eq ptr %.1, null
  br i1 %.not15, label %._crit_edge, label %.lr.ph22, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph22, %11, %.preheader
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call i32 @next(ptr noundef %18) #6
  call void @display() #6
  %20 = load i32, ptr @exitval, align 4, !tbaa !9
  call void @exit(i32 noundef %20) #8
  unreachable
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare ptr @rindex(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

declare void @newsyntax(i32 noundef, ptr noundef) local_unnamed_addr #4

declare void @oldsyntax(i32 noundef, ptr noundef) local_unnamed_addr #4

declare i32 @size(ptr noundef) local_unnamed_addr #4

declare void @rewrite(ptr noundef) local_unnamed_addr #4

declare i32 @next(ptr noundef) local_unnamed_addr #4

declare void @display() local_unnamed_addr #4

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

attributes #0 = { noreturn 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 = { 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 nofree nounwind willreturn memory(read) "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
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)"}
!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}
!11 = !{!12, !10, i64 16}
!12 = !{!"_fs", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass