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

/* Variables and functions */
int mockable_is_surrounded_by_whitespaces(char *, int, int const);
int mockable_is_surrounded_by_whitespaces_but_old_gcc(char *, int, int const);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int replace_jump_destination(char *buf, char *mockable_name, int pos) {
  const int mocklen = strlen(mockable_name);
  const int end = pos + mocklen - 1;
  char newbuf[1024];
  const int new_school = mockable_is_surrounded_by_whitespaces(buf, pos, end);
  const int old_school =
      mockable_is_surrounded_by_whitespaces_but_old_gcc(buf, pos, end);
  if (!new_school && !old_school) {
    return 0;
  }
  buf[pos] = 0;
  if (new_school) {
    sprintf(newbuf, "%scutest_%s%s", buf, mockable_name, &buf[end + 1]);
  } else {
    sprintf(newbuf, "%scutest_%s%s", buf, mockable_name, &buf[end + 1]);
  }
  strcpy(buf, newbuf);
  return 1;
}


x86 assembly (clang, -O0):
<replace_jump_destination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1070 <mockable_is_surrounded_by_whitespaces@plt>
mov    %eax,-0x434(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <mockable_is_surrounded_by_whitespaces_but_old_gcc@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x434(%rbp)
jne    11ce <replace_jump_destination+0x7e>
cmpl   $0x0,-0x438(%rbp)
jne    11ce <replace_jump_destination+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    1257 <replace_jump_destination+0x107>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x434(%rbp)
je     1216 <replace_jump_destination+0xc6>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%r8
lea    0xdf4(%rip),%rsi
call   1060 <sprintf@plt>
jmp    1240 <replace_jump_destination+0xf0>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%r8
lea    0xdc5(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_jump_destination>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%rbx,1),%ebp
add    $0xffffffff,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1070 <mockable_is_surrounded_by_whitespaces@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <mockable_is_surrounded_by_whitespaces_but_old_gcc@plt>
mov    %eax,%ecx
xor    %eax,%eax
or     %r13d,%ecx
je     11d8 <replace_jump_destination+0x88>
add    %ebx,%r12d
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
movslq %r12d,%r8
add    %r15,%r8
lea    0xe49(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%scutest_%s%s\00"
define i32 @replace_jump_destination(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %15, %16
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %9
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = call i32 @mockable_is_surrounded_by_whitespaces(i8* %19, i32 %20, i32 %21)
store i32 %22, i32* %11
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = call i32 @mockable_is_surrounded_by_whitespaces_but_old_gcc(i8* %23, i32 %24, i32 %25)
store i32 %26, i32* %12
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %3
%30 = load i32, i32* %12
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %29
store i32 0, i32* %4
br label %64
33: ; preds = %29, %3
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* %11
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %33
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = load i8*, i8** %5
%43 = load i8*, i8** %6
%44 = load i8*, i8** %5
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %42, i8* %43, i8* %48)
br label %60
50: ; preds = %33
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = load i8*, i8** %5
%53 = load i8*, i8** %6
%54 = load i8*, i8** %5
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
%59 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %52, i8* %53, i8* %58)
br label %60
60: ; preds = %50, %40
%61 = load i8*, i8** %5
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%63 = call i32 @strcpy(i8* %61, i8* %62)
store i32 1, i32* %4
br label %64
64: ; preds = %60, %32
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
@.str = [14 x i8] c"%scutest_%s%s\00"
define i32 @replace_jump_destination(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, %2
%7 = add nsw i32 %6, -1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @mockable_is_surrounded_by_whitespaces(i8* %0, i32 %2, i32 %7)
%10 = tail call i32 @mockable_is_surrounded_by_whitespaces_but_old_gcc(i8* %0, i32 %2, i32 %7)
%11 = icmp ne i32 %9, 0
%12 = icmp ne i32 %10, 0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = sext i32 %2 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
%17 = sext i32 %6 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %18)
%20 = call i32 @strcpy(i8* %0, i8* %8)
br label %21
21: ; preds = %3, %14
%22 = phi i32 [ 1, %14 ], [ 0, %3 ]
ret i32 %22
}