#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ PT_TRACE_ME;
int _error(char const *, char *, int);
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/);
int _ptrace_child(char const *progname) {
  int ret = 0;
  errno = 0;
  if (ptrace(PT_TRACE_ME, 0, NULL, 0) != 0 && errno != 0)
    ret = _error(progname, "PT_TRACE_ME", 1) + 1;
  _exit(ret);
  return -_error(progname, "exit", 1);
}


x86 assembly (clang, -O0):
<_ptrace_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e96(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%edx
mov    %ecx,%esi
call   1050 <ptrace@plt>
cmp    $0x0,%rax
je     119d <_ptrace_child+0x6d>
mov    0x2e68(%rip),%rax
cmpq   $0x0,(%rax)
je     119d <_ptrace_child+0x6d>
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x1,%edx
call   1040 <_error@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<_ptrace_child>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ea1(%rip),%r15
movq   $0x0,(%r15)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
je     1180 <_ptrace_child+0x50>
cmpq   $0x0,(%r15)
je     1180 <_ptrace_child+0x50>
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1040 <_error@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@PT_TRACE_ME = global i32 0
@.str = [12 x i8] c"PT_TRACE_ME\00"
define i32 @_ptrace_child(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i64 0, i64* @errno
%4 = load i32, i32* @PT_TRACE_ME
%5 = call i64 @ptrace(i32 %4, i32 0, i32* null, i32 0)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = call i32 @_error(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %14
14: ; preds = %10, %7, %1
%15 = load i32, i32* %3
%16 = call i32 @_exit(i32 %15)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@PT_TRACE_ME = global i32 0
@.str = [12 x i8] c"PT_TRACE_ME\00"
define i32 @_ptrace_child(i8* %0) {
store i64 0, i64* @errno
%2 = load i32, i32* @PT_TRACE_ME
%3 = tail call i64 @ptrace(i32 %2, i32 0, i32* null, i32 0)
%4 = icmp ne i64 %3, 0
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
%7 = select i1 %4, i1 %6, i1 false
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @_error(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = add nsw i32 %9, 1
br label %11
11: ; preds = %8, %1
%12 = phi i32 [ %10, %8 ], [ 0, %1 ]
%13 = tail call i32 @_exit(i32 %12)
unreachable
}