#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 */
struct esb_s {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ esb_appendn_internal(struct esb_s *, char const *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long,
                           unsigned long);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
void esb_appendn(struct esb_s *data, const char *in_string, size_t len) {
  size_t full_len = strlen(in_string);
  if (full_len < len) {
    fprintf(stderr,
            "dwarfdump esb internal error, bad string length "
            " %lu  < %lu \n",
            (unsigned long)full_len, (unsigned long)len);
    len = full_len;
  }
  esb_appendn_internal(data, in_string, len);
}


x86 assembly (clang, -O0):
<esb_appendn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1184 <esb_appendn+0x54>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <esb_appendn_internal@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<esb_appendn>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    %rbx,%rax
jae    116f <esb_appendn+0x3f>
mov    %rax,%r12
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    %r12,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <esb_appendn_internal@plt>

LLVM IR (-O0):
%struct.esb_s = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"dwarfdump esb internal error, bad string length %lu < %lu \0A\00"
define void @esb_appendn(%struct.esb_s* %0, i8* %1, i64 %2) {
%4 = alloca %struct.esb_s*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store %struct.esb_s* %0, %struct.esb_s** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i64 %15, i64 %16)
%18 = load i64, i64* %7
store i64 %18, i64* %6
br label %19
19: ; preds = %13, %3
%20 = load %struct.esb_s*, %struct.esb_s** %4
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = call i32 @esb_appendn_internal(%struct.esb_s* %20, i8* %21, i64 %22)
ret void
}

LLVM IR (-O2):
%struct.esb_s = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"dwarfdump esb internal error, bad string length %lu < %lu \0A\00"
define void @esb_appendn(%struct.esb_s* %0, i8* %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %4, %2
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %2)
br label %9
9: ; preds = %6, %3
%10 = phi i64 [ %4, %6 ], [ %2, %3 ]
%11 = tail call i32 @esb_appendn_internal(%struct.esb_s* %0, i8* %1, i64 %10)
ret void
}