#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*/ errno;
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/);
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*/ *);
int /*<<< orphan*/ strerror(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) {
    ksft_print_msg("sched_setaffinity() failed: %s\n", strerror(errno));
    _exit(1);
  }
  if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
    ksft_print_msg("ptrace(PTRACE_TRACEME) failed: %s\n", strerror(errno));
    _exit(1);
  }
  if (raise(SIGSTOP) != 0) {
    ksft_print_msg("raise(SIGSTOP) failed: %s\n", strerror(errno));
    _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   1080 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   10a0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1050 <sched_setaffinity@plt>
cmp    $0x0,%rax
je     11e0 <child+0x60>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe2f(%rip),%rdi
call   1070 <ksft_print_msg@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    0x2df9(%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     1227 <child+0xa7>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
call   1070 <ksft_print_msg@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
cmp    $0x0,%rax
je     1265 <child+0xe5>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xded(%rip),%rdi
call   1070 <ksft_print_msg@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   1080 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10a0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1050 <sched_setaffinity@plt>
test   %rax,%rax
jne    11e4 <child+0x64>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
jne    11fb <child+0x7b>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    1212 <child+0x92>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe07(%rip),%rdi
jmp    1227 <child+0xa7>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe10(%rip),%rdi
jmp    1227 <child+0xa7>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe1c(%rip),%rdi
mov    %eax,%esi
call   1070 <ksft_print_msg@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"sched_setaffinity() failed: %s\0A\00"
@errno = global i32 0
@PTRACE_TRACEME = global i32 0
@.str.1 = [35 x i8] c"ptrace(PTRACE_TRACEME) failed: %s\0A\00"
@SIGSTOP = global i32 0
@.str.2 = [27 x i8] c"raise(SIGSTOP) failed: %s\0A\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 %14
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @_exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32, i32* @PTRACE_TRACEME
%16 = call i64 @ptrace(i32 %15, i32 0, i32* null, i32* null)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @_exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32, i32* @SIGSTOP
%25 = call i64 @raise(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i32 @_exit(i32 1)
unreachable
32: ; preds = %23
%33 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [32 x i8] c"sched_setaffinity() failed: %s\0A\00"
@errno = global i32 0
@PTRACE_TRACEME = global i32 0
@.str.1 = [35 x i8] c"ptrace(PTRACE_TRACEME) failed: %s\0A\00"
@SIGSTOP = global i32 0
@.str.2 = [27 x i8] c"raise(SIGSTOP) failed: %s\0A\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 %13, label %8
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @_exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* @PTRACE_TRACEME
%15 = call i64 @ptrace(i32 %14, i32 0, i32* null, i32* null)
%16 = icmp eq i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @_exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @SIGSTOP
%24 = call i64 @raise(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @_exit(i32 1)
unreachable
31: ; preds = %22
%32 = call i32 @_exit(i32 0)
unreachable
}