#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 */
struct sigaction {
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_flags;
  int /*<<< orphan*/ sa_handler;
};

/* Variables and functions */
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ SA_RESTART;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void do_child(void) {
  struct sigaction child_act;
  child_act.sa_handler = SIG_IGN;
  child_act.sa_flags = SA_RESTART;
  sigemptyset(&child_act.sa_mask);
  sigaction(SIGUSR2, &child_act, NULL);
  ptrace(PTRACE_TRACEME, 0, 0, 0);
  kill(getpid(), SIGUSR2);
  exit(1);
}


x86 assembly (clang, -O0):
<do_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1070 <ptrace@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<do_child>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e33(%rip),%r14
mov    (%r14),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <ptrace@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1060 <kill@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i32 }
@SIG_IGN = global i32 0
@SA_RESTART = global i32 0
@SIGUSR2 = global i32 0
@PTRACE_TRACEME = global i32 0
define void @do_child() {
%1 = alloca %struct.sigaction
%2 = load i32, i32* @SIG_IGN
%3 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 2
store i32 %2, i32* %3
%4 = load i32, i32* @SA_RESTART
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
%7 = call i32 @sigemptyset(i32* %6)
%8 = load i32, i32* @SIGUSR2
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %1, i32* null)
%10 = load i32, i32* @PTRACE_TRACEME
%11 = call i32 @ptrace(i32 %10, i32 0, i32 0, i32 0)
%12 = call i32 (...) @getpid()
%13 = load i32, i32* @SIGUSR2
%14 = call i32 @kill(i32 %12, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i32 }
@SIG_IGN = global i32 0
@SA_RESTART = global i32 0
@SIGUSR2 = global i32 0
@PTRACE_TRACEME = global i32 0
define void @do_child() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = load i32, i32* @SIG_IGN
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 2
store i32 %3, i32* %4
%5 = load i32, i32* @SA_RESTART
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGUSR2
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %1, i32* null)
%11 = load i32, i32* @PTRACE_TRACEME
%12 = call i32 @ptrace(i32 %11, i32 0, i32 0, i32 0)
%13 = call i32 (...) @getpid()
%14 = load i32, i32* @SIGUSR2
%15 = call i32 @kill(i32 %13, i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
}