#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 void *uint64_t;
struct user_regs_struct {
  void *rax;
  void *rip;
  void *r9;
  void *r8;
  void *r10;
  void *rdx;
  void *rsi;
  void *rdi;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ PTRACE_SETREGS;
int /*<<< orphan*/ PTRACE_SINGLESTEP;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ find_syscall_addr(int /*<<< orphan*/, void *);
int /*<<< orphan*/ logs(int, char *, ...);
int /*<<< orphan*/ memcpy(struct user_regs_struct *, struct user_regs_struct *,
                          int);
int /*<<< orphan*/ peek_text(int /*<<< orphan*/, void *, char *, int);
int /*<<< orphan*/ poke_text(int /*<<< orphan*/, void *, char *, int);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  struct user_regs_struct *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
uint64_t remote_syscall(pid_t pid, uint64_t rax, uint64_t rdi, uint64_t rsi,
                        uint64_t rdx, uint64_t r10, uint64_t r8, uint64_t r9) {
  struct user_regs_struct regs, return_regs;
  bool substitute = false;
  char saved_text[2];
  char *syscall_opt = "\x0f\x05";
  int syscall_len = 2;
  if (ptrace(PTRACE_GETREGS, pid, NULL, &regs) < 0) {
    logs(2, "%s: %s", "ptrace GETREGS", strerror(errno));
    exit(1);
  }
  memcpy(&return_regs, &regs, sizeof(struct user_regs_struct));
  return_regs.rax = rax;
  return_regs.rdi = rdi;
  return_regs.rsi = rsi;
  return_regs.rdx = rdx;
  return_regs.r10 = r10;
  return_regs.r8 = r8;
  return_regs.r9 = r9;
  void *ret = (void *)find_syscall_addr(pid, return_regs.rip);
  if (ret == NULL) {
    logs(1, "cant find any syscall, using substitution method");
    peek_text(pid, regs.rip, saved_text, syscall_len);
    substitute = true;
  } else {
    return_regs.rip = (uint64_t)ret;
  }
  if (ptrace(PTRACE_SETREGS, pid, NULL, &return_regs) < 0) {
    logs(2, "%s: %s", "ptrace SETREGS", strerror(errno));
    exit(1);
  }
  if (substitute) {
    poke_text(pid, regs.rip, syscall_opt, syscall_len);
  }
  if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
    logs(2, "%s: %s", "ptrace SINGLESTEP", strerror(errno));
    exit(1);
  }
  waitpid(pid, NULL, 0);
  if (ptrace(PTRACE_GETREGS, pid, NULL, &return_regs) < 0) {
    logs(2, "%s: %s", "ptrace GETREGS", strerror(errno));
    exit(1);
  }
  if (ptrace(PTRACE_SETREGS, pid, NULL, &regs) < 0) {
    logs(2, "%s: %s", "ptrace SETREGS", strerror(errno));
    exit(1);
  }
  if (substitute) {
    poke_text(pid, regs.rip, saved_text, syscall_len);
  }
  return return_regs.rax;
}


x86 assembly (clang, -O0):
<remote_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0xb4(%rbp)
lea    0xe35(%rip),%rax
mov    %rax,-0xc0(%rbp)
movl   $0x2,-0xc4(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x70(%rbp),%rcx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    1233 <remote_syscall+0xa3>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xde8(%rip),%rsi
lea    0xde8(%rip),%rdx
mov    $0x0,%al
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xa8(%rbp),%rsi
call   1080 <find_syscall_addr@plt>
mov    %rax,-0xd0(%rbp)
cmpq   $0x0,-0xd0(%rbp)
jne    12ee <remote_syscall+0x15e>
mov    $0x1,%edi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1070 <logs@plt>
mov    -0x4(%rbp),%edi
mov    -0x68(%rbp),%rsi
lea    -0xb6(%rbp),%rdx
mov    -0xc4(%rbp),%ecx
call   1040 <peek_text@plt>
movl   $0x1,-0xb4(%rbp)
jmp    12fc <remote_syscall+0x16c>
mov    -0xd0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0xb0(%rbp),%rcx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    1356 <remote_syscall+0x1c6>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xcc5(%rip),%rsi
lea    0xd05(%rip),%rdx
mov    $0x0,%al
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0xb4(%rbp)
je     137c <remote_syscall+0x1ec>
mov    -0x4(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    -0xc0(%rbp),%rdx
mov    -0xc4(%rbp),%ecx
call   1030 <poke_text@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    13d2 <remote_syscall+0x242>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xc49(%rip),%rsi
lea    0xc98(%rip),%rdx
mov    $0x0,%al
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0xb0(%rbp),%rcx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    143a <remote_syscall+0x2aa>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xbe1(%rip),%rsi
lea    0xbe1(%rip),%rdx
mov    $0x0,%al
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x70(%rbp),%rcx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    1491 <remote_syscall+0x301>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xb8a(%rip),%rsi
lea    0xbca(%rip),%rdx
mov    $0x0,%al
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0xb4(%rbp)
je     14b7 <remote_syscall+0x327>
mov    -0x4(%rbp),%edi
mov    -0x68(%rbp),%rsi
lea    -0xb6(%rbp),%rdx
mov    -0xc4(%rbp),%ecx
call   1030 <poke_text@plt>
mov    -0xb0(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remote_syscall>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0x48(%rsp),%rcx
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <ptrace@plt>
test   %rax,%rax
js     1346 <remote_syscall+0x1b6>
lea    0x8(%rsp),%rdi
lea    0x48(%rsp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    %rbp,0x8(%rsp)
mov    %r13,0x40(%rsp)
mov    %r12,0x38(%rsp)
mov    %r15,0x30(%rsp)
mov    %r14,0x28(%rsp)
mov    0xc0(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    0xc8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%rsi
mov    %ebx,%edi
call   1080 <find_syscall_addr@plt>
mov    %rax,%r14
test   %rax,%rax
je     1253 <remote_syscall+0xc3>
mov    %r14,0x10(%rsp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rcx
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <ptrace@plt>
test   %rax,%rax
jns    12b4 <remote_syscall+0x124>
jmp    1364 <remote_syscall+0x1d4>
lea    0xdbf(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <logs@plt>
mov    0x50(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    %ebx,%edi
mov    $0x2,%ecx
call   1040 <peek_text@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rcx
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <ptrace@plt>
test   %rax,%rax
js     1364 <remote_syscall+0x1d4>
mov    0x50(%rsp),%rsi
lea    0xd58(%rip),%rdx
mov    %ebx,%edi
mov    $0x2,%ecx
call   1030 <poke_text@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
js     1382 <remote_syscall+0x1f2>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rcx
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <ptrace@plt>
test   %rax,%rax
js     1346 <remote_syscall+0x1b6>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0x48(%rsp),%rcx
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <ptrace@plt>
test   %rax,%rax
js     1364 <remote_syscall+0x1d4>
test   %r14,%r14
jne    132f <remote_syscall+0x19f>
mov    0x50(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    %ebx,%edi
mov    $0x2,%ecx
call   1030 <poke_text@plt>
mov    0x8(%rsp),%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xca8(%rip),%rsi
lea    0xca8(%rip),%rdx
jmp    139e <remote_syscall+0x20e>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xc8a(%rip),%rsi
lea    0xcca(%rip),%rdx
jmp    139e <remote_syscall+0x20e>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xc6c(%rip),%rsi
lea    0xcbb(%rip),%rdx
mov    $0x2,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <logs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.user_regs_struct = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@.str = [3 x i8] c"\0F\05\00"
@PTRACE_GETREGS = global i32 0
@.str.1 = [7 x i8] c"%s: %s\00"
@.str.2 = [15 x i8] c"ptrace GETREGS\00"
@errno = global i32 0
@.str.3 = [49 x i8] c"cant find any syscall, using substitution method\00"
@PTRACE_SETREGS = global i32 0
@.str.4 = [15 x i8] c"ptrace SETREGS\00"
@PTRACE_SINGLESTEP = global i32 0
@.str.5 = [18 x i8] c"ptrace SINGLESTEP\00"
define i8* @remote_syscall(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i8* %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca %struct.user_regs_struct
%18 = alloca %struct.user_regs_struct
%19 = alloca i32
%20 = alloca [2 x i8]
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i8*
store i32 %0, i32* %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
store i8* %7, i8** %16
store i32 0, i32* %19
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %21
store i32 2, i32* %22
%24 = load i32, i32* @PTRACE_GETREGS
%25 = load i32, i32* %9
%26 = call i64 @ptrace(i32 %24, i32 %25, i32* null, %struct.user_regs_struct* %17)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %8
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %8
%34 = call i32 @memcpy(%struct.user_regs_struct* %18, %struct.user_regs_struct* %17, i32 64)
%35 = load i8*, i8** %10
%36 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 0
store i8* %35, i8** %36
%37 = load i8*, i8** %11
%38 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 7
store i8* %37, i8** %38
%39 = load i8*, i8** %12
%40 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 6
store i8* %39, i8** %40
%41 = load i8*, i8** %13
%42 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 5
store i8* %41, i8** %42
%43 = load i8*, i8** %14
%44 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 4
store i8* %43, i8** %44
%45 = load i8*, i8** %15
%46 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 3
store i8* %45, i8** %46
%47 = load i8*, i8** %16
%48 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 2
store i8* %47, i8** %48
%49 = load i32, i32* %9
%50 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 1
%51 = load i8*, i8** %50
%52 = call i64 @find_syscall_addr(i32 %49, i8* %51)
%53 = inttoptr i64 %52 to i8*
store i8* %53, i8** %23
%54 = load i8*, i8** %23
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %64
56: ; preds = %33
%57 = call i32 (i32, i8*, ...) @logs(i32 1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* %9
%59 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %17, i32 0, i32 1
%60 = load i8*, i8** %59
%61 = getelementptr inbounds [2 x i8], [2 x i8]* %20, i64 0, i64 0
%62 = load i32, i32* %22
%63 = call i32 @peek_text(i32 %58, i8* %60, i8* %61, i32 %62)
store i32 1, i32* %19
br label %67
64: ; preds = %33
%65 = load i8*, i8** %23
%66 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 1
store i8* %65, i8** %66
br label %67
67: ; preds = %64, %56
%68 = load i32, i32* @PTRACE_SETREGS
%69 = load i32, i32* %9
%70 = call i64 @ptrace(i32 %68, i32 %69, i32* null, %struct.user_regs_struct* %18)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %67
%78 = load i32, i32* %19
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %87
80: ; preds = %77
%81 = load i32, i32* %9
%82 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %17, i32 0, i32 1
%83 = load i8*, i8** %82
%84 = load i8*, i8** %21
%85 = load i32, i32* %22
%86 = call i32 @poke_text(i32 %81, i8* %83, i8* %84, i32 %85)
br label %87
87: ; preds = %80, %77
%88 = load i32, i32* @PTRACE_SINGLESTEP
%89 = load i32, i32* %9
%90 = call i64 @ptrace(i32 %88, i32 %89, i32* null, %struct.user_regs_struct* null)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %87
%93 = load i32, i32* @errno
%94 = call i32 @strerror(i32 %93)
%95 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %94)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %87
%98 = load i32, i32* %9
%99 = call i32 @waitpid(i32 %98, i32* null, i32 0)
%100 = load i32, i32* @PTRACE_GETREGS
%101 = load i32, i32* %9
%102 = call i64 @ptrace(i32 %100, i32 %101, i32* null, %struct.user_regs_struct* %18)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %97
%105 = load i32, i32* @errno
%106 = call i32 @strerror(i32 %105)
%107 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %106)
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %97
%110 = load i32, i32* @PTRACE_SETREGS
%111 = load i32, i32* %9
%112 = call i64 @ptrace(i32 %110, i32 %111, i32* null, %struct.user_regs_struct* %17)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %119
114: ; preds = %109
%115 = load i32, i32* @errno
%116 = call i32 @strerror(i32 %115)
%117 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %116)
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %109
%120 = load i32, i32* %19
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %129
122: ; preds = %119
%123 = load i32, i32* %9
%124 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %17, i32 0, i32 1
%125 = load i8*, i8** %124
%126 = getelementptr inbounds [2 x i8], [2 x i8]* %20, i64 0, i64 0
%127 = load i32, i32* %22
%128 = call i32 @poke_text(i32 %123, i8* %125, i8* %126, i32 %127)
br label %129
129: ; preds = %122, %119
%130 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %18, i32 0, i32 0
%131 = load i8*, i8** %130
ret i8* %131
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@.str = [3 x i8] c"\0F\05\00"
@PTRACE_GETREGS = global i32 0
@.str.1 = [7 x i8] c"%s: %s\00"
@.str.2 = [15 x i8] c"ptrace GETREGS\00"
@errno = global i32 0
@.str.3 = [49 x i8] c"cant find any syscall, using substitution method\00"
@PTRACE_SETREGS = global i32 0
@.str.4 = [15 x i8] c"ptrace SETREGS\00"
@PTRACE_SINGLESTEP = global i32 0
@.str.5 = [18 x i8] c"ptrace SINGLESTEP\00"
define i8* @remote_syscall(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i8* %7) {
%9 = alloca %struct.user_regs_struct
%10 = alloca %struct.user_regs_struct
%11 = alloca [2 x i8]
%12 = bitcast %struct.user_regs_struct* %9 to i8*
%13 = bitcast %struct.user_regs_struct* %10 to i8*
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%15 = load i32, i32* @PTRACE_GETREGS
%16 = call i64 @ptrace(i32 %15, i32 %0, i32* null, %struct.user_regs_struct* %9)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %8
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %8
%24 = call i32 @memcpy(%struct.user_regs_struct* %10, %struct.user_regs_struct* %9, i32 64)
%25 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 0
store i8* %1, i8** %25
%26 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 7
store i8* %2, i8** %26
%27 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 6
store i8* %3, i8** %27
%28 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 5
store i8* %4, i8** %28
%29 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 4
store i8* %5, i8** %29
%30 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 3
store i8* %6, i8** %30
%31 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 2
store i8* %7, i8** %31
%32 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %10, i64 0, i32 1
%33 = load i8*, i8** %32
%34 = call i64 @find_syscall_addr(i32 %0, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %23
%37 = call i32 (i32, i8*, ...) @logs(i32 1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%38 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %9, i64 0, i32 1
%39 = load i8*, i8** %38
%40 = call i32 @peek_text(i32 %0, i8* %39, i8* %14, i32 2)
%41 = load i32, i32* @PTRACE_SETREGS
%42 = call i64 @ptrace(i32 %41, i32 %0, i32* null, %struct.user_regs_struct* %10)
%43 = icmp slt i64 %42, 0
br i1 %43, label %49, label %54
44: ; preds = %23
%45 = inttoptr i64 %34 to i8*
store i8* %45, i8** %32
%46 = load i32, i32* @PTRACE_SETREGS
%47 = call i64 @ptrace(i32 %46, i32 %0, i32* null, %struct.user_regs_struct* %10)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %44, %36
%50 = load i32, i32* @errno
%51 = call i32 @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %36
%55 = load i8*, i8** %38
%56 = call i32 @poke_text(i32 %0, i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %57
57: ; preds = %44, %54
%58 = load i32, i32* @PTRACE_SINGLESTEP
%59 = call i64 @ptrace(i32 %58, i32 %0, i32* null, %struct.user_regs_struct* null)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = load i32, i32* @errno
%63 = call i32 @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %57
%67 = call i32 @waitpid(i32 %0, i32* null, i32 0)
%68 = load i32, i32* @PTRACE_GETREGS
%69 = call i64 @ptrace(i32 %68, i32 %0, i32* null, %struct.user_regs_struct* %10)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i32, i32* @errno
%73 = call i32 @strerror(i32 %72)
%74 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %66
%77 = load i32, i32* @PTRACE_SETREGS
%78 = call i64 @ptrace(i32 %77, i32 %0, i32* null, %struct.user_regs_struct* %9)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = load i32, i32* @errno
%82 = call i32 @strerror(i32 %81)
%83 = call i32 (i32, i8*, ...) @logs(i32 2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %82)
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %76
br i1 %35, label %86, label %90
86: ; preds = %85
%87 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %9, i64 0, i32 1
%88 = load i8*, i8** %87
%89 = call i32 @poke_text(i32 %0, i8* %88, i8* %14, i32 2)
br label %90
90: ; preds = %86, %85
%91 = load i8*, i8** %25
ret i8* %91
}