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

/* Variables and functions */
int /*<<< orphan*/ PTRACE_ATTACH;
int /*<<< orphan*/ PTRACE_DETACH;
int /*<<< orphan*/ PTRACE_GETREGS;
int /*<<< orphan*/ PTRACE_PEEKTEXT;
int /*<<< orphan*/ PTRACE_POKETEXT;
int /*<<< orphan*/ PTRACE_SETREGS;
int /*<<< orphan*/ PTRACE_SINGLESTEP;
int /*<<< orphan*/ atoi(char *);
int cpy_str(int /*<<< orphan*/, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(struct user_regs_struct *, struct user_regs_struct *,
                          int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *, ...);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ sprintf(unsigned char *, char *, ...);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  unsigned char buf[256], cmd[4096], *p;
  int l, i, slen;
  pid_t _pid;
  struct user_regs_struct regs;
  struct user_regs_struct regs_cpy;
  int status;
  long opcode, opcode1;
  _pid = atoi(argv[1]);
  printf("+ Attaching to process %ld\n", _pid);
  if ((ptrace(PTRACE_ATTACH, _pid, NULL, NULL)) < 0)
    perror("ptrace_attach:");
  printf("%s", " ..... Waiting for process...\n");
  wait(&status);
  printf("+ Getting current registers state....\n");
  if ((ptrace(PTRACE_GETREGS, _pid, 0, &regs)) < 0)
    perror("ptrace_get_regs:");
  printf("  -> Process stopped at : %p\n", regs.rip);
  printf("  -> Stack  at          : %p\n", regs.rsp);
  printf("+ Current register set copied...\n");
  memcpy(&regs_cpy, &regs, sizeof(struct user_regs_struct));
  printf("+ Retrieving opcode from (%llx) -> ", regs.rip);
  if ((opcode = ptrace(PTRACE_PEEKTEXT, _pid, regs.rip, 0)) < 0)
    perror("retrieve opcode:");
  printf("0x%lx\n", opcode);
  ptrace(PTRACE_POKETEXT, _pid, regs.rip, 0x050f050f050f050f);
  printf("+ Pushing string into stack...\n");
  regs.rsp -= 2048;
  while (1) {
    memset(cmd, 0, 4096);
    p = cmd;
    if ((l = read(0, buf, 256)) <= 0)
      break;
    p += sprintf(p, "echo -n -e \"");
    for (i = 0; i < l; i++)
      p += sprintf(p, "\\\\x%02x", buf[i]);
    p += sprintf(p, "\" > k\n");
    printf("--------------------\n");
    printf("%s", cmd);
    printf("--------------------\n");
    slen = cpy_str(_pid, cmd, regs.rsp);
    printf("+ Preparing for syscall....\n");
    regs.rax = 1;
    regs.rdi = 5;
    regs.rsi = regs.rsp;
    regs.rdx = slen;
    if ((ptrace(PTRACE_SETREGS, _pid, 0, &regs)) < 0)
      perror("ptrace_set_regs:");
    printf("+ Run single step...\n");
    if ((ptrace(PTRACE_SINGLESTEP, _pid, 0, 0)) < 0)
      perror("Run syscallL");
    printf("%s", "+ Waiting for process...\n");
    wait(&status);
    if ((ptrace(PTRACE_SINGLESTEP, _pid, 0, 0)) < 0)
      perror("Run syscallL");
    printf("%s", "+ Waiting for process...\n");
    wait(&status);
  }
  printf("Restoring opcode att : %p\n", regs_cpy.rip);
  if ((ptrace(PTRACE_POKETEXT, _pid, regs_cpy.rip, opcode)) < 0)
    perror("Restore opcode:");
  printf("0x%lx\n", opcode);
  printf("+Restoting original registers\n");
  if ((ptrace(PTRACE_SETREGS, _pid, 0, &regs_cpy)) < 0)
    perror("ptrace_set_regs:");
  printf("Registers successfully restored\n");
  printf("+ Deataching process...\n");
  if ((ptrace(PTRACE_DETACH, _pid, NULL, NULL)) < 0)
    perror("ptrace_deattach:");
  wait(&status);
  printf("Releasing process...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1128(%rbp)
mov    -0x1128(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    1213 <main+0x73>
lea    0xe0e(%rip),%rdi
call   1090 <perror@plt>
lea    0xe11(%rip),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x116c(%rbp),%rdi
call   10c0 <wait@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x1148(%rbp),%rcx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    1279 <main+0xd9>
lea    0xe00(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1138(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1130(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1168(%rbp),%rdi
lea    -0x1148(%rbp),%rsi
mov    $0x20,%edx
call   1070 <memcpy@plt>
mov    -0x1138(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
mov    -0x1138(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1080 <ptrace@plt>
mov    %rax,-0x1178(%rbp)
cmp    $0x0,%rax
jge    1319 <main+0x179>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1178(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
mov    -0x1138(%rbp),%rdx
movabs $0x50f050f050f050f,%rcx
05 0f 05
mov    $0x0,%al
call   1080 <ptrace@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1130(%rbp),%eax
sub    $0x800,%eax
mov    %eax,-0x1130(%rbp)
lea    -0x1110(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    -0x1110(%rbp),%rax
mov    %rax,-0x1118(%rbp)
lea    -0x110(%rbp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x111c(%rbp)
cmp    $0x0,%eax
jg     13bc <main+0x21c>
jmp    15f5 <main+0x455>
mov    -0x1118(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x1118(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1118(%rbp)
movl   $0x0,-0x1120(%rbp)
mov    -0x1120(%rbp),%eax
cmp    -0x111c(%rbp),%eax
jge    1451 <main+0x2b1>
mov    -0x1118(%rbp),%rdi
movslq -0x1120(%rbp),%rax
movzbl -0x110(%rbp,%rax,1),%edx
ff
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x1118(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1118(%rbp)
mov    -0x1120(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1120(%rbp)
jmp    13f1 <main+0x251>
mov    -0x1118(%rbp),%rdi
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,%ecx
mov    -0x1118(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1118(%rbp)
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1110(%rbp),%rsi
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1128(%rbp),%edi
lea    -0x1110(%rbp),%rsi
mov    -0x1130(%rbp),%edx
call   1030 <cpy_str@plt>
mov    %eax,-0x1124(%rbp)
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1148(%rbp)
movl   $0x5,-0x1144(%rbp)
mov    -0x1130(%rbp),%eax
mov    %eax,-0x112c(%rbp)
mov    -0x1124(%rbp),%eax
mov    %eax,-0x1140(%rbp)
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x1148(%rbp),%rcx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    153c <main+0x39c>
lea    0xc57(%rip),%rdi
call   1090 <perror@plt>
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2a6f(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    157c <main+0x3dc>
lea    0xc3e(%rip),%rdi
call   1090 <perror@plt>
lea    0xaa8(%rip),%rdi
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x116c(%rbp),%rdi
call   10c0 <wait@plt>
mov    0x2a1c(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    15cf <main+0x42f>
lea    0xbeb(%rip),%rdi
call   1090 <perror@plt>
lea    0xa55(%rip),%rdi
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x116c(%rbp),%rdi
call   10c0 <wait@plt>
jmp    1374 <main+0x1d4>
mov    -0x1158(%rbp),%rsi
lea    0xbd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x29a7(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
mov    -0x1158(%rbp),%rdx
mov    -0x1178(%rbp),%rcx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    1644 <main+0x4a4>
lea    0xbb8(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1178(%rbp),%rsi
lea    0xac6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xba7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x297a(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x1168(%rbp),%rcx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    169e <main+0x4fe>
lea    0xaf5(%rip),%rdi
call   1090 <perror@plt>
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xb94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x291f(%rip),%rax
mov    (%rax),%edi
mov    -0x1128(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1080 <ptrace@plt>
cmp    $0x0,%rax
jge    16ed <main+0x54d>
lea    0xb78(%rip),%rdi
call   1090 <perror@plt>
lea    -0x116c(%rbp),%rdi
call   10c0 <wait@plt>
lea    0xb71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1158,%rsp
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     15e5 <main+0x435>
lea    0xf29(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   10d0 <wait@plt>
lea    0xf33(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rcx
mov    %r15d,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     15f6 <main+0x446>
mov    0x18(%rsp),%rsi
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
mov    0x18(%rsp),%rsi
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rdx
mov    %r15d,%esi
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <ptrace@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1607 <main+0x457>
lea    0xdeb(%rip),%rdi
mov    %rbx,0x28(%rsp)
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rdx
movabs $0x50f050f050f050f,%rcx
05 0f 05
mov    %r15d,%esi
xor    %eax,%eax
call   1090 <ptrace@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
addl   $0xfffff800,0x20(%rsp)
ff
lea    0x150(%rsp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    0x50(%rsp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    150d <main+0x35d>
lea    0xd86(%rip),%rbx
lea    0x150(%rsp),%r14
mov    0x2c73(%rip),%r13
mov    %r15d,0x4(%rsp)
jmp    1398 <main+0x1e8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   10d0 <wait@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
xor    %edi,%edi
lea    0x50(%rsp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    150d <main+0x35d>
mov    %r14,%r12
movabs $0x2220652d206e2d,%rcx
mov    %rcx,0x155(%rsp)
movabs $0x206e2d206f686365,%rcx
2d 6e 20
mov    %rcx,0x150(%rsp)
mov    %eax,%ebp
xor    %r14d,%r14d
lea    0x15c(%rsp),%rax
nopl   0x0(%rax)
mov    %rax,%r15
movzbl 0x50(%rsp,%r14,1),%edx
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <sprintf@plt>
cltq
add    %r15,%rax
add    $0x1,%r14
cmp    %r14,%rbp
jne    13d0 <main+0x220>
movl   $0xa6b20,0x3(%rax)
movl   $0x203e2022,(%rax)
lea    0xda9(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xc14(%rip),%rdi
mov    %r12,%r14
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    0x20(%rsp),%edx
mov    0x4(%rsp),%r15d
mov    %r15d,%edi
mov    %r12,%rsi
call   1040 <cpy_str@plt>
mov    %eax,%ebp
lea    0xd7d(%rip),%rdi
call   1030 <puts@plt>
movabs $0x500000001,%rax
mov    %rax,0x8(%rsp)
mov    0x20(%rsp),%eax
mov    %eax,0x24(%rsp)
mov    %ebp,0x10(%rsp)
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%esi
xor    %edx,%edx
lea    0x8(%rsp),%rcx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     14f1 <main+0x341>
lea    0xd53(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%edi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
lea    0xd47(%rip),%r12
mov    %rsp,%rbp
js     14ff <main+0x34f>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   10d0 <wait@plt>
mov    0x0(%r13),%edi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
jns    1360 <main+0x1b0>
lea    0xbfd(%rip),%rdi
call   10a0 <perror@plt>
jmp    1360 <main+0x1b0>
lea    0xbdb(%rip),%rdi
call   10a0 <perror@plt>
jmp    1488 <main+0x2d8>
lea    0xbde(%rip),%rdi
call   10a0 <perror@plt>
jmp    14b5 <main+0x305>
mov    0x40(%rsp),%rsi
lea    0xbd8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2a91(%rip),%rax
mov    (%rax),%edi
mov    0x40(%rsp),%rdx
mov    %r15d,%esi
mov    0x28(%rsp),%rbx
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     1618 <main+0x468>
lea    0xb60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcaf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    0x30(%rsp),%rcx
mov    %r15d,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     1629 <main+0x479>
lea    0xc9e(%rip),%rdi
call   1030 <puts@plt>
lea    0xcb2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2a38(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <ptrace@plt>
test   %rax,%rax
js     163a <main+0x48a>
mov    %rsp,%rdi
call   10d0 <wait@plt>
lea    0xc9a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xa30(%rip),%rdi
call   10a0 <perror@plt>
jmp    11fd <main+0x4d>
lea    0xa31(%rip),%rdi
call   10a0 <perror@plt>
jmp    1240 <main+0x90>
lea    0xa91(%rip),%rdi
call   10a0 <perror@plt>
jmp    12be <main+0x10e>
lea    0xaed(%rip),%rdi
call   10a0 <perror@plt>
jmp    1549 <main+0x399>
lea    0xaa3(%rip),%rdi
call   10a0 <perror@plt>
jmp    1589 <main+0x3d9>
lea    0xadb(%rip),%rdi
call   10a0 <perror@plt>
jmp    15bd <main+0x40d>

LLVM IR (-O0):
%struct.user_regs_struct = type { i32, i32, i32, i32*, i32, i32 }
@.str = [28 x i8] c"+ Attaching to process %ld\0A\00"
@PTRACE_ATTACH = global i32 0
@.str.1 = [15 x i8] c"ptrace_attach:\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [31 x i8] c" ..... Waiting for process...\0A\00"
@.str.4 = [39 x i8] c"+ Getting current registers state....\0A\00"
@PTRACE_GETREGS = global i32 0
@.str.5 = [17 x i8] c"ptrace_get_regs:\00"
@.str.6 = [30 x i8] c" -> Process stopped at : %p\0A\00"
@.str.7 = [30 x i8] c" -> Stack at : %p\0A\00"
@.str.8 = [34 x i8] c"+ Current register set copied...\0A\00"
@.str.9 = [36 x i8] c"+ Retrieving opcode from (%llx) -> \00"
@PTRACE_PEEKTEXT = global i32 0
@.str.10 = [17 x i8] c"retrieve opcode:\00"
@.str.11 = [7 x i8] c"0x%lx\0A\00"
@PTRACE_POKETEXT = global i32 0
@.str.12 = [32 x i8] c"+ Pushing string into stack...\0A\00"
@.str.13 = [13 x i8] c"echo -n -e \22\00"
@.str.14 = [8 x i8] c"\\\\x%02x\00"
@.str.15 = [7 x i8] c"\22 > k\0A\00"
@.str.16 = [22 x i8] c"--------------------\0A\00"
@.str.17 = [29 x i8] c"+ Preparing for syscall....\0A\00"
@PTRACE_SETREGS = global i32 0
@.str.18 = [17 x i8] c"ptrace_set_regs:\00"
@.str.19 = [22 x i8] c"+ Run single step...\0A\00"
@PTRACE_SINGLESTEP = global i32 0
@.str.20 = [13 x i8] c"Run syscallL\00"
@.str.21 = [26 x i8] c"+ Waiting for process...\0A\00"
@.str.22 = [27 x i8] c"Restoring opcode att : %p\0A\00"
@.str.23 = [16 x i8] c"Restore opcode:\00"
@.str.24 = [31 x i8] c"+Restoting original registers\0A\00"
@.str.25 = [33 x i8] c"Registers successfully restored\0A\00"
@.str.26 = [25 x i8] c"+ Deataching process...\0A\00"
@PTRACE_DETACH = global i32 0
@.str.27 = [17 x i8] c"ptrace_deattach:\00"
@.str.28 = [22 x i8] c"Releasing process...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [4096 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.user_regs_struct
%14 = alloca %struct.user_regs_struct
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %12
%22 = load i32, i32* %12
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @PTRACE_ATTACH
%25 = load i32, i32* %12
%26 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %24, i32 %25, i32* null, i8* null)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @wait(i32* %15)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @PTRACE_GETREGS
%35 = load i32, i32* %12
%36 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %34, i32 %35, i32* null, %struct.user_regs_struct* %13)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
%41 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 3
%42 = load i32*, i32** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32* %42)
%44 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 4
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
%48 = call i32 @memcpy(%struct.user_regs_struct* %14, %struct.user_regs_struct* %13, i32 32)
%49 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 3
%50 = load i32*, i32** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32* %50)
%52 = load i32, i32* @PTRACE_PEEKTEXT
%53 = load i32, i32* %12
%54 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 3
%55 = load i32*, i32** %54
%56 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %52, i32 %53, i32* %55, i32 0)
store i64 %56, i64* %16
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %40
%59 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %60
60: ; preds = %58, %40
%61 = load i64, i64* %16
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i64 %61)
%63 = load i32, i32* @PTRACE_POKETEXT
%64 = load i32, i32* %12
%65 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 3
%66 = load i32*, i32** %65
%67 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %63, i32 %64, i32* %66, i64 364515656907818255)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0))
%69 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 4
%70 = load i32, i32* %69
%71 = sub nsw i32 %70, 2048
store i32 %71, i32* %69
br label %72
72: ; preds = %60, %150
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%74 = call i32 @memset(i8* %73, i32 0, i32 4096)
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
store i8* %75, i8** %8
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%77 = call i32 @read(i32 0, i8* %76, i32 256)
store i32 %77, i32* %9
%78 = icmp sle i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %72
br label %153
80: ; preds = %72
%81 = load i8*, i8** %8
%82 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
%83 = load i8*, i8** %8
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i8, i8* %83, i64 %84
store i8* %85, i8** %8
store i32 0, i32* %10
br label %86
86: ; preds = %101, %80
%87 = load i32, i32* %10
%88 = load i32, i32* %9
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %104
90: ; preds = %86
%91 = load i8*, i8** %8
%92 = load i32, i32* %10
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = call i32 (i8*, i8*, ...) @sprintf(i8* %91, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i32 %96)
%98 = load i8*, i8** %8
%99 = sext i32 %97 to i64
%100 = getelementptr inbounds i8, i8* %98, i64 %99
store i8* %100, i8** %8
br label %101
101: ; preds = %90
%102 = load i32, i32* %10
%103 = add nsw i32 %102, 1
store i32 %103, i32* %10
br label %86
104: ; preds = %86
%105 = load i8*, i8** %8
%106 = call i32 (i8*, i8*, ...) @sprintf(i8* %105, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%107 = load i8*, i8** %8
%108 = sext i32 %106 to i64
%109 = getelementptr inbounds i8, i8* %107, i64 %108
store i8* %109, i8** %8
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0))
%111 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0))
%114 = load i32, i32* %12
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%116 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 4
%117 = load i32, i32* %116
%118 = call i32 @cpy_str(i32 %114, i8* %115, i32 %117)
store i32 %118, i32* %11
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
%120 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 0
store i32 1, i32* %120
%121 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 1
store i32 5, i32* %121
%122 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 4
%123 = load i32, i32* %122
%124 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 5
store i32 %123, i32* %124
%125 = load i32, i32* %11
%126 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %13, i32 0, i32 2
store i32 %125, i32* %126
%127 = load i32, i32* @PTRACE_SETREGS
%128 = load i32, i32* %12
%129 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %127, i32 %128, i32* null, %struct.user_regs_struct* %13)
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %104
%132 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0))
br label %133
133: ; preds = %131, %104
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.19, i64 0, i64 0))
%135 = load i32, i32* @PTRACE_SINGLESTEP
%136 = load i32, i32* %12
%137 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %135, i32 %136, i32* null, i32 0)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %133
%140 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.20, i64 0, i64 0))
br label %141
141: ; preds = %139, %133
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0))
%143 = call i32 @wait(i32* %15)
%144 = load i32, i32* @PTRACE_SINGLESTEP
%145 = load i32, i32* %12
%146 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %144, i32 %145, i32* null, i32 0)
%147 = icmp slt i64 %146, 0
br i1 %147, label %148, label %150
148: ; preds = %141
%149 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.20, i64 0, i64 0))
br label %150
150: ; preds = %148, %141
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0))
%152 = call i32 @wait(i32* %15)
br label %72
153: ; preds = %79
%154 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %14, i32 0, i32 3
%155 = load i32*, i32** %154
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.22, i64 0, i64 0), i32* %155)
%157 = load i32, i32* @PTRACE_POKETEXT
%158 = load i32, i32* %12
%159 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %14, i32 0, i32 3
%160 = load i32*, i32** %159
%161 = load i64, i64* %16
%162 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %157, i32 %158, i32* %160, i64 %161)
%163 = icmp slt i64 %162, 0
br i1 %163, label %164, label %166
164: ; preds = %153
%165 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.23, i64 0, i64 0))
br label %166
166: ; preds = %164, %153
%167 = load i64, i64* %16
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i64 %167)
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.24, i64 0, i64 0))
%170 = load i32, i32* @PTRACE_SETREGS
%171 = load i32, i32* %12
%172 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %170, i32 %171, i32* null, %struct.user_regs_struct* %14)
%173 = icmp slt i64 %172, 0
br i1 %173, label %174, label %176
174: ; preds = %166
%175 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0))
br label %176
176: ; preds = %174, %166
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.25, i64 0, i64 0))
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.26, i64 0, i64 0))
%179 = load i32, i32* @PTRACE_DETACH
%180 = load i32, i32* %12
%181 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %179, i32 %180, i32* null, i8* null)
%182 = icmp slt i64 %181, 0
br i1 %182, label %183, label %185
183: ; preds = %176
%184 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.27, i64 0, i64 0))
br label %185
185: ; preds = %183, %176
%186 = call i32 @wait(i32* %15)
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.28, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i32, i32, i32, i32*, i32, i32 }
@.str = [28 x i8] c"+ Attaching to process %ld\0A\00"
@PTRACE_ATTACH = global i32 0
@.str.1 = [15 x i8] c"ptrace_attach:\00"
@.str.2 = [3 x i8] c"%s\00"
@PTRACE_GETREGS = global i32 0
@.str.5 = [17 x i8] c"ptrace_get_regs:\00"
@.str.6 = [30 x i8] c" -> Process stopped at : %p\0A\00"
@.str.7 = [30 x i8] c" -> Stack at : %p\0A\00"
@.str.9 = [36 x i8] c"+ Retrieving opcode from (%llx) -> \00"
@PTRACE_PEEKTEXT = global i32 0
@.str.10 = [17 x i8] c"retrieve opcode:\00"
@.str.11 = [7 x i8] c"0x%lx\0A\00"
@PTRACE_POKETEXT = global i32 0
@.str.13 = [13 x i8] c"echo -n -e \22\00"
@.str.14 = [8 x i8] c"\\\\x%02x\00"
@.str.15 = [7 x i8] c"\22 > k\0A\00"
@PTRACE_SETREGS = global i32 0
@.str.18 = [17 x i8] c"ptrace_set_regs:\00"
@PTRACE_SINGLESTEP = global i32 0
@.str.20 = [13 x i8] c"Run syscallL\00"
@.str.22 = [27 x i8] c"Restoring opcode att : %p\0A\00"
@.str.23 = [16 x i8] c"Restore opcode:\00"
@PTRACE_DETACH = global i32 0
@.str.27 = [17 x i8] c"ptrace_deattach:\00"
@str = [30 x i8] c" ..... Waiting for process...\00"
@str.29 = [38 x i8] c"+ Getting current registers state....\00"
@str.30 = [33 x i8] c"+ Current register set copied...\00"
@str.31 = [31 x i8] c"+ Pushing string into stack...\00"
@str.33 = [21 x i8] c"--------------------\00"
@str.34 = [28 x i8] c"+ Preparing for syscall....\00"
@str.35 = [21 x i8] c"+ Run single step...\00"
@str.37 = [25 x i8] c"+ Waiting for process...\00"
@str.38 = [30 x i8] c"+Restoting original registers\00"
@str.39 = [32 x i8] c"Registers successfully restored\00"
@str.40 = [24 x i8] c"+ Deataching process...\00"
@str.41 = [21 x i8] c"Releasing process...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [4096 x i8]
%5 = alloca %struct.user_regs_struct
%6 = alloca %struct.user_regs_struct
%7 = alloca i32
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.user_regs_struct* %5 to i8*
%11 = bitcast %struct.user_regs_struct* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @PTRACE_ATTACH
%18 = tail call i64 (i32, i32, i32*, ...) @ptrace(i32 %17, i32 %15, i32* null, i8* null)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%24 = call i32 @wait(i32* %7)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.29, i64 0, i64 0))
%26 = load i32, i32* @PTRACE_GETREGS
%27 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %26, i32 %15, i32* null, %struct.user_regs_struct* %5)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 3
%33 = load i32*, i32** %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32* %33)
%35 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 4
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.30, i64 0, i64 0))
%39 = call i32 @memcpy(%struct.user_regs_struct* %6, %struct.user_regs_struct* %5, i32 32)
%40 = load i32*, i32** %32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32* %40)
%42 = load i32, i32* @PTRACE_PEEKTEXT
%43 = load i32*, i32** %32
%44 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %42, i32 %15, i32* %43, i32 0)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %31
%47 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %48
48: ; preds = %46, %31
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i64 %44)
%50 = load i32, i32* @PTRACE_POKETEXT
%51 = load i32*, i32** %32
%52 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %50, i32 %15, i32* %51, i64 364515656907818255)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.31, i64 0, i64 0))
%54 = load i32, i32* %35
%55 = add nsw i32 %54, -2048
store i32 %55, i32* %35
%56 = call i32 @memset(i8* %9, i32 0, i32 4096)
%57 = call i32 @read(i32 0, i8* %8, i32 256)
%58 = icmp slt i32 %57, 1
br i1 %58, label %113, label %59
59: ; preds = %48
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 12
%61 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 0
%62 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 1
%63 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 5
%64 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %5, i64 0, i32 2
br label %65
65: ; preds = %107, %59
%66 = phi i32 [ %57, %59 ], [ %111, %107 ]
%67 = zext i32 %66 to i64
br label %68
68: ; preds = %65, %68
%69 = phi i64 [ 0, %65 ], [ %77, %68 ]
%70 = phi i8* [ %60, %65 ], [ %76, %68 ]
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %69
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %70, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i32 %73)
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %70, i64 %75
%77 = add nuw nsw i64 %69, 1
%78 = icmp eq i64 %77, %67
br i1 %78, label %79, label %68
79: ; preds = %68
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.33, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.33, i64 0, i64 0))
%83 = load i32, i32* %35
%84 = call i32 @cpy_str(i32 %15, i8* %9, i32 %83)
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.34, i64 0, i64 0))
store i32 1, i32* %61
store i32 5, i32* %62
%86 = load i32, i32* %35
store i32 %86, i32* %63
store i32 %84, i32* %64
%87 = load i32, i32* @PTRACE_SETREGS
%88 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %87, i32 %15, i32* null, %struct.user_regs_struct* %5)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %79
%91 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0))
br label %92
92: ; preds = %90, %79
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.35, i64 0, i64 0))
%94 = load i32, i32* @PTRACE_SINGLESTEP
%95 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %94, i32 %15, i32* null, i32 0)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %92
%98 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.20, i64 0, i64 0))
br label %99
99: ; preds = %97, %92
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.37, i64 0, i64 0))
%101 = call i32 @wait(i32* %7)
%102 = load i32, i32* @PTRACE_SINGLESTEP
%103 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %102, i32 %15, i32* null, i32 0)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %99
%106 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.20, i64 0, i64 0))
br label %107
107: ; preds = %105, %99
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.37, i64 0, i64 0))
%109 = call i32 @wait(i32* %7)
%110 = call i32 @memset(i8* %9, i32 0, i32 4096)
%111 = call i32 @read(i32 0, i8* %8, i32 256)
%112 = icmp slt i32 %111, 1
br i1 %112, label %113, label %65
113: ; preds = %107, %48
%114 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %6, i64 0, i32 3
%115 = load i32*, i32** %114
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.22, i64 0, i64 0), i32* %115)
%117 = load i32, i32* @PTRACE_POKETEXT
%118 = load i32*, i32** %114
%119 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %117, i32 %15, i32* %118, i64 %44)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %113
%122 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.23, i64 0, i64 0))
br label %123
123: ; preds = %121, %113
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i64 %44)
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.38, i64 0, i64 0))
%126 = load i32, i32* @PTRACE_SETREGS
%127 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %126, i32 %15, i32* null, %struct.user_regs_struct* %6)
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %123
%130 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i64 0, i64 0))
br label %131
131: ; preds = %129, %123
%132 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.39, i64 0, i64 0))
%133 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.40, i64 0, i64 0))
%134 = load i32, i32* @PTRACE_DETACH
%135 = call i64 (i32, i32, i32*, ...) @ptrace(i32 %134, i32 %15, i32* null, i8* null)
%136 = icmp slt i64 %135, 0
br i1 %136, label %137, label %139
137: ; preds = %131
%138 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.27, i64 0, i64 0))
br label %139
139: ; preds = %137, %131
%140 = call i32 @wait(i32* %7)
%141 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.41, i64 0, i64 0))
ret i32 0
}