#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 */
scalar_t__ allocate(scalar_t__);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void sanatize_name(char **dest, char *src) {
  *dest = (char *)allocate(strlen(src) + 1);
  strcpy(*dest, src);
  char *position = strchr(*dest, ':');
  while (position) {
    *position = '_';
    position = strchr(position, ':');
  }
}


x86 assembly (clang, -O0):
<sanatize_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <allocate@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bd <sanatize_name+0x7d>
mov    -0x18(%rbp),%rax
movb   $0x5f,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1194 <sanatize_name+0x54>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanatize_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <allocate@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    (%r14),%rdi
nopl   0x0(%rax)
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1187 <sanatize_name+0x47>
movb   $0x5f,(%rax)
mov    %rax,%rdi
jmp    1170 <sanatize_name+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @sanatize_name(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = call i64 @allocate(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = load i8**, i8*** %3
store i8* %10, i8** %11
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = call i8* @strchr(i8* %17, i8 signext 58)
store i8* %18, i8** %5
br label %19
19: ; preds = %22, %2
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i8*, i8** %5
store i8 95, i8* %23
%24 = load i8*, i8** %5
%25 = call i8* @strchr(i8* %24, i8 signext 58)
store i8* %25, i8** %5
br label %19
26: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @sanatize_name(i8** nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add nsw i64 %3, 1
%5 = tail call i64 @allocate(i64 %4)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %0
%7 = tail call i32 @strcpy(i8* %6, i8* %1)
%8 = load i8*, i8** %0
%9 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 58)
%10 = icmp eq i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2, %11
%12 = phi i8* [ %13, %11 ], [ %9, %2 ]
store i8 95, i8* %12
%13 = tail call i8* @strchr(i8* %12, i8 signext 58)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %11
15: ; preds = %11, %2
ret void
}