#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*/ PTRACE_TRACEME;
int /*<<< orphan*/ SIGSTOP;
scalar_t__ errno;
int /*<<< orphan*/ getpid();
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int clone_child(void *arg) {
  errno = 0;
  ptrace(PTRACE_TRACEME, 0, 0, 0);
  if (errno != 0)
    perror("ptrace");
  if (kill(getpid(), SIGSTOP) < 0)
    perror("kill");
  return 0;
}


x86 assembly (clang, -O0):
<clone_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1050 <ptrace@plt>
mov    0x2e63(%rip),%rax
cmpq   $0x0,(%rax)
je     118b <clone_child+0x4b>
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
jge    11b8 <clone_child+0x78>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clone_child>:
push   %rbx
mov    0x2e90(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
cmpq   $0x0,(%rbx)
jne    1189 <clone_child+0x49>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2e59(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <kill@plt>
test   %rax,%rax
js     1197 <clone_child+0x57>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
jmp    1169 <clone_child+0x29>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
jmp    1185 <clone_child+0x45>

LLVM IR (-O0):
@errno = global i64 0
@PTRACE_TRACEME = global i32 0
@.str = [7 x i8] c"ptrace\00"
@SIGSTOP = global i32 0
@.str.1 = [5 x i8] c"kill\00"
define i32 @clone_child(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%3 = load i32, i32* @PTRACE_TRACEME
%4 = call i32 @ptrace(i32 %3, i32 0, i32 0, i32 0)
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i32 (...) @getpid()
%11 = load i32, i32* @SIGSTOP
%12 = call i64 @kill(i32 %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@PTRACE_TRACEME = global i32 0
@.str = [7 x i8] c"ptrace\00"
@SIGSTOP = global i32 0
@.str.1 = [5 x i8] c"kill\00"
define i32 @clone_child(i8* nocapture readnone %0) {
store i64 0, i64* @errno
%2 = load i32, i32* @PTRACE_TRACEME
%3 = tail call i32 @ptrace(i32 %2, i32 0, i32 0, i32 0)
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = tail call i32 (...) @getpid()
%10 = load i32, i32* @SIGSTOP
%11 = tail call i64 @kill(i32 %9, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
ret i32 0
}