#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*/ memcpy(char *, char const *, unsigned int);
char *u2a(char *, unsigned int);
char *badds(char *p, const char *s) {
  unsigned int n = 0;
  const char *q = s;
  for (; *q; ++n, ++q)
    ;
  p = u2a(p, n);
  *p++ = ':';
  memcpy(p, s, n);
  return p + n;
}


x86 assembly (clang, -O0):
<badds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     116b <badds+0x4b>
jmp    1151 <badds+0x31>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113f <badds+0x1f>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <u2a@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x3a,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<badds>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmpb   $0x0,(%rsi)
je     113e <badds+0x1e>
xor    %ebx,%ebx
nop
cmpb   $0x0,0x1(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1130 <badds+0x10>
jmp    1140 <badds+0x20>
xor    %ebx,%ebx
mov    %ebx,%esi
call   1040 <u2a@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
movb   $0x3a,(%rax)
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
add    %r15,%rax
add    $0x1,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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