#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 */
typedef int /*<<< orphan*/ newname;

/* Variables and functions */
char *strchr(char const *const, char);
int /*<<< orphan*/ strncpy(char *, char const *const, int);
const char *lily_normalize_user_name(const char *const name) {
  static char newname[2048];
  char *ptr = strchr(name, ' ');
  if (ptr == NULL)
    return (name);
  strncpy(newname, name, sizeof(newname) - 1);
  newname[sizeof(newname) - 1] = 0;
  while ((ptr = strchr(newname, ' ')) != NULL)
    *ptr = '_';
  return (newname);
}


x86 assembly (clang, -O0):
<lily_normalize_user_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <lily_normalize_user_name+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <lily_normalize_user_name+0x88>
mov    -0x10(%rbp),%rsi
lea    0x2edf(%rip),%rdi
mov    $0x7ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x36cd(%rip)
lea    0x2ec7(%rip),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119d <lily_normalize_user_name+0x7d>
mov    -0x18(%rbp),%rax
movb   $0x5f,(%rax)
jmp    1172 <lily_normalize_user_name+0x52>
lea    0x2e9c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lily_normalize_user_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1185 <lily_normalize_user_name+0x65>
lea    0x2f03(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x36eb(%rip)
mov    %r14,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %r14,%rbx
test   %rax,%rax
je     1185 <lily_normalize_user_name+0x65>
lea    0x2ed0(%rip),%rbx
movb   $0x5f,(%rax)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1170 <lily_normalize_user_name+0x50>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@lily_normalize_user_name.newname = internal global [2048 x i8] zeroinitializer
define i8* @lily_normalize_user_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strchr(i8* %5, i8 signext 32)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i8*, i8** %3
store i8* %10, i8** %2
br label %20
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strncpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8* %12, i32 2047)
store i8 0, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 2047)
br label %14
14: ; preds = %17, %11
%15 = call i8* @strchr(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8 signext 32)
store i8* %15, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i8*, i8** %4
store i8 95, i8* %18
br label %14
19: ; preds = %14
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8** %2
br label %20
20: ; preds = %19, %9
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@lily_normalize_user_name.newname = internal global [2048 x i8] zeroinitializer
define i8* @lily_normalize_user_name(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @strncpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8* %0, i32 2047)
store i8 0, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 2047)
%6 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4, %8
%9 = phi i8* [ %10, %8 ], [ %6, %4 ]
store i8 95, i8* %9
%10 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), i8 signext 32)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %8
12: ; preds = %8, %4, %1
%13 = phi i8* [ %0, %1 ], [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), %4 ], [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @lily_normalize_user_name.newname, i64 0, i64 0), %8 ]
ret i8* %13
}