#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 /*<<< orphan*/ memmove(char *, char const *, size_t);
int strlen(char const *);
char *gs_change(char *str, size_t pos, size_t len, const char *value) {
  size_t value_len;
  if (!str)
    return NULL;
  value_len = strlen(value);
  if (value_len == len)
    memmove(str + pos, value, value_len);
  else {
    static char *dest;
    static char *src;
    src = str + pos + len;
    dest = str + pos + value_len;
    memmove(dest, src, strlen(src) + 1);
    memmove(str + pos, value, value_len);
  }
  return str;
}


x86 assembly (clang, -O0):
<gs_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <gs_change+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11ff <gs_change+0xdf>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1187 <gs_change+0x67>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memmove@plt>
jmp    11f7 <gs_change+0xd7>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,0x2ea6(%rip)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,0x2e8b(%rip)
mov    0x2e84(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e81(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e76(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%eax
movslq %eax,%rdx
call   1040 <memmove@plt>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gs_change>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rdi,%rdi
je     1190 <gs_change+0x70>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rcx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r13
add    %r15,%r12
cmp    %rbx,%r13
jne    1154 <gs_change+0x34>
mov    %rbx,%r13
jmp    1182 <gs_change+0x62>
add    %r12,%rbx
mov    %rbx,0x2ee2(%rip)
lea    (%r12,%r13,1),%rbp
mov    %rbp,0x2ecf(%rip)
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <memmove@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <memmove@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@gs_change.dest = internal global i8* null
@gs_change.src = internal global i8* null
define i8* @gs_change(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %4
store i8* null, i8** %5
br label %54
14: ; preds = %4
%15 = load i8*, i8** %9
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
store i64 %17, i64* %10
%18 = load i64, i64* %10
%19 = load i64, i64* %8
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i8*, i8** %6
%23 = load i64, i64* %7
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8*, i8** %9
%26 = load i64, i64* %10
%27 = call i32 @memmove(i8* %24, i8* %25, i64 %26)
br label %52
28: ; preds = %14
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i64, i64* %8
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** @gs_change.src
%34 = load i8*, i8** %6
%35 = load i64, i64* %7
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i64, i64* %10
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** @gs_change.dest
%39 = load i8*, i8** @gs_change.dest
%40 = load i8*, i8** @gs_change.src
%41 = load i8*, i8** @gs_change.src
%42 = call i32 @strlen(i8* %41)
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = call i32 @memmove(i8* %39, i8* %40, i64 %44)
%46 = load i8*, i8** %6
%47 = load i64, i64* %7
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8*, i8** %9
%50 = load i64, i64* %10
%51 = call i32 @memmove(i8* %48, i8* %49, i64 %50)
br label %52
52: ; preds = %28, %21
%53 = load i8*, i8** %6
store i8* %53, i8** %5
br label %54
54: ; preds = %52, %13
%55 = load i8*, i8** %5
ret i8* %55
}

LLVM IR (-O2):
@gs_change.dest = internal unnamed_addr global i8* null
@gs_change.src = internal unnamed_addr global i8* null
define i8* @gs_change(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %21, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %3)
%8 = sext i32 %7 to i64
%9 = icmp eq i64 %8, %2
%10 = getelementptr inbounds i8, i8* %0, i64 %1
br i1 %9, label %18, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %10, i64 %2
store i8* %12, i8** @gs_change.src
%13 = getelementptr inbounds i8, i8* %10, i64 %8
store i8* %13, i8** @gs_change.dest
%14 = tail call i32 @strlen(i8* %12)
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = tail call i32 @memmove(i8* %13, i8* %12, i64 %16)
br label %18
18: ; preds = %6, %11
%19 = phi i64 [ %8, %11 ], [ %2, %6 ]
%20 = tail call i32 @memmove(i8* %10, i8* %3, i64 %19)
br label %21
21: ; preds = %18, %4
ret i8* %0
}