#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*/ ap_str_fix_buf_size(char **, int *, int *, int);
int /*<<< orphan*/ memcpy(char *, void *, int);
int ap_str_put_to_buf(char **dst_buf, int *dst_buf_size, int *dst_buf_fill,
                      void *src_buf, int src_len) {
  if (!ap_str_fix_buf_size(dst_buf, dst_buf_size, dst_buf_fill, src_len))
    return 0;
  memcpy(*dst_buf + *dst_buf_fill, src_buf, src_len);
  *dst_buf_fill += src_len;
  return 1;
}


x86 assembly (clang, -O0):
<ap_str_put_to_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <ap_str_fix_buf_size@plt>
cmp    $0x0,%eax
jne    1165 <ap_str_put_to_buf+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1194 <ap_str_put_to_buf+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_str_put_to_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rdi,%rbp
mov    %r8d,%ecx
call   1040 <ap_str_fix_buf_size@plt>
test   %eax,%eax
je     115b <ap_str_put_to_buf+0x3b>
movslq (%rbx),%rdi
add    0x0(%rbp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
add    %r15d,(%rbx)
mov    $0x1,%eax
jmp    115d <ap_str_put_to_buf+0x3d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ap_str_put_to_buf(i8** %0, i32* %1, i32* %2, i8* %3, i32 %4) {
%6 = tail call i32 @ap_str_fix_buf_size(i8** %0, i32* %1, i32* %2, i32 %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = load i8*, i8** %0
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %3, i32 %4)
%14 = load i32, i32* %2
%15 = add nsw i32 %14, %4
store i32 %15, i32* %2
br label %16
16: ; preds = %5, %8
%17 = phi i32 [ 1, %8 ], [ 0, %5 ]
ret i32 %17
}