#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_POKETEXT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, void *, void *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int ptrace_poketext(pid_t pid, unsigned long long int rsp, void *addr,
                    size_t len) {
  long ret = 0;
  ret = ptrace(PTRACE_POKETEXT, pid, addr, (void *)len);
  if (ret != 0) {
    fprintf(stderr, "ptrace poketext error, ret is %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ptrace_poketext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <ptrace@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11af <ptrace_poketext+0x7f>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <ptrace_poketext+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace_poketext>:
push   %rbx
mov    %edi,%esi
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1040 <ptrace@plt>
test   %rax,%rax
je     1175 <ptrace_poketext+0x45>
mov    0x2e93(%rip),%rax
mov    (%rax),%ebx
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PTRACE_POKETEXT = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"ptrace poketext error, ret is %s\0A\00"
@errno = global i32 0
define i32 @ptrace_poketext(i32 %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i32 %0, i32* %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i64 0, i64* %10
%11 = load i32, i32* @PTRACE_POKETEXT
%12 = load i32, i32* %6
%13 = load i8*, i8** %8
%14 = load i64, i64* %9
%15 = inttoptr i64 %14 to i8*
%16 = call i64 @ptrace(i32 %11, i32 %12, i8* %13, i8* %15)
store i64 %16, i64* %10
%17 = load i64, i64* %10
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %5
br label %25
24: ; preds = %4
store i32 0, i32* %5
br label %25
25: ; preds = %24, %19
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@PTRACE_POKETEXT = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"ptrace poketext error, ret is %s\0A\00"
@errno = global i32 0
define i32 @ptrace_poketext(i32 %0, i64 %1, i8* %2, i64 %3) {
%5 = load i32, i32* @PTRACE_POKETEXT
%6 = inttoptr i64 %3 to i8*
%7 = tail call i64 @ptrace(i32 %5, i32 %0, i8* %2, i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ -1, %9 ], [ 0, %4 ]
ret i32 %15
}