#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
size_t EACCES;
size_t strlen(char *);
size_t write_to_buffer(char const *, size_t, int /*<<< orphan*/, char **,
                       size_t *);
size_t write_to_string(const char *buffer, size_t size, off_t offset,
                       char **target) {
  if ((target == NULL) || (*target == NULL)) {
    ;
    return -EACCES;
  }
  size_t writebuffersize = strlen(*target);
  return write_to_buffer(buffer, size, offset, target, &writebuffersize);
}


x86 assembly (clang, -O0):
<write_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1150 <write_to_string+0x30>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1165 <write_to_string+0x45>
xor    %eax,%eax
mov    0x2e8f(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <write_to_string+0x71>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1040 <write_to_buffer@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rcx,%rcx
je     115f <write_to_string+0x3f>
mov    %rcx,%rbx
mov    %rdi,%rbp
mov    (%rcx),%rdi
test   %rdi,%rdi
je     115f <write_to_string+0x3f>
mov    %edx,%r14d
mov    %rsi,%r15
call   1030 <strlen@plt>
mov    %rax,(%rsp)
mov    %rsp,%r8
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <write_to_buffer@plt>
jmp    116b <write_to_string+0x4b>
mov    0x2e82(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EACCES = global i64 0
define i64 @write_to_string(i8* %0, i64 %1, i32 %2, i8** %3) {
%5 = alloca i64
%6 = icmp eq i8** %3, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7, %4
%11 = load i64, i64* @EACCES
%12 = sub i64 0, %11
br label %17
13: ; preds = %7
%14 = bitcast i64* %5 to i8*
%15 = tail call i64 @strlen(i8* dereferenceable(1) %8)
store i64 %15, i64* %5
%16 = call i64 @write_to_buffer(i8* %0, i64 %1, i32 %2, i8** %3, i64* %5)
br label %17
17: ; preds = %13, %10
%18 = phi i64 [ %12, %10 ], [ %16, %13 ]
ret i64 %18
}