#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*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
int prepend_string(char **before, char *start, const char *what) {
  char *ptr;
  size_t len;
  len = strlen(what);
  ptr = *before - len;
  if (ptr < start)
    return 0;
  memcpy(ptr, what, len);
  *before = ptr;
  return len;
}


x86 assembly (clang, -O0):
<prepend_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
sub    -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    116f <prepend_string+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1192 <prepend_string+0x72>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepend_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    (%r14),%rbx
sub    %rax,%rbx
xor    %eax,%eax
cmp    %r13,%rbx
jb     115e <prepend_string+0x3e>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %rbx,(%r14)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @prepend_string(i8** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %9
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = load i64, i64* %9
%15 = sub i64 0, %14
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = load i8*, i8** %6
%19 = icmp ult i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 0, i32* %4
br label %30
21: ; preds = %3
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = load i64, i64* %9
%25 = call i32 @memcpy(i8* %22, i8* %23, i64 %24)
%26 = load i8*, i8** %8
%27 = load i8**, i8*** %5
store i8* %26, i8** %27
%28 = load i64, i64* %9
%29 = trunc i64 %28 to i32
store i32 %29, i32* %4
br label %30
30: ; preds = %21, %20
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @prepend_string(i8** nocapture %0, i8* readnone %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = load i8*, i8** %0
%6 = sub i64 0, %4
%7 = getelementptr inbounds i8, i8* %5, i64 %6
%8 = icmp ult i8* %7, %1
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = tail call i32 @memcpy(i8* %7, i8* %2, i64 %4)
store i8* %7, i8** %0
%11 = trunc i64 %4 to i32
br label %12
12: ; preds = %3, %9
%13 = phi i32 [ %11, %9 ], [ 0, %3 ]
ret i32 %13
}