#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 */
typedef int /*<<< orphan*/ set;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
scalar_t__ raise(int /*<<< orphan*/);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
void child(int cpu) {
  cpu_set_t set;
  CPU_ZERO(&set);
  CPU_SET(cpu, &set);
  if (sched_setaffinity(0, sizeof(set), &set) != 0) {
    perror("sched_setaffinity() failed");
    _exit(1);
  }
  if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
    perror("ptrace(PTRACE_TRACEME) failed");
    _exit(1);
  }
  if (raise(SIGSTOP) != 0) {
    perror("raise(SIGSTOP) failed");
    _exit(1);
  }
  _exit(0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1050 <sched_setaffinity@plt>
cmp    $0x0,%rax
je     11c0 <child+0x50>
lea    0xe4f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
je     11f7 <child+0x87>
lea    0xe33(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
cmp    $0x0,%rax
je     1225 <child+0xb5>
lea    0xe23(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

x86 assembly (clang, -O2):
<child>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1070 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1050 <sched_setaffinity@plt>
test   %rax,%rax
jne    11d4 <child+0x64>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
jne    11dd <child+0x6d>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    11e6 <child+0x76>
xor    %edi,%edi
call   1040 <_exit@plt>
lea    0xe25(%rip),%rdi
jmp    11ed <child+0x7d>
lea    0xe37(%rip),%rdi
jmp    11ed <child+0x7d>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"sched_setaffinity() failed\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [30 x i8] c"ptrace(PTRACE_TRACEME) failed\00"
@SIGSTOP = global i32 0
@.str.2 = [22 x i8] c"raise(SIGSTOP) failed\00"
define void @child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @CPU_ZERO(i32* %3)
%5 = load i32, i32* %2
%6 = call i32 @CPU_SET(i32 %5, i32* %3)
%7 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %3)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @_exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @PTRACE_TRACEME
%14 = call i64 @ptrace(i32 %13, i32 0, i32* null, i32* null)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @_exit(i32 1)
unreachable
19: ; preds = %12
%20 = load i32, i32* @SIGSTOP
%21 = call i64 @raise(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @_exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [27 x i8] c"sched_setaffinity() failed\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [30 x i8] c"ptrace(PTRACE_TRACEME) failed\00"
@SIGSTOP = global i32 0
@.str.2 = [22 x i8] c"raise(SIGSTOP) failed\00"
define void @child(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @CPU_ZERO(i32* %2)
%5 = call i32 @CPU_SET(i32 %0, i32* %2)
%6 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @_exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i32, i32* @PTRACE_TRACEME
%13 = call i64 @ptrace(i32 %12, i32 0, i32* null, i32* null)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @_exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* @SIGSTOP
%20 = call i64 @raise(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @_exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i32 @_exit(i32 0)
unreachable
}