; LLVM IR from nelhage/reptyr :: platform/linux (linux_ptrace)

; 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.ptrace_child = type { i32, i32, i32, i32, i32, i64, i64, %struct.user_regs_struct }
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

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

; Function Attrs: nounwind uwtable
declare hidden i64 @__ptrace_command(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; 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 i32 @ptrace_wait(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ptrace_child, ptr %6, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ptrace_child, ptr %9, i32 0, i32 3
  %11 = call i32 @waitpid(i32 noundef %8, ptr noundef %10, i32 noundef 0)
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %1
  %14 = call ptr @__errno_location() #4
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ptrace_child, ptr %16, i32 0, i32 4
  store i32 %15, ptr %17, align 8, !tbaa !16
  store i32 -1, ptr %2, align 4
  br label %91

18:                                               ; preds = %1
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ptrace_child, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = and i32 %21, 127
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %34, label %24

24:                                               ; preds = %18
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ptrace_child, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = and i32 %27, 127
  %29 = add nsw i32 %28, 1
  %30 = trunc i32 %29 to i8
  %31 = sext i8 %30 to i32
  %32 = ashr i32 %31, 1
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %24, %18
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ptrace_child, ptr %35, i32 0, i32 1
  store i32 5, ptr %36, align 4, !tbaa !18
  br label %90

37:                                               ; preds = %24
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ptrace_child, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = and i32 %40, 255
  %42 = icmp eq i32 %41, 127
  br i1 %42, label %43, label %86

43:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ptrace_child, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !17
  %47 = and i32 %46, 65280
  %48 = ashr i32 %47, 8
  store i32 %48, ptr %4, align 4, !tbaa !15
  %49 = load i32, ptr %4, align 4, !tbaa !15
  %50 = and i32 %49, 128
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %61

52:                                               ; preds = %43
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ptrace_child, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !18
  %56 = icmp eq i32 %55, 1
  %57 = zext i1 %56 to i64
  %58 = select i1 %56, i32 2, i32 1
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ptrace_child, ptr %59, i32 0, i32 1
  store i32 %58, ptr %60, align 4, !tbaa !18
  br label %85

61:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ptrace_child, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 4, !tbaa !17
  %65 = ashr i32 %64, 16
  store i32 %65, ptr %5, align 4, !tbaa !15
  %66 = load i32, ptr %4, align 4, !tbaa !15
  %67 = icmp eq i32 %66, 5
  br i1 %67, label %68, label %76

68:                                               ; preds = %61
  %69 = load i32, ptr %5, align 4, !tbaa !15
  %70 = icmp eq i32 %69, 1
  br i1 %70, label %71, label %76

71:                                               ; preds = %68
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ptrace_child, ptr %73, i32 0, i32 5
  %75 = call i64 @__ptrace_command(ptr noundef %72, i32 noundef 16897, ptr noundef null, ptr noundef %74)
  br label %76

76:                                               ; preds = %71, %68, %61
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ptrace_child, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !18
  %80 = icmp ne i32 %79, 1
  br i1 %80, label %81, label %84

81:                                               ; preds = %76
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ptrace_child, ptr %82, i32 0, i32 1
  store i32 4, ptr %83, align 4, !tbaa !18
  br label %84

84:                                               ; preds = %81, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %85

85:                                               ; preds = %84, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %89

86:                                               ; preds = %37
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.ptrace_child, ptr %87, i32 0, i32 4
  store i32 22, ptr %88, align 8, !tbaa !16
  store i32 -1, ptr %2, align 4
  br label %91

89:                                               ; preds = %85
  br label %90

90:                                               ; preds = %89, %34
  store i32 0, ptr %2, align 4
  br label %91

91:                                               ; preds = %90, %86, %13
  %92 = load i32, ptr %2, align 4
  ret i32 %92
}

declare i32 @waitpid(i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #4 = { nounwind willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"ptrace_child", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 24, !12, i64 32, !13, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"user_regs_struct", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !14, i64 192, !14, i64 200, !14, i64 208}
!14 = !{!"long long", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 16}
!17 = !{!10, !11, i64 12}
!18 = !{!10, !11, i64 4}


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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ptrace_wait(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = tail call i32 @waitpid(i32 noundef %2, ptr noundef nonnull %3, i32 noundef 0) #3
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %10

6:                                                ; preds = %1
  %7 = tail call ptr @__errno_location() #4
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %8, ptr %9, align 8, !tbaa !14
  br label %40

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !15
  %12 = and i32 %11, 127
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  %15 = shl nuw nsw i32 %12, 24
  %sext = add nuw i32 %15, 16777216
  %16 = icmp sgt i32 %sext, 33554431
  br i1 %16, label %17, label %19

17:                                               ; preds = %14, %10
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 5, ptr %18, align 4, !tbaa !16
  br label %40

19:                                               ; preds = %14
  %20 = and i32 %11, 255
  %21 = icmp eq i32 %20, 127
  br i1 %21, label %22, label %38

22:                                               ; preds = %19
  %23 = and i32 %11, 32768
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %29, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = icmp eq i32 %26, 1
  %28 = select i1 %27, i32 2, i32 1
  store i32 %28, ptr %25, align 4, !tbaa !16
  br label %40

29:                                               ; preds = %22
  %30 = and i32 %11, -33024
  %or.cond = icmp eq i32 %30, 66816
  br i1 %or.cond, label %31, label %34

31:                                               ; preds = %29
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = tail call i64 @__ptrace_command(ptr noundef nonnull %0, i32 noundef 16897, ptr noundef null, ptr noundef nonnull %32)
  br label %34

34:                                               ; preds = %31, %29
  %35 = getelementptr inbounds i8, ptr %0, i64 4
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %.not21 = icmp eq i32 %36, 1
  br i1 %.not21, label %40, label %37

37:                                               ; preds = %34
  store i32 4, ptr %35, align 4, !tbaa !16
  br label %40

38:                                               ; preds = %19
  %39 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 22, ptr %39, align 8, !tbaa !14
  br label %40

40:                                               ; preds = %17, %34, %37, %24, %38, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %38 ], [ 0, %24 ], [ 0, %37 ], [ 0, %34 ], [ 0, %17 ]
  ret i32 %.0
}

declare i32 @waitpid(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

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 = { "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 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 #3 = { nounwind }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"ptrace_child", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24, !10, i64 32, !11, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"user_regs_struct", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208}
!12 = !{!"long long", !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 12}
!16 = !{!6, !7, i64 4}


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