#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*/ strcpy(char *, char const *);
size_t strlen(char const *);
int /*<<< orphan*/ sttstr_reset(char *);
void sttstr_copy(char *this, const char *new_str, size_t buffer_size) {
  if (NULL == this)
    return;
  sttstr_reset(this);
  if (!new_str || !(*new_str) || (buffer_size < strlen(new_str)))
    return;
  strcpy(this, new_str);
}


x86 assembly (clang, -O0):
<sttstr_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1155 <sttstr_copy+0x25>
jmp    11a9 <sttstr_copy+0x79>
mov    -0x8(%rbp),%rdi
call   1050 <sttstr_reset@plt>
cmpq   $0x0,-0x10(%rbp)
je     1197 <sttstr_copy+0x67>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1197 <sttstr_copy+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    119c <sttstr_copy+0x6c>
jmp    11a9 <sttstr_copy+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sttstr_copy>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1160 <sttstr_copy+0x30>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <sttstr_reset@plt>
test   %r14,%r14
je     1160 <sttstr_copy+0x30>
cmpb   $0x0,(%r14)
je     1160 <sttstr_copy+0x30>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %r15,%rax
jbe    1166 <sttstr_copy+0x36>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @sttstr_copy(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %3
br label %29
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @sttstr_reset(i8* %11)
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i64, i64* %6
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19, %15, %10
br label %29
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %25, %24, %9
ret void
}

LLVM IR (-O2):
define void @sttstr_copy(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i32 @sttstr_reset(i8* %0)
%7 = icmp eq i8* %1, null
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = tail call i64 @strlen(i8* %1)
%13 = icmp ugt i64 %12, %2
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %16
16: ; preds = %5, %8, %11, %3, %14
ret void
}