#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 */
char *gs_change(char *, size_t, size_t, char const *);
scalar_t__ malloc(size_t);
size_t strlen(char const *);
char *gs_change_m(const char *str, size_t pos, size_t len, const char *value) {
  char *p;
  if (!str)
    return NULL;
  p = (char *)malloc(strlen(str) + strlen(value) - len + 1);
  if (!p)
    return NULL;
  return gs_change(p, pos, len, value);
}


x86 assembly (clang, -O0):
<gs_change_m>:
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    1160 <gs_change_m+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11bf <gs_change_m+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
sub    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a6 <gs_change_m+0x76>
movq   $0x0,-0x8(%rbp)
jmp    11bf <gs_change_m+0x8f>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <gs_change@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gs_change_m>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1187 <gs_change_m+0x57>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %r12,%rbx
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1187 <gs_change_m+0x57>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <gs_change@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @gs_change_m(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 i8*
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 %34
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %9
%18 = call i64 @strlen(i8* %17)
%19 = add i64 %16, %18
%20 = load i64, i64* %8
%21 = sub i64 %19, %20
%22 = add i64 %21, 1
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %14
store i8* null, i8** %5
br label %34
28: ; preds = %14
%29 = load i8*, i8** %10
%30 = load i64, i64* %7
%31 = load i64, i64* %8
%32 = load i8*, i8** %9
%33 = call i8* @gs_change(i8* %29, i64 %30, i64 %31, i8* %32)
store i8* %33, i8** %5
br label %34
34: ; preds = %28, %27, %13
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
define i8* @gs_change_m(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = tail call i64 @strlen(i8* %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%9 = sub i64 1, %2
%10 = add i64 %9, %7
%11 = add i64 %10, %8
%12 = tail call i64 @malloc(i64 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %6
%15 = inttoptr i64 %12 to i8*
%16 = tail call i8* @gs_change(i8* %15, i64 %1, i64 %2, i8* %3)
br label %17
17: ; preds = %6, %4, %14
%18 = phi i8* [ %16, %14 ], [ null, %4 ], [ null, %6 ]
ret i8* %18
}