#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 user_regs_struct {
  int orig_rax;
  int rdx;
  int rdi;
  int rsi;
  int /*<<< orphan*/ rax;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ SYS_ptrace;
int /*<<< orphan*/ assert(int);
long syscall(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/ *, struct user_regs_struct *);
int is_magic_syscall(pid_t pid, int *syscall_no, int *command, int *is_entry) {
  long res;
  struct user_regs_struct regs;
  int is_magic;
  res = syscall(SYS_ptrace, PTRACE_GETREGS, pid, NULL, &regs);
  assert(res == 0);
  *syscall_no = regs.orig_rax;
  *command = regs.rdx;
  *is_entry = regs.rax == -ENOSYS ? 1 : 0;
  is_magic =
      regs.rdi == 0x7a711e06171129a2UL && regs.rsi == 0xc6925d1ed6dcd674UL;
  return is_magic;
}


x86 assembly (clang, -O0):
<is_magic_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x40(%rbp),%r8
call   1040 <syscall@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x40(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%edx
xor    %esi,%esi
mov    0x2e5b(%rip),%rax
sub    (%rax),%esi
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    %esi,%edx
cmove  %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x38(%rbp),%rcx
xor    %eax,%eax
movabs $0x7a711e06171129a2,%rdx
1e 71 7a
cmp    %rdx,%rcx
mov    %al,-0x45(%rbp)
jne    11d4 <is_magic_syscall+0xb4>
movslq -0x34(%rbp),%rax
movabs $0xc6925d1ed6dcd674,%rcx
5d 92 c6
cmp    %rcx,%rax
sete   %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_magic_syscall>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%edx
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r8
xor    %ecx,%ecx
call   1040 <syscall@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    0x8(%rsp),%eax
mov    %eax,(%rbx)
mov    0xc(%rsp),%eax
mov    %eax,(%r15)
mov    0x18(%rsp),%eax
mov    0x2e70(%rip),%rcx
xor    %edx,%edx
add    (%rcx),%eax
sete   %dl
mov    %edx,(%r14)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.user_regs_struct = type { i32, i32, i32, i32, i32 }
@SYS_ptrace = global i32 0
@PTRACE_GETREGS = global i32 0
@ENOSYS = global i32 0
define i32 @is_magic_syscall(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca %struct.user_regs_struct
%11 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i32, i32* @SYS_ptrace
%13 = load i32, i32* @PTRACE_GETREGS
%14 = load i32, i32* %5
%15 = call i64 @syscall(i32 %12, i32 %13, i32 %14, i32* null, %struct.user_regs_struct* %10)
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32*, i32** %6
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load i32*, i32** %7
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i32 0, i32 4
%27 = load i32, i32* %26
%28 = load i32, i32* @ENOSYS
%29 = sub nsw i32 0, %28
%30 = icmp eq i32 %27, %29
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 0
%33 = load i32*, i32** %8
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i32 0, i32 2
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = icmp eq i64 %36, 8822866156501150114
br i1 %37, label %38, label %43
38: ; preds = %4
%39 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i32 0, i32 3
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = icmp eq i64 %41, -4138142720564865420
br label %43
43: ; preds = %38, %4
%44 = phi i1 [ false, %4 ], [ %42, %38 ]
%45 = zext i1 %44 to i32
store i32 %45, i32* %11
%46 = load i32, i32* %11
ret i32 %46
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i32, i32, i32, i32, i32 }
@SYS_ptrace = global i32 0
@PTRACE_GETREGS = global i32 0
@ENOSYS = global i32 0
define i32 @is_magic_syscall(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.user_regs_struct
%6 = bitcast %struct.user_regs_struct* %5 to i8*
%7 = load i32, i32* @SYS_ptrace
%8 = load i32, i32* @PTRACE_GETREGS
%9 = call i64 @syscall(i32 %7, i32 %8, i32 %0, i32* null, %struct.user_regs_struct* %5)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %1
%15 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %2
%17 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 4
%18 = load i32, i32* %17
%19 = load i32, i32* @ENOSYS
%20 = sub nsw i32 0, %19
%21 = icmp eq i32 %18, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %3
ret i32 0
}