#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 */
char *erealloc(char *, size_t);
scalar_t__ sprintf(char *, char *, char const *);
size_t strlen(char const *);
void add_tok_to_line(char **line, size_t *len, const char *tok) {
  size_t new = *len + 1 + strlen(tok) + 1;
  *line = erealloc(*line, new);
  *len += sprintf(*line + *len, "%s:", tok);
}


x86 assembly (clang, -O0):
<add_tok_to_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <erealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
add    (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <sprintf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_tok_to_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%r12
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x2,%rsi
mov    (%r15),%rdi
call   1040 <erealloc@plt>
mov    %rax,(%r15)
add    (%rbx),%rax
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
add    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s:\00"
define void @add_tok_to_line(i8** %0, i64* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %4
store i64* %1, i64** %5
store i8* %2, i8** %6
%8 = load i64*, i64** %5
%9 = load i64, i64* %8
%10 = add i64 %9, 1
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
%13 = add i64 %10, %12
%14 = add i64 %13, 1
store i64 %14, i64* %7
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = load i64, i64* %7
%18 = call i8* @erealloc(i8* %16, i64 %17)
%19 = load i8**, i8*** %4
store i8* %18, i8** %19
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = load i64*, i64** %5
%23 = load i64, i64* %22
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8*, i8** %6
%26 = call i64 @sprintf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i64*, i64** %5
%28 = load i64, i64* %27
%29 = add i64 %28, %26
store i64 %29, i64* %27
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s:\00"
define void @add_tok_to_line(i8** nocapture %0, i64* nocapture %1, i8* %2) {
%4 = load i64, i64* %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = load i8*, i8** %0
%9 = tail call i8* @erealloc(i8* %8, i64 %7)
store i8* %9, i8** %0
%10 = load i64, i64* %1
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = tail call i64 @sprintf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%13 = load i64, i64* %1
%14 = add i64 %13, %12
store i64 %14, i64* %1
ret void
}