#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*/ append(char *, char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void on_string(void *ctx, const char *code, const char *name, const char *buf,
               size_t len) {
  char *str = (char *)malloc(len + 1);
  strncpy(str, buf, len);
  str[len] = '\0';
  append("%s: %s", name, str);
  free(str);
}


x86 assembly (clang, -O0):
<on_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe67(%rip),%rdi
call   1040 <append@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
lea    0x1(%r8),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <strncpy@plt>
movb   $0x0,(%rbx,%r12,1)
lea    0xe89(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <append@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%s: %s\00"
define void @on_string(i8* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%12 = load i64, i64* %10
%13 = add i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = load i8*, i8** %9
%18 = load i64, i64* %10
%19 = call i32 @strncpy(i8* %16, i8* %17, i64 %18)
%20 = load i8*, i8** %11
%21 = load i64, i64* %10
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %8
%24 = load i8*, i8** %11
%25 = call i32 @append(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i8*, i8** %11
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s: %s\00"
define void @on_string(i8* nocapture readnone %0, i8* nocapture readnone %1, i8* %2, i8* %3, i64 %4) {
%6 = add i64 %4, 1
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strncpy(i8* %8, i8* %3, i64 %4)
%10 = getelementptr inbounds i8, i8* %8, i64 %4
store i8 0, i8* %10
%11 = tail call i32 @append(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %8)
%12 = tail call i32 @free(i8* %8)
ret void
}