#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*/ uint32_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_POKETEXT;
int /*<<< orphan*/ perror(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/);
int inject_data(pid_t pid, unsigned char *src, void *dst, int len) {
  int i;
  uint32_t *s = (uint32_t *)src;
  uint32_t *d = (uint32_t *)dst;
  for (i = 0; i < len; i += 4, s++, d++) {
    if ((ptrace(PTRACE_POKETEXT, pid, d, *s)) < 0) {
      perror("ptrace(POKETEXT):");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<inject_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c1 <inject_data+0xa1>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
call   1030 <ptrace@plt>
cmp    $0x0,%rax
jge    1196 <inject_data+0x76>
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <inject_data+0xa8>
jmp    119b <inject_data+0x7b>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    114d <inject_data+0x2d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inject_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    1171 <inject_data+0x51>
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
mov    0x2e9d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%rbx,1),%rdx
mov    0x0(%r13),%edi
mov    (%r15,%rbx,1),%ecx
mov    %ebp,%esi
call   1030 <ptrace@plt>
test   %rax,%rax
js     1182 <inject_data+0x62>
add    $0x4,%rbx
cmp    %r12d,%ebx
jl     1150 <inject_data+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    1173 <inject_data+0x53>

LLVM IR (-O0):
@PTRACE_POKETEXT = global i32 0
@.str = [18 x i8] c"ptrace(POKETEXT):\00"
define i32 @inject_data(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %7
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %11
%15 = load i8*, i8** %8
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %12
store i32 0, i32* %10
br label %17
17: ; preds = %32, %4
%18 = load i32, i32* %10
%19 = load i32, i32* %9
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = load i32, i32* @PTRACE_POKETEXT
%23 = load i32, i32* %6
%24 = load i32*, i32** %12
%25 = load i32*, i32** %11
%26 = load i32, i32* %25
%27 = call i64 @ptrace(i32 %22, i32 %23, i32* %24, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %40
31: ; preds = %21
br label %32
32: ; preds = %31
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 4
store i32 %34, i32* %10
%35 = load i32*, i32** %11
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %11
%37 = load i32*, i32** %12
%38 = getelementptr inbounds i32, i32* %37, i32 1
store i32* %38, i32** %12
br label %17
39: ; preds = %17
store i32 0, i32* %5
br label %40
40: ; preds = %39, %29
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@PTRACE_POKETEXT = global i32 0
@.str = [18 x i8] c"ptrace(POKETEXT):\00"
define i32 @inject_data(i32 %0, i8* nocapture %1, i8* %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %24
6: ; preds = %4
%7 = bitcast i8* %2 to i32*
%8 = bitcast i8* %1 to i32*
br label %9
9: ; preds = %6, %19
%10 = phi i32* [ %22, %19 ], [ %7, %6 ]
%11 = phi i32* [ %21, %19 ], [ %8, %6 ]
%12 = phi i32 [ %20, %19 ], [ 0, %6 ]
%13 = load i32, i32* @PTRACE_POKETEXT
%14 = load i32, i32* %11
%15 = tail call i64 @ptrace(i32 %13, i32 %0, i32* %10, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %24
19: ; preds = %9
%20 = add nuw nsw i32 %12, 4
%21 = getelementptr inbounds i32, i32* %11, i64 1
%22 = getelementptr inbounds i32, i32* %10, i64 1
%23 = icmp slt i32 %20, %3
br i1 %23, label %9, label %24
24: ; preds = %19, %4, %17
%25 = phi i32 [ -1, %17 ], [ 0, %4 ], [ 0, %19 ]
ret i32 %25
}